Let's think about this for a second
A DHT22 (or DHT11) temperature/humidity sensor connects via one GPIO pin (the data pin), plus power (3.3V) and ground — the wiring is simpler than I2C/SPI sensors since it communicates over a single data pin. This project brings together the concepts from earlier chapters (GPIO wiring, Python control, Linux commands) into one cohesive project.
Let's connect this to a real-world scenario
Connect the DHT22 sensor's 3 pins — VCC (3.3V), Data (a GPIO pin, e.g. BCM 4), and GND — to the Pi using a breadboard and jumper wires (following the same pattern as the LED wiring lesson earlier). Install the Adafruit_DHT or adafruit-circuitpython-dht Python library with pip install (same pattern as the earlier pip lesson).
Let's walk through it together
# Wiring (DHT22 to Pi)
# DHT22 VCC → Pi 3.3V
# DHT22 Data → Pi GPIO 4 (BCM)
# DHT22 GND → Pi GND
# Install library
pip install adafruit-circuitpython-dht
sudo apt install libgpiod2Once the library is installed, you'll be all set to read sensor data with a Python script in Part 2.5-Minute Try-It
If you have a DHT22 sensor, wire it up yourself following the wiring diagram, and run the library install command.
A quick word of caution
Changing the sensor wiring while the power is on can fry the sensor or even the Pi board — follow the same warning from the LED wiring lesson earlier: power off before you touch the wiring.