Home Code Pi and DHT11 temperature and humidity sensor

Pi and DHT11 temperature and humidity sensor

by shedboy71

The DHT11 digital temperature and humidity sensor is a composite Sensor contains a calibrated digital signal output of the temperature and humidity.

DHT11 uses a simplified single bus communication. Single bus that only one data line, the system of data exchange, control by a single bus to complete. Device (master or slave) through an open drain or tri-state port connected to the data line to allow the device does not send data to release the bus, while other devices use the bus; single bus usually require an external one about 5.1k pull up resistor,  so that when the bus is idle, its status is high. Because they are the master slave structure, and only when the host calls the slave, the slave can answer, the host access devices must strictly follow the single bus sequence, if the chaotic sequence, the device will not respond to the host

Here is a picture of a typical breakout

dht11 breakout

dht11 breakout

You will need the following parts

  • Raspberry Pi
  • DHT11/22 or AM2302 temperature and humidity sensor
  • 4.7K or 10K resister
  • Breadboard
  • Jumper wires

I used a Dht11 breakout, I also used a board to protect the GPIO



Installation and testing

Copy the Adafruit library by typing the following at the command prompt

git clone https://github.com/adafruit/Adafruit_Python_DHT.git
    cd Adafruit_Python_DHT

Next, to install the library execute:

sudo python setup.py install

Using simple command line parameters you can test out your device, there are 2 parameters required the device type and the GPIO pin its connected to, so as an example we are using a DHT11 connected to GPIO 4

cd examples
sudo ./AdafruitDHT.py 2302 4

You should see something like the following, note I put in an incorrect device type to show an error as well, I selected a DHT22 first of all. You can see there is a value displayed but it is not correct another error is to specify the wrong GPIO pin

Pi and DHt11

Pi and DHt11


dht11 datasheet
1pcs DHT11 Temperature and Relative Humidity Sensor Module

You may also like