Tested on:Raspberry Pi 2; Raspberry Pi B+; Python 2.7; Python 3; Raspbian pre Jessie
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:10k ohm resistor
DHT22/AM.2302 sensor
Jumper cables and soldering equipment

Measure temperature and humidity with the sensor DHT22/AM2302

Update: DHT22 for Raspbian Stretch
Since Raspbian Stretch was rolled out, there have been problems with the Adafruit driver for the DHT22.
Here’s an alternative: DHT22 on Raspbian Stretch

DHT.AM2302 is a sensor to measure temperature and humidity and Adafruit has implemented a Raspberry Pi driver for the sensor- thanks for that!
Another option if only the temperature should be measured is the 1-wire sensor DS18B20.

Breadboard circuit
The circuit is very simple. Just attach the leftmost sensor pin to the Pin 1 for 3.3V VCC, the second leftmost sensor pin to Pin 15 for data transmission and the rightmost sensor pin to a ground pin like Pin 20 of the Raspberry Pi (all in Board numbering):

Breadboard circuit for DHT22/Am2302

Breadboard circuit for DHT22/Am2302

The assembled DHT22/AM.2302 sensor

The assembled DHT22/AM2302 temperature and humidity sensor

The assembled circruit: temperature and humidity sensor dht22/AM2302

Install sensor drivers
Type in the terminal

Test the installation in python
Open python with sudo python and enter

If everything is fine, this outputs the current temperature and humidity with the first value being the humidity.

Update: Python 3
Execute the following commands for the Python3-version of the Adafruit driver:

Adafruit Industries: https://www.adafruit.com
1-Wire temperature sensor DS18B20: http://www.knight-of-pi.org/measuring-and-logging-temperature-with-the-1-wire-sensor-ds18b20-and-a-raspberry-pi/
DHT22 on Raspbian Stretch: http://www.knight-of-pi.org/update-dht22-am2302-with-pigpio-for-raspbian-stretch/

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.


  1. Hi,there is a little mistake in your example …
    when you test the sensor AM2302 in python , you must write these three lines:

    import Adafruit_DHT
    humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302,’4′)
    print(‘Temp={0:0.1f}* Humidity={1:0.1f}%’.format(temperature, humidity))

    because otherwise you can’t see the response of the AM2302 (I use GPIO4)
    Thank very much for all the info.

    • Hi,
      no, that’s alright in the tutorial: if you don’t assign variables, the current temperature and humidity are just printed to the screen. But thanks anyways!

  2. Thanks for porting the Adafruit DHT driver to python 3! Thank you! Thank you! Thank you!


Time limit is exhausted. Please reload CAPTCHA.