Using ESP32 with GY-906-DCI MLX90614 Contactless Temperature Sensor
Using ESP32 with GY-906-DCI MLX90614 Contactless Temperature Sensor
The MLX90614 is an infrared contactless temperature sensor useful for measuring temperature without touching objects, such as machinery, food, or body temperature. This tutorial covers wiring and coding ESP32 with GY-906-DCI using the MLX90614ESF chip via I2C.
How MLX90614 Works
MLX90614 detects infrared radiation emitted by objects and converts it to temperature values. All objects above Absolute Zero emit infrared radiation; the hotter the object, the more intense the radiation.
Specifications
- Supply voltage: 3V - 5V
- Communication: I2C (2 wires only)
- Object temperature range: -70°C to 380°C
- Ambient temperature range: -40°C to 125°C
- Resolution: 0.02°C
- Measurement distance: Up to ~50cm
Required Components
- ESP32 NodeMCU ESP-WROOM-32
- GY-906-DCI Infrared Temperature Sensor Module
- Breadboard 170 points
- Micro USB cable
- Jumper wires M-M, M-F 20cm
Wiring ESP32 to GY-906-DCI
Connect the wires as follows. Note that this uses ESP32’s I2C port on D22 (SCL) and D21 (SDA).
| ESP32 | GY-906-DCI |
|---|---|
| VIN | VIN |
| GND | GND |
| D22 | SCL |
| D21 | SDA |
Note: ESP32 I2C pins can be remapped, but the example code uses D21 (SDA) and D22 (SCL) as defaults.
Installing the Library
Download Adafruit MLX90614 Library from Mediafire:
Adafruit-MLX90614-Library-master.zip
Installation Steps
- Extract the ZIP file
- Move the folder Adafruit-MLX90614-Library-master to
Documents/Arduino/libraries/ - Restart Arduino IDE
Arduino Code for Reading Temperature
#include <Wire.h>
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(115200);
if (!mlx.begin()) {
Serial.println("Error connecting to MLX90614, check wiring!");
while (1);
}
Serial.println("MLX90614 Initialized Successfully");
}
void loop() {
// Ambient Temperature (surrounding environment)
Serial.print("Ambient = ");
Serial.print(mlx.readAmbientTempC());
Serial.print("°C");
// Object Temperature (target being measured)
Serial.print(" | Object = ");
Serial.print(mlx.readObjectTempC());
Serial.println("°C");
delay(500);
}
Upload Steps
- Connect Micro USB to ESP32
- Go to Tools > Port and select the COM port for ESP32
- Go to Tools > Board and select ESP32 Dev Module or your board model
- Click Upload
- If the console shows “Hard resetting via RTS pin…”, hold the BOOT button on the board briefly during upload
Viewing Results on Serial Monitor
Open Serial Monitor (Tools > Serial Monitor) and set Baud Rate to 115200. You’ll see temperature values update every half second.
- Ambient = Surrounding environment temperature
- Object = Temperature of the target object being measured
Testing Temperature Measurement
Point the sensor at hot water in a cup. The Object value will rise immediately. Then test with ice water. The Object value will drop significantly. The Ambient value changes more slowly because it measures the air temperature around the board.
[image: Comparison diagram showing hot water measurement (high Object value) vs ice water (low Object value) with stable Ambient reading]
Common Issues
Upload fails
- Hold the BOOT button before clicking Upload, then release when “Writing…” appears
- Verify correct Board and Port selection
Serial Monitor shows nothing
- Confirm Baud Rate is set to 115200
- Check that USB cable is properly connected
Readings are incorrect
- Keep sensor away from other heat sources
- Do not exceed 50cm distance
- Shiny surfaces may reflect readings
Summary
GY-906-DCI is easy to connect via I2C with only 4 wires. The 0.02°C resolution is impressive for an affordable sensor. For applications like fever thermometers or machinery temperature monitoring, simply read values from mlx.readObjectTempC() and use them directly.
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย