PyRaspBeta

DHT22 module

The DHT22 module is the DHT22 temperature and humidity sensor with its 10 kΩ pull-up resistor already fitted, so the open-drain data line is ready to read. It costs $7 and is for any project that needs the room's climate: thermostats, weather displays, drying alarms. Wire VCC to 3.3 V, DATA to any GPIO and GND to ground.

What's inside

PartQtyPrice each
DHT22 temp & humidity1$5
Resistor1$0.25
Total2$5.25
  • The DHT22 measures temperature (±0.5 °C) and relative humidity (±2 %) and answers over a single data wire.
  • The 10 kΩ resistor pulls that data line up to 3.3 V so it has a defined idle level — the sensor can only pull it low.
Exposed pinInside the kit
vccdht:VCC
datadht:DATA
gnddht:GND

DATA is the shared node between the sensor and the resistor; VCC and GND power the sensor. The kit has no chain ends. The data pin tolerates 3.3–6 V, so powering the module from 3.3 V keeps everything GPIO-safe.

Wiring it in circuit.py

circuit.py
from wiring import *

pi = Pi()
sensor = kits.DHT22Module()

pi.V3_3 >> sensor.vcc
pi.GPIO4 >> sensor.data
sensor.gnd >> pi.GND

Driving it in main.py

main.py
from adafruit_dht import DHT22
from time import sleep

sensor = DHT22(4)

while True:
    try:
        print(f"{sensor.temperature:.1f} C, {sensor.humidity:.1f} %")
    except RuntimeError as error:
        print("read failed:", error)
    sleep(2)

Why buy the kit

The parts are $5 + $0.25 = $5.25, against $7 — $1.75 for the pull-up, fitted on a three-pin board. Forgetting the pull-up leaves the data line floating and the reads fail; the module makes that mistake impossible, and the three connections are the whole build.

Simulator vs real hardware

  • Values come from the sensor's simulated room, with the DHT22's own resolution and accuracy noise, so a change to the zone's temperature or humidity shows up in the next frame.
  • Reads closer together than two seconds return the previous frame, and roughly 5 % of reads fail by design (checksum or timeout) — the try/except above is the pattern the real library demands too.
  • The simulator answers a read as one request rather than timing microsecond pulses, so reads never fail because your program was interrupted.

Further reading