Make a Non-Contact Infrared Thermometer with MLX90614 IR Temperature Sensor

Published  July 4, 2019   16
Aswinth Raj
Author
IR Thermometer using Arduino and Infrared Temperature Sensor

When debugging an electronics circuit or testing a new hardware design, often times I tend to check if the components on the board are getting hot abnormally by touching them. And if something is messed up (which usually is in the first try) these components could get as hot as 80°C or more burning not only the component but also my finger along with it. After burning my fingers for more times than I could remember I decided to build my own Temperature Gun using Arduino and an Infrared Temperature Sensor. This Thermal gun will be built using a non-contact temperature sensor called MLX90614; hence it can not only be used to measure component temperatures but can also be used for measuring body temperature, surface temperature, Heat ventilation and much more. Of course, these thermal guns are readily available in the market from renowned manufacturers like Fluke, Flir etc. But they are not light on your pockets and on top of that what is more fun than building your own gadgets. So let’s get started…

 

Materials Required

  • Arduino Pro Mini
  • MLX90614 Infrared Temperature Sensor
  • OLED Display – SSD1306
  • Laser Diode
  • 9V Battery
  • Push button
  • Battery Clip
  • Connecting wires

 

MLX90614 Infrared Thermometer

Before we proceed with the tutorial it is important to know how the MLX90614 sensor works. There are many temperature sensors available in the market and we have been using the DHT11 Sensor and LM35 extensively for many applications where atmospheric humidity or temperature has to be measured. You can find some of the DIY Thermometers below:

 

But here, for a thermal gun we need a sensor that could sense the temperature of a particular object (not ambient) without directly getting in contact with the object. For this purpose we have contact less temperature sensors which utilizes Laser or IR to calculate the temperature of an object. The MLX90614 is one such sensor that uses IR energy to detect the temperature of an object. To learn more about Infrared and IR sensor circuit, follow the link.

MLX90614 Infrared Thermometer

 

MLX90614 sensor is manufactured by Melexis Microelectronics Integrated system, it has two devices embedded in it, one is the infrared thermopile detector (sensing unit) and the other is a signal conditioning DSP device (computational unit). It works based on Stefan-Boltzmann law which states that all objects emits IR energy and the intensity of this energy will be directly proportional to the temperature of that object. The sensing unit in the sensor measures how much IR energy is emitted by a targeted object and the computational unit converts it into temperature value using a 17-bit in-built ADC and outputs the data through I2C communication protocol. The sensor measures both the object temperature and ambient temperature to calibrate the object temperature value. The features of MLX90614 sensor is given below, for more details refer the MLX90614 Datasheet.

 

MLX90614 Infrared Temperature Sensor Features:

  • Operating Voltage: 3.6V to 5V
  • Object Temperature Range: -70°C to 382.2°C
  • Ambient Temperature Range: -40°C to 125°C
  • Resolution/Accuracy: 0.02°C

 

What should be the distance between the Sensor and the Object?

One question that is not directly answered by the datasheet is the measuring distance between the sensor and the object. The value of this distance is given by the term Field of View (FOV), for our sensor the field of view is about 80°.

MLX90614 Infrared Thermometer Field of View

 

You can think of the sensing range to be in a conical shape from the point of sensor as show above. So, as we go far from the measuring object the sensing area increase by two folds. Meaning for every 1cm we move away from the object the sensing area grows by 2cm. In our thermal gun we have placed a laser diode on top of the sensor to know where the sensing area of the sensor is currently pointing at. I found that the values were reliable if the gun is pointed at 2cm away from the object and the accuracy goes down as we move away.

 

Arduino MLX90614 Thermometer Circuit Diagram

The circuit diagram for Infrared Thermometer is pretty simple. The complete circuit is shown below, it was created using Fritzing software.

Arduino MLX90614 Infrared Thermometer Circuit Connections

 

Since the Fritzing Software did not support a part for MLX90614 sensor we have used a note to mention its connections as shown above, also we have used a red colour LED in place of a laser diode. The entire circuit is powered by the 9V battery through a push button. When the push button is pressed the 9V battery is connected to the RAW pin of Arduino which is then regulated to 5V using the on-board voltage regulator. This 5V is then used to power the OLED module, Sensor and Laser diode.

Arduino MLX90614 Infrared Thermometer project

 

We have already learnt how to interface SSD1306 OLED with Arduino the same hardware and code will be used here. Also you can design a separate laser diode driver circuit if you require the laser beam to be more powerful.

 

Designing the Casing for Temperature Gun

To make the project more interesting and practically usable we have 3D modeled and printed our outer casing for our thermal gun. The design involves two parts, one is the top part which acts as the body of the gun housing the Arduino controller, OLED, Sensor and the Laser diode. The other is the bottom part which acts as a handle of the gun housing the battery and push button. The Push button here acts as the trigger. The model looks like this below.

3D-Modelling Thermal Gun

 

The Design Files are available for download from thingiverse; you can download the design and print one using your 3D printer or also modify it to suit your needs. The download link is given below

Thermal Gun 3D Model

After downloading the files you can direclty start 3D printing the design or can do some tweaks according to your requirements.

 

3D printing the Enclosure:

The model was then saved as STL file and converted into G-code using Cura. I used my Tevo tarantula printer to print both my parts and then screwed them together. It is also possible to print both the parts as single piece if you printer supports it. The slicing setting for my print is shown below

3D-Model Designing Thermal Gun

 

It took me nearly 6 hours to print both the parts, once printed hardware connections was made my -directly soldering wires directly to the Arduino pins using 7-pin and 4-pin Relimate connectors (RMC) for the sensor and OLED display respectively. The OLED was then mounted in the printed part using screws while the sensor and Laser diode was mounted using hot glue.  The power pins (Raw, Gnd) were then slid down through a wire for the handle part which consists of the push button and battery. This wires was then connected to the battery though the push button. The Once the assembly is done the thermal gun looked like this below

Making IR Thermometer using Arduino and Infrared Temperature Sensor

Thermal Gun Construction

 

You can proceed with designing a cover for the top part, but I decided to leave it open so that I can tweak it later in future if required.

 

Programming for Arduino MLX90614 Infrared Thermometer 

The Program for Arduino should read the temperature value from the MLX90614 and display it on the OLED display. Lucky for us the program will be very simple since Adafruit has provided us a Library to easily read data from the MLX90614. The Library can be downloaded from below link

Arduino MLX90614 Library

The link will download the library as a ZIP folder. After download add it to the Arduino IDE following the command Sketch -> Include Library -> Add .ZIP Library and browse for the location of this ZIP file. Also make sure you have followed OLED interfacing with Arduino tutorial so that you have installed the required libraries for OLED display module as well. Once the libraries are added we can begin our program, the complete program for this project can be found at the bottom of this page. Here the same program will be explained in small snippets.

Like always we begin the program by adding the required library files. Here the Wire library (in-built) is used to communicate using I2C protocol and the SparkFunML90614 library is used to for communicating with the sensor. The SPI, GFX and SSD1306 libraries are used for communicating with 4-wire SPI protocol to the OLED display module.

#include <Wire.h>
#include <SparkFunMLX90614.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

 

We then define the pins of the OLED display to which we have made the connection. Since the module works with SPI we have used the SPI pins of the Arduino. There are OLED displays that works with I2C protocol as well, but we can’t use them here since the I2C pins are already occupied by the thermometer sensor.

#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

 

Inside the void setup() function, we initialize serial monitor for debugging and also the IR temperature sensor using the object therm that we created earlier. Here in India the most followed unit for temperature is Celsius (degree C) hence we have set the unit of the with TEMP_C you can also change this to TEMP_F if you need the values to be in Fahrenheit (F). Finally we initialize the OLED display and clear its display. Also the screen of OLED is rotated by 180 degree for easier mounting option in the casing.

void setup()
{
  Serial.begin(9600);
  therm.begin();
  therm.setUnit(TEMP_C);

   display.begin(SSD1306_SWITCHCAPVCC);
   display.clearDisplay();
   display.setRotation(2);
}

 

Inside the loop function, we read the value of temperature from the sensor and convert it into String to be displayed in the OLED display. We have also printed the value on the serial monitor for debugging purpose. We have also incremented a variable called runner which is produce a small animation on the screen every time the value of the temperature sensor is updated successfully, this will help us know if the reading is stuck for some reason.

  if (therm.read()) // On success, read() will return 1, on fail 0.
  {
    temperature = String(therm.object(), 2);
    Serial.print("Object: ");
    Serial.print(temperature); Serial.println("C");
    display.clearDisplay();
    runner++;
    delay(5);
  }

 

Testing Arduino Thermal Gun

Once the Arduino code is ready we can upload it to our hardware using an external TTL programmer or FTDI board since the pro mini does not have one on-board. Then simply press the push button to trigger the thermal gun and you will notice the laser beam falling on the object and the temperature of the object being displayed on the OLED screen as shown below. Here I have used it to measure the temperature of a component as pointed by the laser beam.

IR Thermometer using Arduino and Infrared Temperature Sensor

 

The thermal gun was also tested on soldering iron, 3D printer nozzle, ice cubes etc and a satisfactory result was observed. The complete working of the thermal gun can be found in the video at the bottom of this page. Hope you enjoyed the project and learnt something useful in building it, if you have questions leave them in the comment section below or use our forums for more technical questions.

Code

/***********************************
Code for Arduino MLX90614 Contactless thermometer 
MLX90614 I2C connection
OLED 4-wire SPI connection 
Dated: 7-6-2019
Code by: Aswint Raj
**********************************/

#include <Wire.h> 
#include <SparkFunMLX90614.h> 

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

IRTherm therm;

void setup() 
{
  Serial.begin(9600); 
  therm.begin(); 
  therm.setUnit(TEMP_C); 

   display.begin(SSD1306_SWITCHCAPVCC);
   display.clearDisplay();
   display.setRotation(2);
  
}

String temperature; 
char runner;

void loop() 
{
  if (therm.read()) // On success, read() will return 1, on fail 0.
  {
    temperature = String(therm.object(), 2);
    Serial.print("Object: ");
    Serial.print(temperature); Serial.println("C");
    display.clearDisplay();
    runner++;
    delay(5);
  }

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(display.width()/4,display.height()/12);
  
  if (therm.object()>=100)
  display.setCursor(display.width()/4,display.height()/12);
  
  display.println(temperature);

  display.drawLine(display.width()/runner,display.height() - display.height()/2.5, display.width()/runner+1, display.height() - display.height()/2.5, WHITE);

  display.setCursor(0,display.height()-display.height()/4);
  display.setTextSize(1);
  display.println("   Arduino Thermlgun");
  display.setCursor(display.width()- display.width()/4,display.height()/12);
  display.println("deg C");
  display.display();

  if (runner>20)
  runner=0;
}

Video

Have any question realated to this Article?

Ask Our Community Members

Comments

Aswinth, one of the most nifty projects found on this site. Did you manage to evaluate the margin of error though? Also, did you check the temperature difference with and without the laser beam? Since laser is radiation as well, as is known to heat up objects on focus (of course, it's intesity dependent), just want to know how much it impacts the actual measurement.

Would be great if you could post your findings.

Look forward to reading more of your projects. Cheers.

Hi Jay thanks for the comments, I am still playing around with this and it is quite useful. But defanitly there are space for improvements 

I still cannot get access to a flir or fluke meter to compare my results, but I would say the accuracy largely varies based on the disctance between the object and sensor. If the distance is less than 8cm I think the accuracy is 1*C + or -.

As far as the laser is concerned I have tried turning it off and the reading does not vay much. I think the laser that I am using is not powerful enough to heat up the object. 

I received an error in the code as -
Call to constructor of string is ambiguous
At line 36 of the code i.e temperature= String(therm.object(), 2)

Can you please help me in sorting this error

I want to build a system of IR measurement of surface temperature employing 4 x MLX90614 sensors and a Arduino Pro Mini which must record the temperatures hourly for 2-3 weeks. Do you have any suggestion? Since the use will be outdoors how easy is to make it wifi so the measurement and recording can be using by distance?

Thanks

Hi There, 

 I've tried making this project and the temperature doesnt appear on the OLED screen, the "deg C" and "thermlgun" appear but no temperature. Can you help?

Hello! I was working on this project, but I also encountered the problem that there is no "display temperature". I looked at the code and didn't add some strings. Fortunately, I am an electronics/software writing engineer, I will help you, please leave an email to me, I will send you the correct code, thank you, (I am from Taipei, Taiwan)

Hello! I was working on this project, but I also encountered the problem that there is no "display temperature". I looked at the code and didn't add some strings. Fortunately, I am an electronics/software writing engineer, I will help you, please leave an email to me, I will send you the correct code, thank you, (I am from Taipei, Taiwan)

我正在ping,來自台灣國家,我在發表製作修改此項目成功(有拍照片),有自己的代碼後製作,重新上傳,OLED有顯示溫度測試。如果你在後,沒有顯示溫度時間,請來信告知 我,我保送我修改代碼發給你,成功,祝你好運。保證我的郵箱:pingsinoca@gmail.com

 

我在2022/7/15發表評論,原來的屏幕沒有以攝氏度顯示溫度。 查了代碼,我加號後,重新編譯上傳,已經有溫度了,測試成功。 我用的是雙色顯示屏,我把測溫槍外殼的3D上蓋和圖紙中的mlx90614感應頭和激光頭二合一底座製作的測溫槍外殼轉出了stl格式 用於打印,實物照片如下:(如果您已經打印了溫度槍外殼,槍內沒有蓋子和二合一底座,請寫信給我並發送給您)電子郵件在 註釋

I commented on 7/15/2022, the original screen didn't show the temperature in degrees Celsius.  After checking the code, I added the sign, recompiled and uploaded, the temperature is already there, and the test is successful.  I am using a two-color display. I converted the 3D top cover of the temperature measuring gun shell and the temperature measuring gun shell made of the mlx90614 sensor head and laser head two-in-one base in the drawing to stl format for printing. The actual photos are as follows:  (If you have already printed the temperature gun case without the cover and 2-in-1 base inside the gun, please write to me and send it to you) Email in the comments