ThisCalculator

Everyday

ESP32 Garden Heat Alerts: What MLX90640 Detects

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

ESP32 Garden Heat Alerts: What MLX90640 Detects

The MLX90640 infrared array sensor, when paired with an ESP32, detects the surface temperature of objects in its field of view without touching them, creating a low-resolution thermal map (32×24 pixels) that can be used to monitor plant leaf temperatures, soil surface warmth, and nearby heat sources in a garden. By comparing these temperatures to air temperature or preset thresholds, the ESP32 can trigger heat alerts when, for example, a leaf surface exceeds a safe limit or a compost pile begins to overheat. This article explains exactly what the sensor can and cannot detect, how to set up a garden alert system, and common pitfalls to avoid.

Formula

The core calculation for a heat alert is the difference between the surface temperature (measured by the MLX90640) and the ambient air temperature (measured by a separate sensor like a DHT22 or a thermistor):

ΔT = Tsurface − Tair

  • Tsurface – the temperature of the object (leaf, soil, compost) in degrees Celsius, as detected by the MLX90640.
  • Tair – the ambient air temperature in degrees Celsius, measured by a standard temperature sensor.
  • ΔT – the temperature difference. If ΔT exceeds a chosen threshold (e.g., 10°C), the ESP32 triggers an alert.

This simple difference is useful because plants typically cool themselves through transpiration; a leaf that is significantly warmer than the air may indicate water stress or a malfunctioning irrigation system.

Worked Example

Using the default values from the calculator above:

  1. Air temperature (Tair) = 25°C
  2. Leaf surface temperature (Tsurface) = 35°C
  3. Threshold = 10°C
  4. ΔT = 35 − 25 = 10°C
  5. Since ΔT (10°C) is not greater than the threshold (10°C), the alert status is 0 (no alert). If the leaf were 36°C, ΔT = 11°C, which would trigger an alert.

The calculator shows that the alert condition is strictly greater than the threshold. You can adjust the threshold based on your plants’ needs—for example, a 5°C difference might be critical for seedlings, while mature trees may tolerate 15°C.

What the MLX90640 Can Detect

The MLX90640 is a thermal camera module that measures infrared radiation emitted by objects. It returns a 32×24 grid of temperature readings, each representing the average surface temperature of a small area. In a garden context, this allows you to:

  • Monitor leaf temperature – Detect when leaves are significantly warmer than the air, which can indicate water stress or disease.
  • Check soil surface warmth – See if a seedbed is warm enough for germination or if mulch is trapping too much heat.
  • Spot heat sources – Identify hot spots in a compost pile, which can indicate active decomposition or a fire risk.
  • Detect animal or human presence – Warm-blooded animals emit strong infrared signatures, so the sensor can act as a simple motion detector.
  • Monitor greenhouse temperatures – Place the sensor to view a bench or floor to detect uneven heating.

However, the sensor measures surface temperature only. It does not measure air temperature, soil moisture, or humidity. It also cannot see through leaves or soil; it only sees what is in its direct line of sight.

How the Sensor Works

The MLX90640 uses a microbolometer array that absorbs infrared radiation and changes resistance accordingly. The onboard ASIC converts these resistance changes into digital temperature values for each pixel. The sensor has a field of view (FOV) of either 55° or 110°, depending on the variant (MLX90640ESF-BAB is 55°, MLX90640ESF-BAA is 110°). The ESP32 communicates with the sensor via I2C, reading the 768 temperature values and processing them.

To build a heat alert system, you typically:

  1. Connect the MLX90640 to the ESP32 using I2C pins (SDA, SCL).
  2. Add a separate air temperature sensor (e.g., DHT22) to measure ambient temperature.
  3. Write code that reads the MLX90640, extracts the maximum or average temperature from a region of interest (e.g., the center of the image), and compares it to the air temperature.
  4. If the difference exceeds a threshold, send an alert via Wi-Fi (e.g., a push notification, email, or MQTT message).

The MLX90640 is not a high-resolution thermal camera; it has only 768 pixels, so each pixel covers a relatively large area. At a distance of 1 meter, each pixel covers roughly 3 cm x 3 cm for the 55° version. This is sufficient for detecting overall leaf temperatures but not fine details.

Choosing the Right Sensor and Setup

When selecting an MLX90640 for garden use, consider the field of view and the distance to your plants. A 55° lens is better for focused monitoring of a single plant or a small bed, while a 110° lens covers a larger area but with less spatial resolution. Also, check the temperature range: the MLX90640 measures from -40°C to 300°C, which is ample for garden use.

For accurate readings, place the sensor so that the target fills the field of view. If you are monitoring a single leaf, place the sensor close (10-20 cm). For a whole bed, mount it higher, but remember that each pixel will then average the temperature over a larger area, which may dilute hot spots.

Environmental factors affect accuracy. Direct sunlight can heat the sensor housing and cause false readings. Shade the sensor from direct sun, and consider using a small shield to block rain and debris. Also, the emissivity of the target matters: the MLX90640 assumes an emissivity of 1.0 (blackbody), but leaves have an emissivity around 0.95-0.98, which introduces a small error (typically less than 1°C).

Common Problems and Misconceptions

A frequent misconception is that the MLX90640 measures air temperature. It does not; it measures surface temperatures. If you point it at the sky, it will read the temperature of the clouds or space, not the air. Therefore, you always need a separate air temperature sensor for the difference calculation.

Another issue is the refresh rate. The MLX90640 can be configured to update at 0.5, 1, 2, 4, 8, 16, 32, or 64 Hz, but higher rates increase noise. For garden monitoring, 1-2 Hz is usually sufficient. Also, the sensor has a warm-up time; readings taken in the first few seconds after power-on may be inaccurate. Wait at least 1-2 minutes for stable readings.

False alerts can occur if the sensor is pointed at a hot object like a rock in direct sunlight. To avoid this, either position the sensor to avoid such objects or use a region-of-interest mask in your code to ignore pixels that are not part of the plant canopy.

Finally, power consumption is a consideration. The MLX90640 draws about 15 mA, and the ESP32 can draw hundreds of mA when transmitting over Wi-Fi. For battery-powered garden nodes, use deep sleep and only wake up periodically to take a reading and send an alert.

Practical Applications

Beyond simple heat alerts, the MLX90640 can be used for:

  • Irrigation scheduling – If leaf temperature rises above air temperature by a certain amount, it may indicate that the plant is not transpiring enough, suggesting the need for water.
  • Compost monitoring – A hot compost pile should reach 55-65°C; the sensor can alert you if it gets too hot (risk of fire) or too cold (decomposition stalled).
  • Greenhouse climate control – Map temperature distribution to find cold drafts or hot spots near heaters.
  • Pest detection – Warm-blooded pests like rodents or rabbits can be detected as moving heat signatures, triggering a deterrent or an alert.

For advanced users, the ESP32 can process the 32×24 array to compute the maximum, minimum, and average temperature over the whole scene, and even track the movement of a hot object across the array.

Limitations and Accuracy

The MLX90640 has an absolute accuracy of ±2°C (typical) and a noise equivalent temperature difference (NETD) of 0.1°C at 1 Hz. This means that while it can detect relative differences of 0.1°C, the absolute temperature reading may be off by up to 2°C. For heat alerts that rely on a difference between leaf and air, the absolute error is less critical because both readings are taken with similar sensors, but the air sensor (e.g., DHT22) has its own error (±0.5°C), so the combined error can be around ±2.5°C.

Emissivity variations can also cause errors. Most organic materials (leaves, soil, wood) have high emissivity (0.9-0.98), so the error is small. However, shiny or metallic objects have low emissivity and will appear much colder than they actually are. If you are monitoring a greenhouse with reflective surfaces, be aware of this.

Also, the sensor cannot see through water vapor. In a humid greenhouse, the infrared signal may be attenuated, but the effect is usually negligible at typical garden distances.

Frequently Asked Questions

Can the MLX90640 measure air temperature?

No. It measures the surface temperature of objects in its field of view. To get air temperature, you need a separate sensor like a DHT22, BME280, or a simple thermistor.

What is the range of the MLX90640?

The sensor can measure temperatures from -40°C to 300°C, which is more than sufficient for garden environments. The maximum distance depends on the field of view and the size of the target; at 1 meter, the 55° version covers an area of about 1 meter x 0.75 meters.

How do I avoid false alerts from direct sunlight?

Shade the sensor from direct sun, and in your code, only consider pixels that are within a region of interest that excludes hot surfaces like rocks or bare soil. You can also use a threshold that is based on the difference from air temperature, rather than an absolute value.

Can I use the MLX90640 to detect animals in my garden?

Yes, warm-blooded animals will appear as hot spots in the thermal image. You can use the ESP32 to detect a pixel or group of pixels that are significantly warmer than the background and trigger an alert or a light.

What is the power consumption of the MLX90640?

The sensor draws about 15 mA at 3.3V. Combined with the ESP32, the total power consumption can be around 80-250 mA depending on Wi-Fi usage. For battery operation, use deep sleep and wake the system periodically.

How accurate is the MLX90640 for leaf temperature?

The absolute accuracy is ±2°C, but the relative accuracy (difference between two pixels) is much better, around 0.1°C. For heat stress detection, the relative difference between leaf and air is more important than the absolute value, so the sensor is suitable for this purpose.

Related

Formula used
in t_air | Air temperature | °C | 25 | 0
in t_leaf | Leaf surface temperature | °C | 35 | 0
in threshold | Alert threshold (°C above air) | °C | 10 | 0
out diff | Temperature difference | °C | t_leaf - t_air | 1
out alert | Alert status | - | (t_leaf - t_air > threshold) ? 1 : 0 | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.