Print Friendly, PDF & Email

Difficulty level: Beginner

Approx reading time:

Components Required:

1. Raspberry Pi 3 model B

2. MicroSD card 8 or 16 GB (Class 4 and above) with Raspbian

3. Windows PC / Linux PC (Tested on Windows 10, Ubuntu 14.04 LTS)

4. Ethernet cable (Category 5 – also called Cat 5)

5. Micro USB cable

6. Breadboard

7. DHT11 Sensor

8. Jumper Wires (Male to Female, Male to Male)

Way to go ->

1. Login to your Pi using PuTTy or your Ubuntu terminal.

2. Login to your Pi GUI using VNC server (Linux / Windows).

3. In Python 3 (IDLE), create a new file. 

4. The name could be:

5. In the file, write the following code with comments (line starting with “#”) for clear understanding and save (press Cntrl + S on your PC keyboard) the file.

import Adafruit_DHT

while True:
    humidity, temperature = Adafruit_DHT.read_retry(11, 27)  # GPIO27 (BCM notation)
    print ("Humidity = {} %; Temperature = {} C".format(humidity, temperature))

Before running the python script do the following:

6. In the terminal type: 

sudo apt-get install git-core

7. Download the Adafruit DHT11 library. In the terminal type:

git clone

8. Navigate to to Adafruit_Python_DHT directory (folder), in the terminal type: 

cd Adafruit_Python_DHT

9. Run the following commands in the terminal.

sudo apt-get install build-essential python-dev  # python2                   

sudo apt-get install build-essential python3-dev  # python3

10. To install the library, in the terminal type:

sudo python install  # python2

sudo python3 install  # python3

11. Finally, run the script by clicking on Run -> Run Module in the menu bar or by pressing F5 on your PC keyboard.


Hardware Connections ->

1. Raspberry Pi 3 GPIO Header.


2. DHT11 to Pi connections.





Read full tutorial at

Rating widget: