Overview
In this project, you will learn how to make your own Infrared Thermometer using the MLX90614 Infrared Temperature Sensor & Raspberry Pi Pico using MicroPython Code. You can display the temperature reading on an SSD1306 0.96″ OLED Display. Earlier, we utilized temperature sensors like DS18B20, LM35, & MAX6675. However, these temperature sensors can only sense the temperature when heat is applied directly to their surface. But if you aim to measure the temperature of a very hot object such as a flame or hot iron, these sensors are not suitable.
The MLX90614 sensor employs contactless temperature sensing to gather temperature data without needing to physically touch the surface. For this project, we will connect the MLX90614 with the Raspberry Pi Pico and utilize MicroPython for programming. The OLED Display will show the value of ambient and object temperature.
We can use the MLX90614 to measure the temperature of hot objects such as machinery, flames, hot iron, and device CPUs. This sensor is also suitable for laboratory purposes; for instance, the MLX90614 can be used as an infrared thermometer for measuring body temperature. Earlier, during COVID-19, the demand for this sensor surged very high.
Bill of Materials
We need following components for making this IR Thermometer.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | Raspberry Pi Pico | 1 | Amazon | AliExpress |
| 2 | MLX90614 IR Temperature Sensor | 1 | Amazon | AliExpress |
| 3 | 0.96" I2C OLED Display | 1 | Amazon | AliExpress |
| 4 | Connecting Jumper Wires | 10 | Amazon | AliExpress |
| 5 | Breadboard | 1 | Amazon | AliExpress |
MLX90614 Contactless Infrared Temperature Sensor
The MLX90614 is an infrared thermometer for non-contact temperature measurements capable of measuring temperature between -70 to 380°C. The sensor uses IR sensitive thermopile detector chip and the signal conditioning ASIC integrated into a single chip. The thermometer comes factory calibrated with a digital SMBus output giving full access to the measured temperature in the complete temperature range(s) with a resolution of 0.02°C. Even though it works on SMBus protocol, but can be used with I2C pins.
MLX90614 Pinout Configuration
The MLX90614 sensor has 4 pins. The working voltage of the sensor is 3.6V to 5V but the 3.3V version is also available. It has I2C Pins as SDA & SCL. The SDA is the Serial data pin & SCL is the Serial Clock pin used for I2C Communication.
Specifications
1. Operating Voltage: 3.6V to 5V
2. Supply Current: 1.5mA
3. Object Temperature Range: -70°C to 382°C
4. Ambient Temperature Range: -40°C to 125°C
5. Accuracy: 0.02°C
6. Field of View: 80°
7. Distance between object and sensor: approx. 2cm-5cm
Working Principle of MLX90614
As mentioned earlier, the MLX90614 sensor can measure the temperature of an object with any physical contact. This is often made possible with a law called Stefan-Boltzmann Law, which states that each one objects and living beings emit IR Energy and therefore the intensity of this emitted IR energy is going to be directly proportional to the temperature of that object or living being.
Therefore the MLX90614 sensor calculates the temperature of an object by measuring the quantity of IR energy emitted from it.
Applications of MLX90614
- High-precision non-contact temperature measurements
- Thermal Comfort sensor for Mobile Air Conditioning control system
- Temperature sensing element for residential, commercial & industrial building air
- Automotive blind angle detection
- Industrial temperature control of moving parts
- Healthcare
- Livestock monitoring
- Movement detection
- Thermal relay/alert
- Body temperature measurement
Interfacing MLX90614 with Raspberry Pi Pico
Let us interface MLX90614 Infrared Temperature Sensor with Raspberry Pi Pico. The connection is very simple as MLX90614 works on I2C communication protocol.
Connect the I2C Pins of MLX90614 to Raspberry Pi Pico. Here we are connecting the SDA & SCL pin of MLX90614 to GP0 (Pin 1) & GP1 (Pin 2) of Pi Pico respectively. Provide the 3.3V & GND to the power pin of MLX90614.
You can use a breadboard for assembly and jumper wire for connection.
MicroPython Code for MLX90614 with Raspberry Pi Pico
Here is the MicroPython Code for reading the temperature reading from MLX90614 using the Raspberry Pi Pico.
The code continuously reads and displays the ambient and object temperatures using the MLX90614 infrared temperature sensor connected to a Raspberry Pi Pico via I2C. It initializes the I2C bus, reads temperatures from the sensor’s registers and converts these readings from Kelvin to Celsius. Finally it prints the results to the console in a loop until the script is manually stopped by the user.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
from machine import SoftI2C, Pin import time # MLX90614 I2C address MLX90614_I2C_ADDR = 0x5A # Register addresses for temperatures MLX90614_TA = 0x06 # Ambient temperature register MLX90614_TOBJ1 = 0x07 # Object temperature register # Initialize I2C on the specified SDA and SCL pins i2c = SoftI2C(sda=Pin(0), scl=Pin(1), freq=100000) def read_temp(register): """ Reads temperature from a specified register of the MLX90614. Args: register: The register address from which to read the temperature. Returns: The temperature in Celsius. """ # Read data from the sensor's register data = i2c.readfrom_mem(MLX90614_I2C_ADDR, register, 3) # Combine the bytes and convert to temperature in Celsius temp = (data[1] << 8) | data[0] temp = (temp * 0.02) - 273.15 # Convert from Kelvin to Celsius return temp try: print("* MLX90614 Temperature Readings *") while True: # Read sensor values for object and ambient temperatures object_temp = read_temp(MLX90614_TOBJ1) ambient_temp = read_temp(MLX90614_TA) # Print the temperature readings with the degree symbol print("Object Temperature: {:>5.2f}°C".format(object_temp)) print("Ambient Temperature: {:>5.2f}°C".format(ambient_temp)) print("-" * 30) # Print a separator line for clarity # Wait for a second before the next reading time.sleep(1) except KeyboardInterrupt: # Gracefully handle script termination by the user print('\nScript stopped by user') finally: # Any cleanup can be done here print('Goodbye!') |
Copy the above code and paste it on the Thonny IDE. Save the file with any name such as main.py. Then run the code.
The console will display the value of ambient as well as object temperature. You may place your hand or any hot object in front of MLX90614, you will observe immediate change in temperature reading.
Displaying Temperature Reading on OLED Display
Let us add an extra OLED Display to the above circuit, so that we can display the temperature readings on OLED Screen.
The OLED Display we are using here is SSD1306 I2C OLED Display Module. Here we are not using the same I2C pins as we assigned for MLX90614. Rather we are using different I2C pin to connect OLED Display with Raspberry Pi Pico. Connect the SCL Pin of OLED to GP19 and SDA Pin to GP18 of Raspberry Pi Pico.
You can insert the OLED Display on breadboard and use jumper wires to establish connection with Raspberry Pi Pico.
MicroPython Code for Displaying Temperature Reading on OLED
Let us write a MicroPython Code to read the temperature value from MLX90614 connected to Raspberry Pi Pico and display the readings on OLED Display.
For this code we require the SSD1306 OLED Driver. Therefore first copy the ssd1306.py to the Raspberry Pi Pico from following tutorial: OLED Display Pi Pico Guide.
The following code reads ambient and object temperatures using the MLX90614 infrared temperature sensor connected to a microcontroller via I2C, and displays these temperatures on an SSD1306 OLED display. It initializes two separate I2C buses for the sensor and the OLED display, respectively, continuously updates the display with the current temperature readings, and also prints these readings to the console.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
from machine import Pin, SoftI2C, I2C import time from ssd1306 import SSD1306_I2C # MLX90614 I2C address and register addresses MLX90614_I2C_ADDR = 0x5A MLX90614_TA = 0x06 # Ambient temperature register MLX90614_TOBJ1 = 0x07 # Object temperature register # Initialize I2C for MLX90614 sensor i2c_sensor = SoftI2C(sda=Pin(0), scl=Pin(1), freq=100000) # OLED Display Setup WIDTH, HEIGHT = 128, 64 i2c_display = I2C(1, scl=Pin(19), sda=Pin(18), freq=200000) oled = SSD1306_I2C(WIDTH, HEIGHT, i2c_display) def read_temp(register): data = i2c_sensor.readfrom_mem(MLX90614_I2C_ADDR, register, 3) temp = (data[1] << 8) | data[0] temp = (temp * 0.02) - 273.15 # Convert from Kelvin to Celsius return temp def center_text(text, line, font_width=8): # Calculate starting x position based on text length x = max(0, (WIDTH - len(text) * font_width) // 2) oled.text(text, x, line) try: print("* MLX90614 Temperature Readings *") while True: object_temp = read_temp(MLX90614_TOBJ1) ambient_temp = read_temp(MLX90614_TA) # Clear the display before adding new text oled.fill(0) # Display temperatures obj_temp_str = "{:.2f}C".format(object_temp) amb_temp_str = "{:.2f}C".format(ambient_temp) center_text("Object Temp:", 10) center_text(obj_temp_str, 20) # Adjust line spacing as needed center_text("Ambient Temp:", 40) center_text(amb_temp_str, 50) # Update the display with new content oled.show() # Print the readings to the console as well print("Object Temperature: {:>5.2f}°C".format(object_temp)) print("Ambient Temperature: {:>5.2f}°C".format(ambient_temp)) time.sleep(1) except KeyboardInterrupt: print('\nScript stopped by user') finally: print('Goodbye!') |
After running the code, the OLED will display the value of ambient temperature and object temperature both on OLED Screen.
To observe the change in the temperature reading introduce any hot/cold object or your hand in front of MLX90614.
You will see the rise in temperature reading displayed on OLED Screen. Thus, this is how we can use MLX90614 Infrared temperature sensor with Raspberry Pi Pico to read temperature without any physical contact.

















