Raspberry Pi and MLX90614 infrared thermometer

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.

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

gy-906-2-300x200

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

 

Code

The code below is fairly straightforward it was found on the internet and slightly modified to simply output to the console, save this as mlx90614.c

//gcc mlx90614.c -o mlx90614 -l bcm2835
#include <stdio.h>
#include <bcm2835.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#define AVG 1   //averaging samples
 
 
int main(int argc, char **argv)
{
    unsigned char buf[6];
    unsigned char i,reg;
    double temp=0,calc=0, skytemp,atemp;
    bcm2835_init();
    bcm2835_i2c_begin();
    bcm2835_i2c_set_baudrate(25000);
    // set address
    bcm2835_i2c_setSlaveAddress(0x5a);
 
    printf("\ndevice is working!!\n");
 
    calc=0;
    reg=7;
 
    for(i=0;i<AVG;i++)
	{
        bcm2835_i2c_begin();
        bcm2835_i2c_write (&reg, 1);
        bcm2835_i2c_read_register_rs(&reg,&buf[0],3);
        temp = (double) (((buf[1]) << 8) + buf[0]);
        temp = (temp * 0.02)-0.01;
        temp = temp - 273.15;
        calc+=temp;
        sleep(1);
    }
 
    skytemp=calc/AVG;
    calc=0;
    reg=6;
 
    for(i=0;i<AVG;i++){
        bcm2835_i2c_begin();
        bcm2835_i2c_write (&reg, 1);
        bcm2835_i2c_read_register_rs(&reg,&buf[0],3);
        temp = (double) (((buf[1]) << 8) + buf[0]);
        temp = (temp * 0.02)-0.01;
        temp = temp - 273.15;
        calc+=temp;
        sleep(1);
    }
 
    atemp=calc/AVG;
 
    printf("ambient temperature = %04.2f\n", atemp);
    printf("object temperature = %04.2f\n", skytemp);
 
    printf("done\n");
 
    return 0;
}

 

Compile this by using the following

gcc mlx90614.c -o mlx90614 -l bcm2835

Run it by typing the following

sudo ./mlx90614

 

Testing

You should something like this

mlx90614-output

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