JAlcocerTech E-books

Chapter 7 — The Sensor Dictionary: DHT, MLX, and What to Buy First

There are hundreds of sensor types. These are the ones that appear repeatedly in real IoT projects — cheap, well-documented, and reliably supported by MicroPython and Arduino libraries.

Temperature and Humidity

DHT22 (also called AM2302): the workhorse. Measures temperature (-40 to +80°C) and relative humidity (0–100%). Single-wire protocol. One sensor, three pins (VCC, GND, DATA). Accuracy: ±0.5°C temperature, ±2–5% humidity. Update interval: minimum 2 seconds.

DHT11: cheaper, less accurate (±2°C, ±5% humidity), narrower range (0–50°C). Use it for learning and non-critical monitoring. Use the DHT22 for anything you care about.

Both sensors are susceptible to condensation. Don’t use them in environments where humidity regularly hits 100% — the readings will drift and eventually the sensor will fail.

Infrared (Non-Contact) Temperature

MLX90614: measures surface temperature remotely, without contact. Useful for measuring the temperature of leaves (plants), water surfaces, radiators, or human skin. I2C interface. Range: -70 to +380°C. Accuracy: ±0.5°C in the 0–50°C range.

For plant monitoring, the MLX90614 complements the DHT22: the DHT22 measures air temperature and humidity, the MLX90614 measures leaf surface temperature. The difference between the two is an input to VPD (Vapour Pressure Deficit) calculations — covered in Chapter 13.

MLX90614 infrared sensor — measures surface temperature without contact

Pi, ESP32, and MLX sensors assembled — the multi-sensor node for plant monitoring

Soil Moisture

Capacitive soil moisture sensors (generic, ~€2 each) measure the dielectric constant of soil, which correlates with moisture content. They don’t corrode like resistive sensors. They need calibration: take a reading in bone-dry soil (0% moisture baseline) and in fully saturated soil (100% baseline). Everything in between is interpolated.

CO2 and Air Quality

MH-Z19 (CO2, UART or PWM): measures actual CO2 concentration in ppm. Accurate, self-calibrating, ~€20. Useful for indoor air quality monitoring.

SGP30 (TVOC and eCO2, I2C): measures volatile organic compounds and estimated CO2. Less accurate than the MH-Z19 for CO2, but adds TVOC measurement. Cheaper (~€8).

The Bill of Materials for a Starting Kit

If you’re building your first IoT setup and want to cover the most common projects:

SensorQtyPrice (approx.)Use
DHT223€5 totalTemperature + humidity, multiple rooms
MLX906141€8Non-contact surface temperature
Capacitive moisture3€6 totalSoil monitoring
Tapo P1102€30 totalPower monitoring + smart switching
ESP32 (38-pin)2€10 totalSensor nodes
Pico W2€12 totalSensor nodes
5W solar panel1€8Power for outdoor node
TP4056 module2€3 totalBattery charging
18650 battery2€6 totalEnergy storage

Total: ~€88. Enough hardware for 5–6 meaningful projects.

How Sensors Talk: The Four Interfaces

Every sensor above uses one of four interfaces. The interface decides how many pins you spend, how many sensors share a bus, and what can go wrong.

InterfaceWiresSensors in this chapterWhat to watch
Single-wire digital1 data (+ power)DHT22, DHT11Strict timing; respect the 2-second minimum between reads
Analog1 signal (+ power)Capacitive soil moistureNeeds an ADC pin and calibration; readings drift with supply voltage
I2C2 (SDA, SCL)MLX90614, SGP30Many sensors on one bus, as long as their addresses differ
UART / SPI2–4MH-Z19 (UART)Fast and robust, but every device costs more pins

Two practical consequences:

  • Analog on the Pico W vs ESP32: both have ADCs, but neither is precise enough to trust raw values. Always calibrate against known dry/wet points, as above. Chapter 5 compares the two boards.
  • I2C scales best: a node with an MLX90614 and an SGP30 still uses only two GPIO pins. Run an I2C scan first; a sensor that doesn’t show up is usually wiring, not code.

Reading a Datasheet: What Matters

Before buying a sensor you haven’t used, check these lines on its datasheet:

  • Accuracy and range at the conditions you’ll actually measure (accuracy is often specified for a narrower band than the full range, like the MLX90614’s ±0.5°C only for 0–50°C).
  • Minimum sampling interval and response time.
  • Operating temperature and humidity: the DHT22’s condensation problem is exactly the kind of limit that’s easy to miss.
  • Supply voltage and logic level: 3.3V boards (ESP32, Pico W) and 5V sensors need a level shifter or a different sensor.
  • Current draw, active and idle: this is what sets battery life on a solar node (Chapter 8).
  • Interface and address, from the table above.

Takeaway: DHT22 for air. MLX90614 for surfaces. Capacitive sensors for soil. Add a solar panel and TP4056 for any outdoor node.