Arduino library · Sensors

Adafruit MLX90614: temperature without touching

Yes. You can use the Adafruit MLX90614 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (IR thermometer, MLX90614). The example below, "A forehead and the room with Adafruit MLX90614", runs on the Arduino Uno R3.

Built in on Mokxi: #include <Adafruit_MLX90614.h> and it builds, with nothing to install. Free, and no account needed.

What Adafruit MLX90614 Library does

The MLX90614 is the infrared thermometer in a small metal can found on GY-906 boards. A thermopile inside measures the infrared that a surface gives off, and the chip reports two temperatures: the object in front of it and the sensor’s own, called ambient. Adafruit’s library reads both over the SMBus flavor of I2C at 0x5A.

Each reading is one word from the chip’s RAM, followed by a packet error code that the library checks. A word that fails the check, or carries the chip’s error flag, comes back as NAN, so a bad connection shows up as nan instead of a believable wrong number. Temperatures arrive in steps of 0.02 kelvin and are converted to Celsius, with Fahrenheit versions of both calls.

Emissivity says how well a surface radiates compared with an ideal one. It lives in the chip’s EEPROM, readEmissivity() reports it and writeEmissivity() changes it; shiny metal needs a much lower value than skin or matte paint. In Mokxi the mlx90614 part has sliders for the object and ambient temperatures, and the example prints a forehead and a room. The emissivity is stored and read back there, but it does not change the simulated reading.

Library Manager nameAdafruit MLX90614 Library
AuthorAdafruit
Include#include <Adafruit_MLX90614.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesIR thermometer, MLX90614

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_MLX90614.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit MLX90614 Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit MLX90614 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 2.1.7, so a sketch written here builds there too.

What to know in the simulator: The emissivity is stored but does not change the reading.

The calls you will use

In the order a sketch meets them.

Adafruit_MLX90614 mlx = Adafruit_MLX90614()

Creates the driver for the default address, 0x5A.

mlx.begin()

Starts I2C and checks that the sensor answers; returns false otherwise. begin(0x5B) is for a chip whose address was changed.

mlx.readObjectTempC()

The temperature of what the sensor is pointed at, in Celsius, as a double; NAN on a failed read.

mlx.readAmbientTempC()

The sensor’s own temperature, which is close to the room’s once the module has settled.

mlx.readObjectTempF()

The object reading in Fahrenheit; readAmbientTempF() converts the ambient one.

mlx.readEmissivity()

The emissivity stored in EEPROM as a fraction of 1. The example prints 1.00, the factory setting.

mlx.writeEmissivity(0.95)

Writes a new emissivity to EEPROM, clearing the word first and waiting for each write to settle. Do it once, not on every pass.

Example: A forehead and the room with Adafruit MLX90614

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit MLX90614 test");
  if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  }
  Serial.print("Emissivity = ");
  Serial.println(mlx.readEmissivity());
}

void loop() {
  Serial.print("Ambient = ");
  Serial.print(mlx.readAmbientTempC());
  Serial.print("*C	Object = ");
  Serial.print(mlx.readObjectTempC());
  Serial.println("*C");
  delay(500);
}

Wiring

  • Arduino Uno R3 A4 to IR thermometer, MLX90614 SDA
  • Arduino Uno R3 A5 to IR thermometer, MLX90614 SCL
  • Arduino Uno R3 5V to IR thermometer, MLX90614 VIN
  • Arduino Uno R3 GND to IR thermometer, MLX90614 GND

Open it in the editor, wired and ready to run

Common errors and how to fix them

Error connecting to MLX sensor. Check wiring.

begin() got no answer at 0x5A. Check the bus wires and power on VIN, then run an I2C scanner; a module whose address was rewritten will show up somewhere else.

Object temperature prints nan

The packet error code did not match or the error flag was set, usually from long wires or missing pull-ups. Shorten the cable, keep the bus at the standard 100 kHz, and test with isnan() before using the value.

A forehead reads several degrees below body temperature

Skin is cooler than the body’s core, and from a distance the sensor also sees cooler background around the target. Hold it close and steady, and treat the result as a surface temperature, not a medical reading.

Questions and answers

What is the difference between object and ambient on the MLX90614?

Object is the surface the sensor is aimed at. Ambient is the chip itself, which the sensor needs in order to work out the object figure.

Does changing the emissivity change readings in Mokxi?

No. The value is written and read back, but the mlx90614 part reports its slider whatever emissivity is set. On a real chip it changes the object reading.

Projects that use Adafruit MLX90614 Library

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Try Adafruit MLX90614 Library without installing anything

Open the example, change the sketch, and keep your version in a free account.