RPi IoT Project - Non contact Temp sensors MLX90614 & InfluxDB
Raspberry PI and the MLX90614 IR Temp 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
- This video and github where really helpfull to me to get started:
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:
- Install Adafruit-blinka https://pypi.org/project/Adafruit-Blinka/
- and also: adafruit-circuitpython-mlx90614 https://pypi.org/project/adafruit-circuitpython-mlx90614/
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 Data from Python to InfluxDB
We will be using 2 existing containers:
We have 3 mandatory components for this to work, all of them in this folder:
- The adjusted Python code that pushed data: https://github.com/JAlcocerT/RPi/Z_IoT/MLX90614-to-InfluxDB/Python2InfluxDB.py
- https://github.com/JAlcocerT/RPi/Z_IoT/MLX90614-to-InfluxDB/Python2InfluxDB-Stack.yml
- The docker image that isolates all of this and allow us to deploy easier: https://hub.docker.com/r/fossengineer/iot/tags
- The tag is: dht11_sensor_to_influxdb
And another one if you want to replicate the docker build process:
- The https://github.com/JAlcocerT/RPi/Z_IoT/MLX90614-to-InfluxDB/Dockerfile>