Infrared Temperature Sensor

From Waveshare Wiki
Jump to: navigation, search
Infrared Temperature Sensor
Infrared-Temperature-Sensor-1.jpg

Contact-less Infrared Temperature Sensor
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

  • Measures the surface temperature of an object without touching it, depending on the emitted IR waves of the target.
  • Also measures the average temperature over an area.
  • Contact-less, high precision, high resolution, fast response.
  • Calibrated before delivery, with gradient temperature compensation.
  • Works with 3.3V/5V MCU system directly, thanks to the built-in level translation.

Specifications

  • Power: 3.3V ~ 5V
  • Measuring range (area): -40°C ~ 85 °C
  • Measuring range (object): -70°C ~ 380 °C
  • Resolution: 0.02°C
  • Precision: ±0.5°C ( 0~50°C)
  • Field of view (FOV): 35°
  • Dimension: 28mm x 16 mm
  • Mounting holes size: 2.0mm

Pinouts

PIN Description
VCC 3.3V/5V
GND Power ground
SDA I2C data input
SCL I2C clock pin

Communication Protocol

This sensor has both digital PWM and SMBus (System Management Bus) output. In this document, we only introduce SMBus communication. SMBus is a 2 wires interface based on the I2C principle. You can treat SMBus as a simplified I2C.
Start Signal: SCL is HIGH, SDA hops from HIGH to LOW, begin to transmit data.

Infrared-Temperature-Sensor-UM-1.jpg

Stop signal: SCL is HIGH, SDA hops from LOW to HIGH, transmission is finished.
ACK: Every time Master (Slave) receives 8-bits data from Slave (Master), it will send an ACK back to the sender to inform that data has been transmitted successfully by holding the SDA inactive for a whole SCL period.

Infrared-Temperature-Sensor-UM-2.jpg
Infrared-Temperature-Sensor-UM-3.jpg

Every time Slave Device (SD) receives every 8-bits data, it will respond to an ACK/NACK.

  1. Master Devices (MD) will send an address of SD after initializing communication. Only the corresponding SD who can recognize the address will confirm, others keep silent.
  2. If no SD confirms the address, MD will cut off the communication and send the information again.

Note: The calculation result of PEC is based on all the bits except the START, REPEATED START, STOP, ACK and NACK. PEC is a polynomial (X8+X2+X1+1) of CRC-8. Every byte is transmitted MSB first.

Read Timing of SMBus

Infrared-Temperature-Sensor-UM-4.jpg
  1. MD will send a Start signal, then 8-bits data to SD. The data are combined with the 7-bits address of SD and “Read” operation bit. SD will respond to an ACK back after receiving.
  2. MD sends an 8-bits command to SD, the SD will reply with an ACK.
  3. MD sends a Start signal and the 8-bits data which is combined with the 7-bits address of SD and “Read” operation bit again. SD will reply to an ACK and send the data on its register to MD after receiving them.

Note: MD should send an ACK back every time it receives a byte. If MD receives PEC, it will send the Stop signal to stop communicating after ACK.

Write Timing of SMBus

Infrared-Temperature-Sensor-UM-5.jpg
  1. MD sends a Start signal and sends an 8-bits data which is combined with the 7-bits address of SD and “Write” operation bit to SD. SD will respond to an ACK signal.
  2. The MD sends an 8-bits command to SD and get the ACK from SD.
  3. MD sends low bytes of data first, after getting the ACK it will send the high bytes. Get the ACK then send the PEC bytes.
  4. At the last send the Stop signal to stop the communication.

RAM registers of MLX90614

Infrared-Temperature-Sensor-UM-7.jpg

EEPROM Registers of MLX90614

Infrared-Temperature-Sensor-UM-8.jpg

Commands of MLX90614

Infrared-Temperature-Sensor-UM-6.jpg

Note**:xxxxx stands for the low 5 bits of the address of RAM/ EEPROM registers which are read and written
Note**: Like Reading command. MLX90614 will respond to PEC after sending 16-bit data. Only 4 bits of PEC are necessary for MD. MD will stop communicating after sending the last byte. The difference between reading and Read Identifier is that Read Identifier doesn't repeat the start bit.
Read Identifier:

  • Data[7] - EEBUSY – The operation Read/Write on EEPROM is ongoing, active high.
  • Data[6] – Unused
  • Data[5] - EE_DEAD - EEPROM occurs Double Fault. Active High
  • Data[4] - INIT – POR is initializing. Active Low.
  • Data[3] – Nonexecution.
  • Data[2..0] and Data[8..15] – 0.

Program analysis

According to the protocol of SMBus and its timing we can know that. The Master will send a Start signal at the beginning. Then send 8-bit data which is combined with the 7-bit address of the Slave and Read/Write operation bit. If there is only one MLX90614 sensor, the 7-bit address is 0x00 by default. If there is more than one MLX90614 on the bus, we can change the Slave address on EEPROM. With the Start signal, if we want to read the MLX90614, we need to send (SA<<1) + 0 = 0x00 next. If we want to write, we need to send (SA<<1) + 1 = 0x01 next.
According to the RAM register address form above, the address of the Ambient Temperature register is 0x06, and it is 0x07 of the Object Temperature register on RAM. With the command form, we can know the operation code that accesses RAM is 0x00, and 0x20 accesses the EEPROM. Generally, we read temperature values from RAM and needn't read the EEPROM. To access the Ambient Temperature register on RAM, the command is 0x00 | 0x06 = 0x06. And use command: 0x00 | 0x07 = 0x07 to access the Object Temperature register.
Using STM32F code as examples, the driver uses PB8 and PB9 to simulate the timing of SMBus. The driver code is on SMBus.c file. We read the data of ambient and object temperature according to the timing introduced above, then calculate the ambient temperature and object temperature referred to in the datasheet.
Celsius degree (°C): ((TempData_H <<8) + TempData_L )*0.02 - 273.15.

Measure Principle

For a non-contact infrared temperature measuring module, Field of view (FOV) is a very important concept. The FOV is determined by the 50% radiation signal received by the thermoelectric pile. And it is related to the spindle axis of the sensor. The temperature detected is the weighted mean of the object temperature detected on FOV. So, the value is most correct while the object covers the whole FOV.

Infrared-Temperature-Sensor-UM-9.jpg

The sensor of this module is MLX90614ESF-BCC, the figure above is the FOV figure of BCC, FOV = 35°. It is that:
The radius of the measured object÷Distance from the sensor probe = tan35°, It is that if the radius of the measured object is 5CM, the Max measure distance is 7CM (Ensure that the temperature value is accurate)
General FOV figures of BAA:

Infrared-Temperature-Sensor-UM-10.jpg

Comparing these two sensors, the result of the operational test:
Take the temperature of the palm as a reference, if the BCC is within 7CM of the palm, the temperature is almost invariant. If the distance increases to 15CM, the temperature only reduces by 1°C. As for the BAA, the temperature has changed fast when it is 2CM away from the palm. Temperature reduces 1°C when the distance increased to 4CM.
BCC is better than BAA in performance. The distance and accuracy of measurement are relative to FOV, the FOV is smaller, the performance is better.

RPI Guide

Enable I2C Interface

Open a terminal and run the following commands:

sudo raspi-config 
Choose Interfacing Options -> I2C -> Yes.

Reboot Raspberry Pi:

sudo reboot

RPI open i2c.png

Install Library

If you use bookworm system, only the lgpio library is available, bcm2835 and wiringPi libarary cannot be installed or used. Please note that the python library does not need to install, you can directly run the demo.

BCM2835

#Open the Raspberry Pi terminal and run the following command
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.71.tar.gz
tar zxvf bcm2835-1.71.tar.gz 
cd bcm2835-1.71/
sudo ./configure && sudo make && sudo make check && sudo make install
# For more, you can refer to the official website at: http://www.airspayce.com/mikem/bcm2835/

WiringPi

#Open the Raspberry Pi terminal and run the following command
cd
sudo apt-get install wiringpi
#For Raspberry Pi systems after May 2019 (earlier than that can be executed without), an upgrade may be required:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v
# Run gpio -v and version 2.52 will appear, if it doesn't it means there was an installation error

# Bullseye branch system using the following command:
git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v
# Run gpio -v and version 2.70 will appear, if it doesn't it means there was an installation error

lgpio

wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
sudo make install 
#for more details, you can refer to https://github.com/gpiozero/lg

Python

#python3
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install RPi.GPIO
sudo pip3 install spidev

Download examples

Open a terminal of the Raspberry Pi

sudo apt-get install p7zip-full -y
sudo wget  https://files.waveshare.com/upload/5/53/Infrared-Temperature-Sensor-Code.7z
7z x Infrared-Temperature-Sensor-Code.7z
cd Infrared-Temperature-Sensor-Code/RaspberryPi/

Hardware connection

PCF8574 Raspberry Pi Description
Board order
VCC 5V Power input
GND GND Power ground
SDA 3 I2C data input
SCL 5 I2C clock pin

MLX90614 RPI 1.jpg

Run examples

C examples

cd ~/Infrared-Temperature-Sensor-Code/RaspberryPi/
cd wiringPi
sudo make clean
sudo make 
sudo ./main

Python example

cd ~/Infrared-Temperature-Sensor-Code/RaspberryPi/
cd python
sudo python3 MLX90614.py

Expected result

The temprature data are printed in terminal:

C

C example

Python

Python example

The STM32 examples are based on the STM32F103RBT6 and the STM32H743. The connection provided below is based on the STM32F103RB. If you need to use other STM32 boards, you may need to change the hardware connection and port the code yourself.

STM32

Hardware connection

Sensor STM32 Description
VCC 3.3V Power input
GMD GND Power ground
SDA PB9 I2C data input
SCL PB8 I2C clock pin
MLX90614 STM32 2.jpg

Examples

The examples are developed based on the HAL libraries. Download the Demo codes archive to your PC. Unzip and find the STM32 project from Infrared-Temperature-Sensor-Code\STM32\STM32F103RB\MDK-ARM.

  • Open the Infrared-Temperature-Sensor.uvprojx file by Keil.
  • Build and the project.
  • Program the project to your STM32 board.
  • Connect the UART1 of your STM32 board to the PC and check the serial data with SSCOM software.
MLX90614 STM32 1.jpg

The Arduino example is written for the Arduino UNO. If you want to connect it to other Arduino boards, you may need to change the connection.

Arduino

Hardware connection

Sensor Arduino Description
VCC 5V Power input
GMD GND Power ground
SDA SDA I2C data input
SCL SCL I2C clock pin
MLX90614 Arduino 2.jpg

Examples

  • Download the demo codes to your PC and unzip them.
  • Install the Arduino IDE on your PC.
  • Go into Infrared-Temperature-Sensor-Code/Arduino/WaveShare_MLX90614.
  • Run the WaveShare_MLX90614.ino file.
  • Select the correct Board and the Port.
MQ5 Arduino 1.jpg
  • Build the project and upload it to the board.
  • Open the serial monitor of the Arduino IDE or the SSCOM software and check the serial data.
MLX90614 Arduino 1.jpg

Resources

Document

Datasheet

FAQ

 Answer:
  • The actual test result shows that when the palm is used as a temperature reference and the sensor is within 7cm of the palm, the temperature is basically unchanged. When the distance is extended to 15cm, the temperature value drops by 1°C. The accuracy will decrease as the distance increases.
{{{3}}}
{{{4}}}

{{{5}}}


Support



Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)