MLX90614 Non-contact Infrared Temperature Sensor with ESP8266

In this guide, we will learn to interface GY-906 MLX90614 non-contact infrared temperature sensor with ESP8266 NodeMCU. The MLX90614 is a contactless IR Temperature sensor which can measure temperature without even touching the object. This exceptional sensor introduced by Melexis uses IR technology that uses the IR radiations to measure temperature and provides a digital output signal through I2C port. Contactless temperature sensors played a major contribution during COVID-19 days to check temperature. We will start with an introduction to this sensor, discuss pinout details, pin configurations, specifications and interfacing with ESP8266. After that, we will show you a program sketch in Arduino IDE where we will use this sensor to acquire both the ambient and object temperature in degrees Celsius and Fahrenheit.

We have similar guides with ESP32 and Arduino:

GY-906 MLX90614 Sensor Introduction

The GY-906 MLX90614 is an IR based contactless temperature sensor that can measure the temperature of a particular object between -70°C – 382.2°C and an ambient temperature of -40°C – 125°C without even making physical contact with an object under observation. It is embedded with an I2C port to communicate temperature reading to microcontrollers over an I2C bus. On top of that, it is provided with ESD protection to avoid malfunctioning of the sensor.

MLX90614 Non-Contact IR Temperature Sensor

The tiny device is highly accurate and precise due to its powerful ADC. A 17-bit ADC is embedded in the module to output the values with 0.14 ˚C of resolution. Melexis has introduced different versions of this sensor based on input voltage requirements i.e., 3 Volts or 5volts and resolving power for different project requirements. But MLX90614 is a sensitive temperature sensor that has a long list of applications, especially in home automation.

Overview of GY-906 Module

MLX90614 Module Overview

As you can see in the diagram above, the MLX90614 is found at the center of the module. It is a highly precise non-contact temperature sensor. With the aid of this sensor, temperature is measured through emitted IR waves without any physical contact. Additionally, this sensor is able to measure both the ambient temperature and the object temperature with an accuracy of 0.5°C. Notice the built-in optical filter (long-wave pass) present in the MLX90614 sensor. This is useful in cutting off the near-infrared and visible light thereby reducing their impact on the readings.

At the back of the module, you can find the 662K 3.3V precision voltage regulator, therefore we can safely use microcontrollers that use 5/3.3 level input/outputs with this module.

Key Features

  • IR sensor is integrated with an optical filter, a DSP, and a low noise amplifier for fine output digital signals.
  • Adaptable for 8-16 Volts applications and can be integrated easily.
  • The MLX90614 sensor module has a low power operation, as it uses less than 2mA when measuring temperature. Therefore it makes a great choice to use in battery powered devices such as thermal scanners etc.
  • One of the interesting features of MLX90614 is that it consists of two output interfaces: SMBus (I2C) and PWM. By default, the 2 wire SMBus interface is used for communication. The SMBus interface uses the I2C pins SDA (serial data) and SCL (serial clock) to initiate a proper communication between the master and slave. The PWM interface can also be used to acquire the temperature measurement. However, the sensor should be first set up in the SMBus interface before using the PWM interface. On the SDA pin, the MLX90614 generates a continuous 10-bit PWM signal that represents the recorded object temperature once it is setup. The PWM signal spans a temperature range of -20°C to 120°C by default, with a 0.14°C output resolution, however this can be changed using SMBus. Therefore, we can also use the PWM output as a thermal relay/switch by setting the range of temperature values. For example, the PWM pin can be utilized as an interrupt and activated when the temperature goes over a set threshold.
  • Supports power-saving mode and is available in single and dual versions
  • It is a power-efficient and highly sensitive sensor.

Specifications

The table below shows the specifications of this sensor:

Operating Voltage3.3V – 5.5V
Ambient Temperature Range-40°C – 125°C
Object Temperature Range-70°C – 380°C
Measurement Resolution±0.2°C
Temperature Accuracy±0.5°C
ESD Sensitivity2kV
Sink/Source Current25mA
ADC Resolution17 bits

For more information about the specifications, refer to the MLX90614 Datasheet.

IR Thermometer Working Principle

MLX90614 is a contactless IR temperature sensor that works on the Stefan Boltzmann principle. The principle states that every object above -273°C radiates infrared radiation proportional to its temperature.

The MLX9416 measures this radiation and converts it to a digital signal that is communicated through the I2C bus to the microcontroller.

MLX90614 internal connections with pins

The functional diagram of MLX90614 IR Temperature Sensor is provided below:

MLX90614 Block Diagram
MLX90614 Block Diagram

The IR sensor module consists of an infrared thermopile detector and an ASSP (Signal conditioning application processor) unit. Thermopile serves the function of collecting the radiation in its field of view (FOV) which varies from version to version and then produces an electrical signal proportional to the radiation. The ASSP processing unit convert this analog signal to filtered amplified signal which is then sent to the microcontroller.

Field of View (FOV)

One important concept that comes up while learning the working of the infrared thermometer is the field of view of the sensor, also known as FOV. FOV is a solid angle through which the sensor is sensitive to electromagnetic radiation.

When the MLX90614 gives us the object temperature reading, it is the average temperature of all the objects present in the FOV of the sensor. Therefore, if you want to get an accurate temperature reading of an object, make sure it lies completely in the field of view of the sensor.

The field of view of the GY-906 MLX90614 sensor is 90°

The necessary measurement distance is thus determined by the desired field of view. A measuring distance of roughly 1 cm is often employed for measuring the surface temperature of an object such as an IC or a rotating shaft.

MLX90614 Pinout

This temperature sensor module comes with a 3.3 voltage regulator, I2C Bus with internal pullup resistors to define a default state and a capacitor for noise filtering. The pinout of the non-contact MLX90614 IR Temperature Sensor module is as shown:

MLX90614 Non-Contact IR Temperature Sensor pinout diagram

MLX90614 has two versions and is available in the TO-39 package. The pin configuration details are listed in a table below:

Pin NameFunction
VCCPositive power supply pin
GNDReference potential pin
SCLOpen drain Serial Clock pin. An I2C line clock pulses pin for data synchronization.
SDAOpen drain Serial Data pin. An I2C line to communicate data to the host MCU.

Interfacing MLX90614 Module with ESP8266

This section explains the interfacing of ESP8266 and MLX90614 contactless IR Temperature sensor.

MLX90614 with ESP8266

The following figure shows the connection diagram between MLX90614 temperature sensor and ESP8266.

  • Connect the power supply pin (Vin) of the temperature sensor to the 3.3V pin of ESP8266 and the GND pin of MLX90614 to the GND pin of ESP8266.
  • Connect the SDA and SCL pins of the mentioned IR sensor to D2 and D1 pins of ESP8266 for transferring data serially. D2 and D1 pins of ESP8266 also share alternate function of SDA and SCL pins of I2C port of ESP8266.
MLX90614 with ESP8266 connection diagram
MLX90614 with ESP8266 connection diagram
MLX90614 IR Temperature Sensor GY-906 ModuleESP8266
VCC3.3V
GNDGND
SDAD2
SCLD1

Installing the Adafruit MLX90614 Arduino Library

We will use Arduino IDE to program our ESP8266 development board. Thus, you should have the latest version of Arduino IDE. Additionally, you also need to install the ESP8266 plugin.

If you have not installed it before you can follow this tutorial:

Install ESP8266 in Arduino IDE ( Windows, Linux, and Mac OS)

Next we will download the Adafruit MLX90614 Arduino library and install it on the Arduino IDE software. It is very convenient to use the prewritten library specifically for the module and add it to the sketches to perform the commands. Open Arduino IDE and click on Sketch > Library > Manage Libraries

MPU-6050 Install library

The following window will open up.

search library Arduino IDE

Type ‘adafruit mlx90614’ in the search bar and press enter. Install the latest version of the library as shown below.

Install Adafruit MLX90614 Library

After installation of the library, restart your IDE.

ESP8266 MLX90614 IR Thermometer Sketch

Open your Arduino IDE and go to File > New. A new file will open. Copy the code given below in that file and save it.

This code will display the ambient temperature and object temperature in both degree Celsius and Fahrenheit and update it to new readings after every second.

#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(115200);
  while (!Serial);

  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };
}

void loop() {
  Serial.print("Ambient temperature = "); 
  Serial.print(mlx.readAmbientTempC());
  Serial.print("°C");      
  Serial.print("   ");
  Serial.print("Object temperature = "); 
  Serial.print(mlx.readObjectTempC()); 
  Serial.println("°C");
  
  Serial.print("Ambient temperature = ");
  Serial.print(mlx.readAmbientTempF());
  Serial.print("°F");      
  Serial.print("   ");
  Serial.print("Object temperature = "); 
  Serial.print(mlx.readObjectTempF()); 
  Serial.println("°F");

  Serial.println("-----------------------------------------------------------------");
  delay(1000);
}

How the Code Works?

The first step is to include the required library i.e. “Adafruit_MLX90614.h” for the temperature sensor.

#include <Adafruit_MLX90614.h>

Next create an object ‘mlx’ to access the MLX90614 library functions.


Adafruit_MLX90614 mlx = Adafruit_MLX90614();

Inside the setup() function, we first start the serial communication at a baud rate of 115200. Then we initialize the temperature sensor using the begin() method on the Adafruit_MLX90614 object.

void setup() {
  Serial.begin(115200);
  while (!Serial);

  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };
}

Inside the loop() function, we access the ambient temperature and the object temperature reading in both degree Celsius and Fahrenheit. These are printed in the serial monitor after every second.

To obtain the ambient temperature in degree Celsius we use the mlx.readAmbientTempC() function and in Fahrenheit we use the mlx.readAmbientTempF(). Similarly, to obtain the object temperature in degree Celsius we use mlx.readObjectTempC() function and in Fahrenheit we use the mlx.readObjectTempF() function.

void loop() {
  Serial.print("Ambient temperature = "); 
  Serial.print(mlx.readAmbientTempC());
  Serial.print("°C");      
  Serial.print("   ");
  Serial.print("Object temperature = "); 
  Serial.print(mlx.readObjectTempC()); 
  Serial.println("°C");
  
  Serial.print("Ambient temperature = ");
  Serial.print(mlx.readAmbientTempF());
  Serial.print("°F");      
  Serial.print("   ");
  Serial.print("Object temperature = "); 
  Serial.print(mlx.readObjectTempF()); 
  Serial.println("°F");

  Serial.println("-----------------------------------------------------------------");
  delay(1000);
}

Demonstration

Make sure you choose the correct board and COM port before uploading your code to the board. Go to Tools > Board and select NodeMCU1.0.

select ESP8266 NodeMCU board

Next, go to Tools > Port and select the appropriate port through which your board is connected.

ESP8266 COM Port

Next, click on the upload button to upload the code into the ESP8266 development board.

After you have uploaded your code and the files to the ESP8266 development board, press its RST button.

ESP8266 NodeMCU reset button

In your Arduino IDE, open up the serial monitor and you will be able to see the temperature readings. Bring the sensor close to an object to monitor its temperature. Moreover, make sure the sensor is away from electromagnetic waves as they can give rise to inaccurate readings.

MLX90614 with ESP8266 serial monitor

Leave a Comment