SensorsQUICK REFERENCE
DHT11 / DHT22
Temperature and humidity wiring, sampling intervals and valid readings.
01Bare sensor pinout
- Front grille facing you
- Pins left to right: 1 VCC, 2 DATA, 3 NC, 4 GND. Modules can reorder these.
- Pull-up
- Typically 4.7–10 kohm from DATA to a compatible supply; often included on breakout boards.
- Wiring
- Common ground; short data cable; use the supply specified for your sensor revision.
02Read reliably
- DHT11
- Basic, lower-resolution sensor; wait at least 1 second between readings.
- DHT22 / AM2302
- Higher resolution and wider range; wait at least 2 seconds between readings.
- Protocol
- Timing-sensitive single data wire; use a DHT library, not I2C or Dallas OneWire.
- Validation
- Check failed/NaN readings; retain last valid reading and retry after the sampling interval.
03MicroPython pattern
- Setup
- import dht; sensor = dht.DHT22(Pin(4))
- Sample
- sensor.measure(); sensor.temperature(); sensor.humidity()
- Units
- Temperature in °C; relative humidity in %. Catch OSError on failed reads.