Arduino library · Sensors

SparkFun MLX90614: an example that runs

Yes. You can use the SparkFun 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, "Read an object and the room with IRTherm", runs on the Arduino Uno R3.

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

What SparkFun MLX90614 does

The infrared thermometer as IRTherm: begin(), setUnit(TEMP_C | TEMP_F | TEMP_K), read(), object(), ambient(), minimum() and maximum(). That is what SparkFun MLX90614 covers. The sketch below uses it on the Arduino Uno: “Read an object and the room with IRTherm”.

The SparkFun MLX90614 library's interface (the IRTherm class), for the MLX90614 infrared thermometer on I2C.

read() fetches the object and ambient temperatures from the chip together; object() and ambient() return what it fetched in the unit set last, and minimum() and maximum() the lowest and highest each has been since the sketch began. TEMP_RAW is the chip's own 16-bit number (0.02 K a step).

The calls follow release 1.1.0 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameSparkFun MLX90614
AuthorSparkFun
Include#include <SparkFunMLX90614.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 <SparkFunMLX90614.h> and the sketch compiles, with no download, no zip and no Library Manager.

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

The calls you will use

In the order a sketch meets them.

IRTherm therm

Makes therm, the IRTherm object the calls below are made on.

therm.begin()

Starts it up. Call it once in setup(). Arguments: address.

therm.setUnit(TEMP_C)

Sets the unit to the value you pass in.

therm.read()

Returns the value as a whole number.

therm.object()

Returns the object as a decimal number.

therm.ambient()

Returns the ambient as a decimal number.

Example: Read an object and the room with IRTherm

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

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

IRTherm therm;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  therm.begin();
  therm.setUnit(TEMP_C);
}

void loop() {
  if (therm.read()) {
    Serial.print("Object: ");
    Serial.println(therm.object(), 1);
    Serial.print("Ambient: ");
    Serial.println(therm.ambient(), 1);
    therm.setUnit(TEMP_F);
    Serial.print("Object F: ");
    Serial.println(therm.object(), 1);
    therm.setUnit(TEMP_C);
  } else {
    Serial.println("no reading");
  }
  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

Try SparkFun MLX90614 without installing anything

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