The MLX90640 thermal imaging camera opens a fascinating dimension of electronics — seeing heat distribution invisible to the naked eye. This 32×24 pixel infrared sensor array creates a thermal heatmap, enabling you to detect hot spots in circuits, find heat leaks, identify overheating components, and even build a primitive people detector. This guide covers wiring, configuration, and visualisation for both Arduino and Raspberry Pi.
Table of Contents
- MLX90640 Overview and Specifications
- Wiring to Arduino and Raspberry Pi
- Arduino Code and Library
- Python Visualisation on Raspberry Pi
- Image Interpolation for Better Display
- Practical Applications in India
- Frequently Asked Questions
MLX90640 Overview and Specifications
- Sensor array: 32×24 pixels (768 temperature measurements)
- Temperature range: -40°C to +300°C (-40°C to +1000°C for high-temp version)
- Temperature accuracy: ±1.5°C
- Interface: I2C, up to 400 kHz
- I2C address: 0x33 (default)
- Field of view: 55°×35° (standard) or 110°×75° (wide)
- Frame rate: 0.5–64 Hz (configurable)
- India price: ₹1,500–3,500 for breakout board
Wiring to Arduino and Raspberry Pi
MLX90640 Breakout to Arduino Uno:
VIN -> 3.3V (some breakouts accept 5V via regulator)
GND -> GND
SDA -> A4 (SDA)
SCL -> A5 (SCL)
MLX90640 Breakout to Raspberry Pi:
VIN -> Pin 1 (3.3V)
GND -> Pin 6 (GND)
SDA -> Pin 3 (GPIO2, SDA1)
SCL -> Pin 5 (GPIO3, SCL1)
I2C pull-up: Most breakout boards include 4.7kΩ pull-ups.
Enable I2C on Raspberry Pi: sudo raspi-config > Interface Options > I2C
Arduino Code and Library
#include
#include
Adafruit_MLX90640 mlx;
float frame[32*24]; // Temperature array
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // 400 kHz I2C
if (!mlx.begin(MLX90640_I2CADDR_DEFAULT, &Wire)) {
Serial.println("MLX90640 not found!");
while(1);
}
mlx.setMode(MLX90640_CHESS); // Chess pattern interpolation
mlx.setResolution(MLX90640_ADC_18BIT);
mlx.setRefreshRate(MLX90640_2_HZ); // 2 Hz (manageable for Arduino)
Serial.println("MLX90640 ready");
}
void loop() {
if (mlx.getFrame(frame) != 0) {
Serial.println("Failed to get frame");
return;
}
// Find min and max temperatures
float minT = 999, maxT = -999;
for (int i = 0; i < 768; i++) {
if (frame[i] maxT) maxT = frame[i];
}
Serial.printf("Min: %.1f°C Max: %.1f°C
", minT, maxT);
// Print thermal map as ASCII (useful for Serial plotter)
for (int row = 0; row < 24; row++) {
for (int col = 0; col < 32; col++) {
float temp = frame[row * 32 + col];
// Map temperature to ASCII gradient
int idx = map(temp, minT, maxT, 0, 9);
const char gradient[] = " .:-=+*#%@";
Serial.print(gradient[idx]);
}
Serial.println();
}
Serial.println("---");
}
Python Visualisation on Raspberry Pi
import board
import busio
import adafruit_mlx90640
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
import time
i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
mlx = adafruit_mlx90640.MLX90640(i2c)
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ
frame = [0] * 768
fig, ax = plt.subplots()
plt.ion()
while True:
try:
mlx.getFrame(frame)
except Exception as e:
continue
data = np.array(frame).reshape(24, 32)
# Interpolate to higher resolution for display
data_interp = ndimage.zoom(data, 10) # 240x320 display
ax.clear()
im = ax.imshow(data_interp, cmap='inferno',
vmin=20, vmax=40, # Adjust for your range
interpolation='bilinear')
ax.set_title(f'Thermal Camera | Max: {np.max(data):.1f}°C')
plt.colorbar(im, ax=ax, label='Temperature (°C)')
plt.draw()
plt.pause(0.1)
Practical Applications in India
- Electronics diagnostics: Identify overheating components in PCBs — hot spots indicate failed capacitors, overloaded resistors, or failing ICs before they cause visible damage.
- Electrical panel inspection: Detect overheating connections in switchboards — a common cause of electrical fires in Indian buildings. IR thermal cameras are used by licensed electricians for this purpose.
- Building energy audit: Find heat leaks in walls, roofs, and around air conditioners in Indian buildings — the MLX90640 is basic but sufficient for identifying obvious thermal bridges.
- People counting: The MLX90640’s 32×24 resolution is sufficient to detect and count people passing by a doorway — a low-cost alternative to computer vision for occupancy monitoring.
- Solar panel inspection: Detect cracked cells or delamination hotspots on rooftop solar panels — hotspots reduce efficiency and indicate panel degradation.
Frequently Asked Questions
What is the resolution of MLX90640 in real terms?
32×24 pixels is very low — think of it as a 768-pixel thermal “image” with each pixel showing the average temperature of an area. At 1 metre distance with the standard 55°×35° lens, each pixel covers approximately 1.7cm × 1.5cm of the scene. This is sufficient to see a human silhouette, detect hot components on a PCB, or find a heat leak around a window — but not enough to read text or identify fine features.
Can the MLX90640 detect fever in humans?
Theoretically yes, but not reliably in practice without careful calibration. The ±1.5°C accuracy and environmental temperature effects make fever detection (±0.3°C accuracy required) unreliable without compensation algorithms. During COVID-19, specialised cameras with better accuracy (FLIR Lepton 3.5, ±0.05°C) were used for fever screening. The MLX90640 is not appropriate as a medical-grade fever detector.
Why is my MLX90640 reading taking too long on Arduino?
The MLX90640 requires two sub-pages of data to form a complete frame, and at 400 kHz I2C, reading 768 × 3 bytes takes approximately 50–100ms per frame. On Arduino Uno, the I2C library overhead makes this even slower. Use a faster board (Arduino Due, ESP32, or Raspberry Pi) for smoother thermal imaging. On ESP32, the MLX90640 at 8 Hz refresh is very practical.
Add comment