Thermal Imaging Sensor Project

The Thermal Imaging Sensor project demonstrates how to interface an MLX90640 thermal camera sensor with an Arduino Mega to capture and display temperature data. This sensor is capable of non-contact temperature measurement, making it ideal for applications such as thermal imaging, object detection, and temperature monitoring.

How It Works

A thermal imaging sensor is an array of infrared thermopiles rather than a single detector. The AMG8833 Grid-EYE carries an 8×8 grid — 64 pixels — each measuring the long-wave infrared radiated by whatever is in its field of view. Everything above absolute zero emits such radiation, and its intensity rises with temperature, so each pixel reports a temperature without touching anything.

Sixty-four pixels sounds trivially small, and as an image it is. But it is enough to tell a person from a radiator, to locate the warmest point in a scene, and to track movement — which is what most projects actually need. The AMG8833 covers 0–80 °C with roughly ±2.5 °C accuracy at about 10 frames per second.

The MLX90640 is the step up, at 32×24 pixels — 768 in total — with a wider temperature range. It costs considerably more and needs more RAM to hold a frame, which matters on a board with 8 KB of SRAM.

Both communicate over I²C, on D20 (SDA) and D21 (SCL) for this board. Thermopiles respond to emitted infrared, so they see through darkness and smoke but not through glass, which is opaque at these wavelengths.

Components Needed

  • Arduino Mega 2560
  • MLX90640 Thermal Camera Sensor
  • Jumper Wires
  • Arduino Mega 2560
  • Power Supply

Wiring to the Arduino Mega 2560

Connect SDA and SCL to D20 (SDA) and D21 (SCL), VIN to the 5 V rail and GND to ground. The AMG8833 die runs at 3.3 V but Adafruit-style breakouts include a regulator and level shifting, so either supply works on those boards.

The default I²C address is 0x69, with 0x68 selectable by tying the AD_SELECT pin. If a scanner finds nothing, check that address first.

This board's 8 KB of SRAM comfortably holds a Grid-EYE frame and leaves room for processing.

Module pinArduino Mega 2560 pinFunction
SDAD20I²C data
SCLD21I²C clock
VIN5VSupply (board has a regulator)
GNDGNDCommon ground

Build and Upload

Open the Arduino IDE and create a new sketch.

Copy and paste the provided Arduino code into the sketch.

Upload the code to the Arduino Mega.

Open the Serial Monitor in the Arduino IDE (set to 9600 baud).

Observe temperature readings displayed in Celsius from the thermal camera sensor.

erify accurate temperature measurements and sensor stability.

Example Code

Reading the 8×8 thermal grid and locating the hottest pixel. Upload it with the board set to Arduino Mega 2560 and open the Serial Monitor at 9600 baud.

Reading the 8×8 thermal grid and locating the hottest pixel
#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];   // 64 values

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!amg.begin(0x69)) {                 // try 0x68 if this fails
    Serial.println("AMG8833 not found — check wiring and address");
    while (1) delay(1000);
  }
  delay(100);
}

void loop() {
  amg.readPixels(pixels);

  float hottest = -100, coldest = 500;
  int hotIndex = 0;

  for (int i = 0; i < AMG88xx_PIXEL_ARRAY_SIZE; i++) {
    if (pixels[i] > hottest) { hottest = pixels[i]; hotIndex = i; }
    if (pixels[i] < coldest) coldest = pixels[i];
  }

  Serial.print("hottest ");
  Serial.print(hottest, 1);
  Serial.print(" C at row ");
  Serial.print(hotIndex / 8);
  Serial.print(", col ");
  Serial.print(hotIndex % 8);
  Serial.print("   coldest ");
  Serial.print(coldest, 1);
  Serial.println(" C");

  delay(500);
}

Applications

A thermal imaging sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Presence and occupancy detection that works in complete darkness
  • Finding overheating components, bearings and electrical joints
  • People counting that preserves privacy, since 64 pixels identify nobody
  • Fire and hotspot detection in workshops and storage areas
  • Thermal insulation and draught surveys in buildings

Working with the Arduino Mega 2560

The Arduino Mega 2560 is built around the ATmega2560 and runs on 5 V logic with 8 KB of SRAM and 256 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Mega’s 8 KB of SRAM is four times the Uno’s, so larger buffers and lookup tables are practical.

I²C lives on D20/D21 rather than A4/A5 — wiring copied from an Uno tutorial will not work unchanged.

Four hardware UARTs mean a serial sensor can have its own port instead of fighting SoftwareSerial.

Arduino Mega 2560 characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A15 (sixteen channels)Determines how many analog sensors can share the board
PWM outputsD2–D13 and D44–D46Needed for brightness, speed and tone control
I²C pinsD20 (SDA) and D21 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2, D3, D18, D19, D20 and D21Required for counting fast or asynchronous events
Serialfour independent hardware UARTsMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • The sensor is not detected — the address is 0x69 by default, not the 0x68 many examples assume.
  • Everything reads roughly the same temperature — the field of view is filled by one surface. Point it at a scene with real contrast.
  • A person behind glass is invisible — glass blocks long-wave infrared. This is physical, not fixable in software.
  • Readings are noisy frame to frame — average two or three frames; thermopiles are inherently noisy at this price point.
  • The sketch fails to compile on a board with little RAM — the float array is too large; use a board with more SRAM.
  • Code written for an ESP board gives odd analog values — the Arduino Mega 2560 uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Mega 2560 I²C is on D20 (SDA) and D21 (SCL).

Taking It Further on the Arduino Mega 2560

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Mega 2560 specifically:

The Mega’s sixteen analog inputs make it the right board when several of these sensors must run at once. Where an Uno would need an external multiplexer, the Mega simply reads A0 through A15 directly.

Four hardware UARTs mean a GPS, a serial display and a debug console can coexist without SoftwareSerial, which is unreliable above 38400 baud and blocks interrupts while it transmits.

With 8 KB of SRAM there is room to buffer readings and do real processing — a rolling average over several hundred samples, or holding a full display frame in memory, both of which are impractical on an Uno.

Notes and Practical Limits

Interpolating 8×8 up to a smooth image is cosmetic. It looks better on a display but adds no information, and a hot pixel in the raw grid is more trustworthy than a smoothed blob.

Absolute accuracy of ±2.5 °C makes these parts unsuitable for medical temperature screening, whatever product listings claim. They are reliable for relative comparisons — which of these things is hottest — and that covers most genuine uses.