A look at the MLX90614 infrared thermometer

In this example we look at the MLX90614 with various usage examples

The MLX90614 is an infrared thermometer for non-contact temperature measurements. Both the IR sensitive thermopile detector chip and the signal conditioning ASIC are integrated in the same TO-39 can. Integrated into the MLX90614 are a low noise amplifier, 17-bit ADC and powerful DSP unit thus achieving high accuracy and resolution of the thermometer.

The thermometer comes factory calibrated with a digital SMBus output giving full access to the measured temperature in the complete temperature range(s) with a resolution of 0.02°C.

The user can configure the digital output to be pulse width modulation (PWM). As a standard, the 10-bit PWM is configured to continuously transmit the measured temperature in range of -20 to 120°C, with an output resolution of 0.14°C.

Features and benefits

Factory calibrated in wide temperature range: -40 to 125°C for sensor temperature and -70 to 380°C for object temperature
High accuracy of 0.5°C over wide temperature range (0..+50 C for both Ta and To)
Medical accuracy of 0.1°C in a limited temperature range available on request
Measurement resolution of 0.02°
Single and dual zone versions
SMBus compatible digital interface for fast temperature readings and building sensor networks
Customizable PWM output for continuous reading
Available in 3V and 5V versions

Arduino Example

We start off with the arduino example, we also tested this on a number of other boards that were supported by the Arduino IDE including the ESP32, ESP8266 and a LinkIt one

Parts List

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
MLX90614 module MLX90614 Contactless Temperature Sensor Module
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Connection

Arduino MLX90614 module
5v Vin
Gnd GND
SDA SDA
SCL SCL

Code

The sketch below is fairly straightforward, most of the work is done in the Adafruit MLX96014 library which outputs the result via the serial monitor

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() 
{
  Serial.begin(9600);

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() 
{
  Serial.print("Ambient = "); 
  Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); 
  Serial.print(mlx.readObjectTempC()); 
  Serial.println("*C");
  Serial.print("Ambient = "); 
  Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); 
  Serial.print(mlx.readObjectTempF()); 
  Serial.println("*F");

  Serial.println();
  delay(500);
}

[/codesyntax]

 

Raspberry Pi Example

You can use any Raspberry Pi for this example – we used a Pi 3. The code example is in C but there are also python examples that work just as well

Parts List

Name Link
Raspberry Pi 3 Raspberry Pi 3 Model B With WiFi & Bluetooth
MLX90614 module MLX90614 Contactless Temperature Sensor Module
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Connection

Raspberry Pi MLX90614 module
3v3 Vin
Gnd GND
Pin 3 – GPIO2 SDA
Pin 5 – GPIO3 SCL

Code and Testing

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

[codesyntax lang=”cpp”]

//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;
}

[/codesyntax]

 

Compile this by using the following

[codesyntax lang=”bash”]

gcc mlx90614.c -o mlx90614 -l bcm2835

[/codesyntax]

Run it by typing the following

[codesyntax lang=”bash”]

sudo ./mlx90614

[/codesyntax]

You should something like this

MBed example

Our next example uses the MBed online compiler and an MBEd LPC1768 board. You could get this working for any board that the compiler supports

Parts List

Name Link
MBED board MBED from Amazon
MLX9014 module MLX90614 Contactless Temperature Sensor Module
connecting wire UNO R3 CH340G/ATmega328P, compatible for Arduino UNO

Layout

Code

We used the online compiler and imported the following into it

https://os.mbed.com/components/MLX90614-I2C-Infrared-Thermometer/

[codesyntax lang=”cpp”]

#include "mbed.h"
#include "mlx90614.h"

DigitalOut myled(LED1); //displays I2C wait
I2C i2c(p28,p27);   //sda,scl
Serial pc(USBTX,USBRX);  //serial usb config

MLX90614 IR_thermometer(&i2c);
//setup an MLX90614 using MLX90614 library from
// http://mbed.org/users/aquahika/libraries/MLX90614/lsixz6

float temp; //temperature in degrees C

int main() {
    while (1) {
        myled=1; // if led1 on - waiting on I2C
        if (IR_thermometer.getTemp(&temp)) {
            //gets temperature from sensor via I2C bus
            myled=0;
            //print temperature on PC
            printf("Temperature is %5.1F degrees C\r\n",temp);
        }
        //wait for device to produce next temperature reading
        wait(0.5);
    }
}

[/codesyntax]

using a terminal program such as TeraTerm you should see something like this

Temperature is 26.4 degrees C
Temperature is 27.0 degrees C
Temperature is 27.0 degrees C
Temperature is 26.9 degrees C
Temperature is 27.0 degrees C
Temperature is 26.9 degrees C
Temperature is 26.8 degrees C
Temperature is 26.8 degrees C

 

Links

https://www.melexis.com/-/media/files/documents/datasheets/mlx90614-datasheet-melexis.pdf

LEAVE A REPLY

Please enter your comment!
Please enter your name here