Post

How to visualize MLX90614 Temperature (With InfluxDB & Grafana)

Raspberry PI and the MLX90614 IR Temp Sensor

  • What we will be doing:
    • Read Data from MLX90614 sensor with Python
    • Push the Data to InfluxDB
    • Visualize the MLX90614 sensor temperature data with Grafana

The MLX90614 Sensor

The MLX90614 GY-906 is an infrared (IR) temperature sensor module commonly used for non-contact temperature measurements. It’s also known as a pyrometer or non-contact thermometer.

  • Working Principle: The sensor measures the infrared radiation emitted by an object to determine its temperature.
    • All objects emit thermal radiation based on their temperature, and this radiation falls within the infrared spectrum.
  • Accuracy and Range: The MLX90614 GY-906 sensor can offer a relatively high level of accuracy for non-contact temperature measurements.
    • It has a wide temperature measurement range, typically spanning from -70°C to 380°C (-94°F to 716°F), depending on the specific model and calibration.
  • Two Sensors in One: The sensor actually contains two separate sensors within a single package: one to measure the temperature of the object being measured (object temperature) and another to measure the temperature of the sensor itself (ambient temperature).
    • This dual-sensor setup helps improve accuracy, as it compensates for changes in the sensor’s ambient temperature.
  • Communication Interface: The MLX90614 GY-906 sensor can communicate with other devices using the I2C (Inter-Integrated Circuit) communication protocol.

Dont forget to enable I2C in the Raspberry Pi.

1
2
3
4
sudo raspi-config
#-> interfacing options
#-> enable I2C
reboot #it is a must, I already try not to

The Setup

Vin to 3.3V - GND to gnd SCL to GPIO3 (SCL) SDA to GPIO2 (SDA)

If connected properly, you should see something different than – in at least one of the buckets when running:

1
i2cdetect -y 1

The Base Code: Python

We will require these packages to read the MLX90614 sensor data with Python:

The initial code of STJRush that we will tweak is this one below it is a repo with very interesting projects worth to check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This is the code to run the MLX90614 Infrared Thermal Sensor
# You'll need to import the package "Adafruit Blinka"
# You'll need to import the package "adafruit-circuitpython-mlx90614/"
# You'll need to enable i2c on the pi https://pimylifeup.com/raspberry-pi-i2c/
# Reboot after enabling i2C
# Sensor is connected to 3.3V, GND and the i2C pins 3(SDA) and 5(SCL)

import board
import busio as io
import adafruit_mlx90614

from time import sleep

i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
mlx = adafruit_mlx90614.MLX90614(i2c)

ambientTemp = "{:.2f}".format(mlx.ambient_temperature)
targetTemp = "{:.2f}".format(mlx.object_temperature)

sleep(1)

print("Ambient Temperature:", ambientTemp, "°C")
print("Target Temperature:", targetTemp,"°C")

Pushing MLX90614 Data to InfluxDB

We will be using 2 existing containers:

We have 3 mandatory components for this to work, all of them in this folder:

And another one if you want to replicate the docker build process:

  • The https://github.com/JAlcocerT/RPi/Z_IoT/MLX90614-to-InfluxDB/Dockerfile>

Why InfluxDB

Integrated Tools

  • Complete Suite: InfluxDB includes Telegraf for data collection, Chronograf for visualization, and Kapacitor for real-time processing and alerting, offering an all-in-one solution for data management.

Easy to Use

  • InfluxQL: Uses a SQL-like query language, facilitating ease of use for those familiar with SQL.
  • Minimal Setup: Simple setup and straightforward configuration process make it user-friendly for new adopters.

High Availability

  • Clustering: Available in the enterprise version, clustering ensures data redundancy and high availability.

Customizable Retention Policies

  • Automated Data Management: Enables customizable retention policies to efficiently manage large data volumes.

Extensive API Support

  • Robust API: Supports various programming languages, enhancing developer accessibility and integration.

Community and Ecosystem

  • Vibrant Community: A large and active community provides extensive support and resources.
  • Rich Ecosystem: Abundant third-party tools and integrations expand InfluxDB’s functionality.

These features position InfluxDB as an excellent choice for IoT, analytics, and domains requiring robust time-series data management.

Grafana Dashboard

This post is licensed under CC BY 4.0 by the author.