Back to Sensors & Actuators Series

Humidity & Temperature: DHT22 (AM2302)

July 21, 2025 Wasil Zafar 7 min read

DHT22 deep dive — capacitive humidity sensing, single-wire protocol, calibration, complete code, and real-world HVAC applications.

Contents

  1. Working Principle
  2. Electrical Characteristics
  3. Interfacing with MCU
  4. Calibration
  5. Code Example
  6. Real-World Applications
  7. Limitations

Working Principle

The DHT22 combines a capacitive humidity sensor and a thermistor in a single module. The humidity element is a polymer capacitor whose dielectric constant changes with moisture absorption, altering capacitance. An internal MCU converts both readings to digital values transmitted over a proprietary single-wire protocol (not 1-Wire).

Electrical Characteristics

ParameterValue
Supply Voltage3.3 V – 5.5 V
Humidity Range0 – 100% RH
Humidity Accuracy± 2% RH
Temperature Range−40 to +80 °C
Temperature Accuracy± 0.5 °C
Sampling Rate0.5 Hz (one reading per 2 seconds)

Code Example

/*
 * DHT22 Humidity & Temperature — Arduino
 * Requires: DHT sensor library by Adafruit
 * Wiring: DATA → Pin 4, VCC → 5V, 10kΩ pull-up on DATA
 */
#include <DHT.h>

#define DHT_PIN 4
#define DHT_TYPE DHT22

DHT dht(DHT_PIN, DHT_TYPE);

void setup() {
    Serial.begin(9600);
    dht.begin();
    Serial.println("DHT22 ready. Readings every 2 seconds.");
}

void loop() {
    delay(2000);  /* DHT22 needs ≥ 2s between reads */

    float humidity = dht.readHumidity();
    float tempC    = dht.readTemperature();

    if (isnan(humidity) || isnan(tempC)) {
        Serial.println("Failed to read from DHT22!");
        return;
    }

    /* Compute heat index */
    float heatIndex = dht.computeHeatIndex(tempC, humidity, false);

    Serial.print("Humidity: ");    Serial.print(humidity);   Serial.print("% | ");
    Serial.print("Temp: ");        Serial.print(tempC);      Serial.print("°C | ");
    Serial.print("Heat Index: ");  Serial.print(heatIndex);  Serial.println("°C");
}

Real-World Applications

Environmental

Data Centre Climate Control

Server rooms deploy DHT22 arrays in hot/cold aisles to maintain 45–55% RH and prevent electrostatic discharge (low humidity) or condensation (high humidity). The 2-second polling rate is perfectly adequate for slow-changing HVAC loops.

HVACData CentreClimate

Limitations

  • Very slow: 0.5 Hz sampling makes it unusable for fast humidity changes.
  • No true I2C: Proprietary protocol; bit-banging is timing-sensitive and can fail on fast MCUs without delays.
  • Accuracy degrades: Above 80% RH, accuracy drops to ± 5%.