Example Code for Arduino-Get Temperature Data
This demo demonstrates how to put the sensor into and out of sleep mode and how to read temperature data from the sensor.
Hardware Preparation
- DFRduino UNO x 1
- IR Thermometer Sensor MLX90614 x 1
- Jumper Wires
Software Preparation
- Library Files and Examples
- About Library installation
- Arduino IDE (version compatible with the library)
Wiring Diagram

Other Preparation Work
- Install the DFRobot_MLX90614 library according to the provided installation guide.
- Connect the hardware as per the Wiring Diagram.
- Ensure the Arduino IDE is properly set up with the correct board and port selected.
Sample Code
/*!
* @file getData.ino
* @brief this demo demonstrates how to put the sensor enter/exit sleep mode and get temperature data measured by sensor
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [qsjhyy]([email protected])
* @version V1.0
* @date 2021-08-09
* @url https://github.com/DFRobot/DFRobot_MLX90614
*/
#include <DFRobot_MLX90614.h>
DFRobot_MLX90614_IIC sensor; // instantiate an object to drive our sensor
void setup()
{
Serial.begin(115200);
// initialize the sensor
while( NO_ERR != sensor.begin() ){
Serial.println("Communication with device failed, please check connection");
delay(3000);
}
Serial.println("Begin ok!");
/**
* adjust sensor sleep mode
* mode select to enter or exit sleep mode, it's enter sleep mode by default
* true is to enter sleep mode
* false is to exit sleep mode (automatically exit sleep mode after power down and restart)
*/
sensor.enterSleepMode();
delay(50);
sensor.enterSleepMode(false);
delay(200);
}
void loop()
{
/**
* get ambient temperature, unit is Celsius
* return value range: -40.01 °C ~ 85 °C
*/
float ambientTemp = sensor.getAmbientTempCelsius();
/**
* get temperature of object 1, unit is Celsius
* return value range:
* @n -70.01 °C ~ 270 °C(MLX90614ESF-DCI)
* @n -70.01 °C ~ 380 °C(MLX90614ESF-DCC)
*/
float objectTemp = sensor.getObjectTempCelsius();
// print measured data in Celsius
Serial.print("Ambient celsius : "); Serial.print(ambientTemp); Serial.println(" °C");
Serial.print("Object celsius : "); Serial.print(objectTemp); Serial.println(" °C");
// print measured data in Fahrenheit
Serial.print("Ambient fahrenheit : "); Serial.print(ambientTemp*9/5 + 32); Serial.println(" F");
Serial.print("Object fahrenheit : "); Serial.print(objectTemp*9/5 + 32); Serial.println(" F");
Serial.println();
delay(500);
}
Footer
Result

Was this article helpful?
