DIY Temperature Gun Using Arduino and MLX90614 Module

0 43046 Easy

During the Coronavirus outbreak, temperature checks with non-contact temperature guns are commonly used in stores, workplaces, and other public places. Compared with traditional thermometers, they are a good way to detect the body temperature since there is no need to have physical contact with the person being tested, which greatly helps in avoiding the risk of getting infected. With fever being a key symptom of Coronavirus, it is essential to have a fast temperature check of the people at every possible place where there’s a huge gathering.

Due to its quick measurement and high level of accuracy, the demand of the temperature gun is increasing every passing day during the Covid-19 pandemic.  


How does a temperature gun work?

A temperature gun(infrared thermometer) is a thermometer that infers temperature from a portion of the thermal radiation sometimes called black-body radiation emitted by the object being measured. By knowing the amount of infrared energy emitted by the object and its emissivity, the object’s temperature can often be determined within a certain range of its actual temperature.

Now we’ve got a clue about what we are making. Let’s get it started!


Bill of Material

1. DFRduino UNO 3.0  ×1

2. Gravity: I2C Non-contact IR Temperature Sensor For Arduino ×1

3. 0.96” IIC OLED Module Blue


I select the GY-906 MLX90614 Infrared Temperature sensor in this project. In addition to the non-contact temperature measurement, the sensor supports I2C communication protocol. SDA and SCL lines will be mainly used.


Features of MLX90614 Infrared Temperature sensor:

Operating Voltage: 3.6V~5V

Object Temperature Range: -70℃~382.2℃

Ambient Temperature Range: -40℃~125℃

Resolution: 0.02℃


As shown above, the sensing range can be regarded as a cone shape. So when the sensor is away from the object to be measured, the sensing area doubles. For every 1cm away from the object, and the sensing area increases by 2cm.

In this temperature gun, I am gonna put a laser diode on top of the sensor to better understand the sensing area the sensor is currently pointing to. I found that when the gun was pointing 2 cm away from the object, if the accuracy decreased as we left, the value was reliable.


The OLED screen is more frequently used in embedded electronic equipment because of its small size, lightweight and low power consumption. OLED screens of different sorts have various display colors: white, blue, yellow, blue dual color. There are also screens of various sizes and built-in driver chips on the market. SPI and IIC are two commonly used driver interfaces. This project uses a 0.96 inch blue IIC OLED module whose built-in driver chip is SSD1306.


There are many OLED display driver libraries. Here, we use Adafruit_SSD1306 and Adafruit_GFX.

In Arduino IDE, click Project - load Library - library manager to search and select the latest version for installation.


The I2C has been used by the temperature sensor, so the OLED will be connected as below:



First, we need to add the required library files to the program. Here, the wire Library (built-in) is used to communicate using the I2C protocol, and the ML90614 library is used to communicate with the sensor. SPI, GFX and SSD1306 libraries are used in the communication of 4-wire SPI protocol with OLED display module.


Define Head file:

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


Define OLCD Pin

#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13


Initialize OLED



Read Data

temperature = String(therm.object(), 2);


Data Algorithm:

float tempFloat;
                // First convert each temperature to Kelvin:
                if (_defaultUnit == TEMP_F)
                        // Convert from farenheit to Kelvin
                        tempFloat = (calcTemp - 32.0) * 5.0 / 9.0 + 273.15;
                else if (_defaultUnit == TEMP_C)
                        tempFloat = calcTemp + 273.15;
                else if (_defaultUnit == TEMP_K)
                        tempFloat = calcTemp;
                // Then multiply by 0.02 degK / bit
                tempFloat *= 50;
                rawTemp = (int16_t) tempFloat;
All Rights