Home / Tutorials / Arduino Tutorial / Arduino Interfacing with MLX90614 (GY-906) Sensor
pcbway
Arduino MLX90614

Arduino Interfacing with MLX90614 (GY-906) Sensor

The MLX90614 is a really cool infrared thermometer sensor that can measure temperature without even touching an object. It works by detecting infrared radiation (heat) emitted by an object and converting it into a temperature reading. This makes it perfect for projects where you want to measure temperature from a distance, like reading the temperature of a hot surface, or even someone’s forehead.

In this article, I’ll show you how to use the MLX90614 with an Arduino. It’s a super simple setup and a great sensor to add to your toolkit.

What You’ll Need

  • Arduino board (like an Uno)
  • MLX90614 sensor
  • 16×2 LCD display
  • Jumper wires
  • Breadboard (optional)
  • A computer with the Arduino IDE installed

How the MLX90614 Works

The MLX90614 has two types of temperature readings:

  1. Object Temperature: This is the temperature of the object you’re pointing the sensor at.
  2. Ambient Temperature: This is the temperature of the surrounding air.

The sensor communicates with the Arduino using the I2C protocol. I2C is a simple way for devices to communicate by using just two wires: SDA (data line) and SCL (clock line). The MLX90614 uses these to send temperature data to the Arduino.

Wiring the MLX90614 to the Arduino

First, let’s wire it up. The MLX90614 has four pins:

  1. VCC: Power (3.3V or 5V)
  2. GND: Ground
  3. SDA: Data line
  4. SCL: Clock line

Here’s how to connect it to the Arduino:

  • VCC to the 3.3V (or 5V) pin on the Arduino
  • GND to GND on the Arduino
  • SDA to A4 on the Arduino
  • SCL to A5 on the Arduino

Arduino MLX90614

Make sure everything is connected securely. Now let’s move on to the code.

Writing the Code

We’ll use the Adafruit MLX90614 library to make reading temperatures easy. You can install this library in the Arduino IDE by going to Sketch > Include Library > Manage Libraries, then search for “Adafruit MLX90614” and install it.

Here’s a simple code to read and print the temperature:

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

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

void loop() {
  Serial.print("Ambient Temp = ");
  Serial.print(mlx.readAmbientTempC());
  Serial.print(" °C\tObject Temp = ");
  Serial.print(mlx.readObjectTempC());
  Serial.println(" °C");

  delay(1000); // Read every second
}

How the Code Works

  • Wire.h is the library that handles I2C communication.
  • Adafruit_MLX90614.h is the library that makes interacting with the sensor easy.
  • We create an object called mlx to represent the sensor.
  • In the setup(), we start communication with the sensor using mlx.begin() and start the serial monitor with Serial.begin(9600) so we can see the temperature readings.
  • In the loop(), we read both the ambient temperature (mlx.readAmbientTempC()) and the object temperature (mlx.readObjectTempC()). These are printed to the serial monitor every second.

Adding a 16×2 LCD to Display Temperature

Now, let’s take it a step further by displaying the temperature readings on a 16×2 LCD. The LCD will show both the ambient and object temperatures in real-time.

What You’ll Need

  • A 16×2 LCD display
  • A potentiometer (for contrast adjustment)
  • Jumper wires

Wiring the LCD to the Arduino

A 16×2 LCD typically has 16 pins. Here’s how to connect it:

  • VSS to GND
  • VDD to 5V
  • VO to the middle pin of the potentiometer (for adjusting contrast)
  • RS to Pin 12 on the Arduino
  • RW to GND
  • E to Pin 11 on the Arduino
  • D4 to Pin 5 on the Arduino
  • D5 to Pin 4 on the Arduino
  • D6 to Pin 3 on the Arduino
  • D7 to Pin 2 on the Arduino
  • A (Anode) to 5V (for the LCD backlight)
  • K (Cathode) to GND

Arduino MLX90614 with LCD

Updating the Code to Include the LCD

You’ll also need the LiquidCrystal library, which is built into the Arduino IDE, so no need to install anything. Here’s the updated code that displays the temperature on the LCD:

 

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

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // Pins for the LCD

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

  // Initialize the LCD and set the size (16 columns, 2 rows)
  lcd.begin(16, 2);
  lcd.print("Temp Monitor");  // Display a title on the LCD
  delay(2000);                // Wait for 2 seconds
  lcd.clear();                // Clear the display
}


void loop() {
  float ambientTemp = mlx.readAmbientTempC();
  float objectTemp = mlx.readObjectTempC();

  // Print to Serial Monitor
  Serial.print("Ambient Temp = ");
  Serial.print(ambientTemp);
  Serial.print(" °C\tObject Temp = ");
  Serial.print(objectTemp);
  Serial.println(" °C");

  // Display on LCD
  lcd.setCursor(0, 0);  // Set cursor to first row
  lcd.print("Amb: ");
  lcd.print(ambientTemp);
  lcd.print(" C");

  lcd.setCursor(0, 1);  // Set cursor to second row
  lcd.print("Obj: ");
  lcd.print(objectTemp);
  lcd.print(" C");

  delay(1000);  // Update every second
}

How the LCD Code Works

  • LiquidCrystal lcd(12, 11, 5, 4, 3, 2) sets up the LCD with the correct pin connections.
  • In the setup(), we initialize the LCD using lcd.begin(16, 2) to tell it that we’re using a 16×2 display.
  • We use lcd.print() to write the temperature readings to the display.
  • The lcd.setCursor() function positions the text. For example, lcd.setCursor(0, 0) places the text at the start of the first row, and lcd.setCursor(0, 1) moves it to the start of the second row.

Uploading the Code and Testing

Once you’ve uploaded this code, you should see the ambient and object temperatures displayed on the 16×2 LCD. The Serial Monitor will also continue printing the temperatures, so you can check both if you like.

Conclusion

With the MLX90614 sensor and an Arduino, you can easily measure temperatures from a distance. Adding a 16×2 LCD makes it even more convenient, as you can display the readings without needing a computer or serial monitor. This combination can be useful for temperature monitoring projects, from environmental sensors to non-contact thermometers.

Now you have a guide on how to read temperatures with the MLX90614 and display them on a 16×2 LCD! Let me know if you want to add more to it.

 

Check Also

Arduino Tones

Creating Tones with Arduino

One of the fun and engaging projects with Arduino is creating tones using a piezo …