What The Tech

Non-Contact Thermometer

Simple Touchless Temperature Measurements

Johann Wyss

Issue 42, January 2021

This article includes additional downloadable resources.
Please log in to access.

Log in

We take a look at these powerful temperature sensors and how you can use one in your next microcontroller project.

If you have been reading DIYODE for a while, you will likely no doubt notice that we are quite fond of temperature sensing projects. This is largely because temperature sensors are arguably one of the most useful sensors to a greater number of makers, from taking measurements of their workspace and living environment to the temperature of their 3D printer or server room, for example. This also means temperature sensors are designed for an incredibly diverse range of applications and to incredibly different tolerance’s/resolution.

For example, if you just want a ballpark idea of the temperature in your room then you have the DHT11. If you need a more precise level of accuracy for a manufacturing process or thermal control then a K-type thermocouple is more likely to satisfy your needs. What do you do though if you do not have the ability to physically connect the sensor to the device you are wanting to measure?

You could be wanting to measure the temperature of a rotating bearing, measuring the temperature of an object in a hazardous environment without risking injury to a human operator, or perhaps more poignant for 2020, measuring the temperature of a person without risking transmitting a virus.

Well, that is where the MLX90614 non-contact temperature sensor comes into play. This type of sensor, as the name suggests, is a “non-contact” type, which means the sensor does not need to make physical contact with the object under test. This makes this style of sensor incredibly useful for the situations above and countless more.

Naturally, when we found this sensor at our local Jaycar store we were keen to take a look and see how useful it is.

How it works

To understand how these sensors work you must first understand that only a tiny proportion of the light spectrum is in the range which is visible to humans.

Visible light has a wavelength between 380nm and 780nm on the light spectrum.

Note: While the radiation wavelengths between these values are considered visible, the vast majority of people can only see wavelengths between 380 and 700nm.

As you can see in this diagram, there is much more invisible radiation i.e. light outside of this spectrum range with shorter wavelengths, making up ultraviolet radiation, X rays and Gamma rays. Whereas, longer wavelengths include infrared, radar and other bands commonly used for communications. Non-contact temperature sensors operate in the Infrared radiation band from 780nm to 14um, the non-visible area of the light spectrum.

You may be asking yourself “what does light have to do with temperature"? Well as crazy as it sounds the first time hearing it, light is in fact an electromagnetic wave. Moreover, any body with a temperature above absolute zero (-273.15°C / 0°K) emits electromagnetic radiation. Some of this radiation is emitted as infrared radiation. This was discovered by William Hershel in 1800 while conducting experiments with light and separating the light into its bands using a prism. He discovered that the temperature of the light increased as he moved the thermometer from the blue bands and into the red bands, he also discovered that the hottest point was outside of the bands of visible light on the red side. His discovery was crucial in confirming the existence of non-visible infrared radiation and paved the way for other scientists such as Max Plank to make further discoveries in black body radiation, which made technology such as this non-contact thermometer possible.

Credit: Troy Benesch (CC-BY-SA-4.0) https://science.nasa.gov/ems/07_infraredwaves

Simply put, these sensors detect the level of black body radiation (black body radiation is the name given to the spectrum of light which is emitted by any object warmer than 0°K). The sensor itself has a lens which directs the black body radiation onto the sensor die itself. From this the temperature is approximated.

We say approximated as there are other factors needed to correctly derive the temperature from infrared radiation. The most critical is the reflectivity / emissivity of the object being tested. This type of temperature sensor takes a reading and is at that point comparing the result against a perfect black body (A black body is a perfect conductor and has an emissivity of 1.0). It’s not possible to have a perfect conductor, and as such, the thermometer accounts for this by assuming the object you're trying to scan has an emissivity of 0.95, as most organic substances fall close to this number.

However, highly reflective objects such as polished copper, for example, have an emissivity as low as 0.02. Using this style of thermometer, as well as even more complex styles, such as a thermal camera to measure the temperature of such materials will produce a false reading. This can be overcome by coating the surface under test with matte black paint or a piece of kapton tape, etc.

If you’re not getting the value you’re expecting from the temperature sensor, your first step should be to consider if the object you’re testing has a much lower emissivity.

NON-CONTACT IR SENSOR MODULE

According to the datasheet provided by Jaycar, this sensor has a field of view up to 45° off centre axis, and is powered by 5V. The I2C address of the module is 0x5A (7bit).

Hands On: Test Build

To put our Jaycar module to the test, we put together this simple circuit. Thankfully, controlling this sensor was an incredibly simple task thanks to the sensor featuring I2C, and our friends over at Sparkfun providing their awesome library, which is incredibly easy to use.

Electronics

If you're building the circuit using the Jaycar module you can simply, follow the Fritzing diagram or the following table.

SensorArduino Nano
Vcc / VDD5V
GND / VSSGND
SCL (Serial Clock) A5
SDA (Serial Data)A4
Parts Required: JaycarAltronicsCore Electronics
1 x Arduino Nano or CompatibleXC4414Z6372A000005
1 x MLX90614 Non-contact Temperature Sensor ModuleXC3704-CE07535

Parts Required:

OPTIONAL:JaycarAltronicsCore Electronics
1 x MLX90614 Sensor 3V Version--ADA1748^
1 x MLX90614 Sensor 5V Version--ADA1747^

OPTIONAL:

Prototyping hardware and accessories are also required. ^ See text regarding this sensor from Core Electronics.

The code

The code for this build can be downloaded from our website.

Setup

#include <Wire.h>
#include <SparkFunMLX90614.h>
IRTherm therm;
unsigned long timeSpent = 0;
int duration = 1000;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  if (therm.begin() == false) {
    Serial.println("DIYODE non-contact temperature 
sensing project failed to connect with sensor");
    while (1);
  }
  Serial.println("DIYODE non-contact 
temperature sensing project successfully 
connected with sensor");
 }

Loop

  if ((therm.read()) && ((millis() >= 
(timeSpent + duration)))) {
    timeSpent += duration;
    Serial.println("DIYODE non-contact 
temperature sensor");
    Serial.print("Object: " + 
String(therm.object(), 2));
    Serial.println("C");
    Serial.print("Ambient: " + 
String(therm.ambient(), 2));
    Serial.println("C");
    Serial.println();  
  }
 } 

Python code

Of course, we could just watch the serial data output from the serial monitor in the Arduino IDE or we could use PuTTY or another type of terminal program. For our first experiments with the sensor, we have decided to add a little something extra by trying our hand at a Python script which will display the output data on the Windows command prompt.

This way, we demonstrate how you can use the data from the Arduino in a real-world situation. You could, for example, be using such a sensor as part of a bigger system and need to log it or pass it onto a different piece of software. If your project was largely PC based, this would allow you to easily take real world inputs and incorporate it into your solution.

Note: You are not limited to the temperature sensor we’ve used. You could easily import data from any sensor for your project. As such, it is a very powerful tool to add to your toolkit.

Your first step is to download and install Notepad++: https://notepad-plus-plus.org/downloads/

This awesome little text editor not only allows you to open your usual text files, but it also allows you to write programs and applies the formatting for many different languages. This makes writing small programs / scripts like this very simple.

With it installed, you can install Python on your PC.

From the command prompt type:

Python

Then, Press enter.

If you have Python installed, you will see a screen like below showing the Python build. In our case, 3.8.6.

If you don’t have Python installed, the Windows app store will open up and you can select the Install button to download and install it on your windows machine.

Once you’re done, open up Notepad++.

Next, set the Language to Python, which will help us to identify syntax errors in our code as we learn the new language.

To do this select Language > P > Python.

You can now enter the following code:

import serial
with serial.Serial('COM17', 9600) as ser:
   while True:
     data = ser.readline().rstrip().
decode( "utf-8" )
     print(data)

In this line, one import serial invokes the pyserial module.

with serial.Serial('COM17', 9600) as ser: sets the serial port as Com 17 and the baud rate as 9600. These will need to match the com port and baud rate settings of your Arduino. Be sure to find the correct COM port before writing the Python script.

While True: creates an inescapable loop condition not unlike the while(1){ } statement we often use in Arduino. This will make the lines of code preceding this statement repeat forever.

Note: This isn’t ideal practice as the only way to end the script would be to close the terminal down. Ideally, we would add a condition in which the program can end. How would you do this?

data = ser.readline().rstrip().decode( "utf-8" ) places the incoming data from the serial port into a variable called data. It also strips the control data such as carriage return and datatype info, giving a cleaner output.

Save the script. In our case, we saved the script as:

D:diyodetest.py

This way, it will be easy to find and execute later from the command prompt. With the python script created, we now need to install the dependencies on our computer.

To install Python Serial onto your PC you use the following command from the Windows command prompt.

pip install pyserial

This will download and install the required Python libraries to enable serial communications on your computer. If you have any issues, you can just as easily remove the software with the command:

pip uninstall pyserial

You can now open a Windows command prompt and use the following commands:

CD
D:
Python diyodetest.py

This will bring up the following screen and the temperature measurements from the Arduino will scroll down the screen.

Congratulations. You have now successfully taken code from an Arduino sketch and imported it into a desktop PC using a very simply Python script.

Where to from here?

From here, you can log the data or even use it in a larger control scheme.

You can even send commands to the serial port. Rather than just polling the port, thus you can create a script that requests the data from the Arduino.

Projects with this IR sensor are endless. Use it to sound an alarm if an object is too hot or too cold, trigger a relay if an object within a temperature range is met, display the temperature on an LCD screen, and more.

MLX90614 Sensor

Our friends at Core Electronics sell the Melexis sensors on their own, thanks to Adafruit. This sensor can easily be used as a substitute in this project by following the pinout shown in the datasheet.

Note: If you’re using the 3.3V sensor from Core Electronics Vcc / VDD will be the 3.3V pin of the Arduino Nano. You will also need to add a voltage divider to the SDA and SCL I2C pins.

A look at the MLX90616 datasheet by Melexis states the following specifications:

PACKAGE:TO-29 can
SENSOR TEMP RANGE:-40 to 125°C
OBJECT TEMP RANGE:-70 to 380°C
ACCURACY:+/-0.5°C
MEASUREMENT RESOLUTION0.02°C
POWER:2.7-3.6V or 4.5-5.5V models available
Johann Wyss

Johann Wyss

DIYODE Staff Technical Writer