B4R Arduino MLX90614 infrared thermometer example

The MLX90614 is a non-contact infrared thermometer with a measurement range from -70 to +380 degree Celsius. Just connect the four leads to your Arduino and you will have a accurate thermometer with a resolution of 0.01 and a accuracy of 0.5 degrees, or for that matter you can use any microcontroller that can communicate with it through it’s I2C interface.

Being an I2C device you simply need to connect to the SDA, SCL and choose a suitable GND and Vin. I used 3.3v to be safe, although the breakout states 3 to 5v.

This version I chose comes with a breakout board with all of the components needed for operation. Here is a picture of that breakout board

Features:

Small size, low cost
Mounted on a breakout board with two types of pins
10k Pull up resistors for the I2C interface with optional solder jumpers
Factory calibrated in wide temperature range:
-40 … + 125 ° C for sensor temperature and
-70 … + 380 ° C for object temperature.
High accuracy of 0.5 ° C over wide temperaturerange (0 … + 50 ° C for both Ta and To) High (medical) accuracy calibration
Measurement resolution of 0.02 ° C
Single and dual zone versions
SMBus compatible digital interface
Customizable PWM output for continuous reading
Sleep mode for reduced power consumption

 

Layout

 

arduino and mlx90614
arduino and mlx90614

 

 

Code

 

The sketch below is fairly straightforward, most of the work is done in the Adafruit MLX96014 library

#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public timer1 As Timer
Public mlxambtempc As Float
Public mlxobjtempc As Float
Public mlxambtempf As Float
Public mlxobjtempf As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("setup",Null)
timer1.Initialize("timer1_Tick",1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
RunNative("loop",Null)
Log("Ambient temperature (c) is: ", mlxambtempc, "°C")
Log("Ambient temperature (f) is: ", mlxambtempf, "°F")
Log("Object temperature (c) is: ", mlxobjtempc, "°C")
Log("Object temperature (f) is: ", mlxobjtempf, "°F")
End Sub
#if C
#include <Wire.h>
#include "Adafruit_MLX90614.h"
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup(B4R::Object* o){
mlx.begin();
}
void loop (B4R::Object* o) {
b4r_main::_mlxambtempc =mlx.readAmbientTempC();
b4r_main::_mlxobjtempc =mlx.readObjectTempC();
b4r_main::_mlxambtempf =mlx.readAmbientTempF();
b4r_main::_mlxobjtempf =mlx.readObjectTempF();
}
#End if

 

Output

Here is the output

Ambient temperature (c) is: 22.0700°C
Ambient temperature (f) is: 71.7260°F
Object temperature (c) is: 28.2500°C
Object temperature (f) is: 82.8500°F
Ambient temperature (c) is: 22.0700°C
Ambient temperature (f) is: 71.7260°F
Object temperature (c) is: 26.1700°C
Object temperature (f) is: 79.1060°F
Ambient temperature (c) is: 22.0700°C
Ambient temperature (f) is: 71.7260°F
Object temperature (c) is: 26.8500°C
Object temperature (f) is: 80.3300°F
Ambient temperature (c) is: 22.0700°C
Ambient temperature (f) is: 71.7260°F
Object temperature (c) is: 22.9500°C
Object temperature (f) is: 73.3100°F

 

Links

Here is a link to the datasheet and also the breakout I purchased, come in at about $9 a piece.

MLX90614 datasheet
MLX90614 Contactless IR Infrared Thermometer Sensor Module IIC for Arduino