Reference
DHT22
Temperature and humidity (AM2302, higher precision than DHT11).
- Connects over
- GPIO pins
- Made by
- Aosong
- Datasheet
- cdn-shop.adafruit.com
Use it
hardware {
device dht22: DHT22(pin: 16)
}
every 1s {
let value: float = dht22.temperature()
log("dht22", "temperature={value}")
}
The DHT22 is wired to ordinary GPIOs: give each of its pins (pin) as a named argument. The compiler checks every pin can do its job.
Methods
-
dht22.temperature() -> float
Temperature in °C
-
dht22.humidity() -> float
Humidity %
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V or 5V |
DATA | Pull-up 4.7kΩ–10kΩ to VCC |
NC | Not connected |
GND | Ground |
Specifications
- Voltage
- 3.3V – 6V
- Current
- 1.5 mA measuring, 50 μA standby
- Temp
- −40°C to +80°C ±0.5°C
- Humidity
- 0 – 100% RH ±2 – 5%
- Sample rate
- Every 2 s (slower than DHT11)
Tips
- Marketed as AM2302 — same chip.
- Single-wire protocol is timing-critical — many MCU libraries disable interrupts during read.
- If you query faster than every 2 s you get the previous reading.
Alternatives worth knowing:
- AHT20: I²C, cheaper, similar accuracy. Strongly recommended for new designs.
- SHT31: Sensirion — top-tier accuracy and reliability.
- BME280: Adds pressure if you need altitude / weather.