DHT11 sensor measures and provides humidity and temperature values serially over a single wire.
It can measure the relative humidity in percentage (20 to 90% RH) and temperature in degree Celsius in the range of 0 to 50°C.
It has 4 pins; one of which is used for data communication in serial form.
Pulses of different TON and TOFF are decoded as logic 1 or logic 0 or start pulse or end of a frame.
DHT11 Interfacing with Raspberry Pi 3
Here, we are going to interface the DHT11 sensor with Raspberry Pi 3 and display Humidity and Temperature on the terminal.
We will be using the DHT Sensor Python library by Adafruit from GitHub. The Adafruit Python DHT Sensor library is created to read the Humidity and Temperature on raspberry Pi or Beaglebone Black. It is developed for DHT series sensors like DHT11, DHT22 or AM2302.
Extract the library and install it in the same root directory of the downloaded library by executing the following command,
sudo python setup.py install
Once the library and its dependencies have been installed, open the example sketch named simple test from the library kept in the examples folder.
In this code, raspberry Pi reads Humidity and Temperature from the DHT11 sensor and prints them on the terminal. But, it read and display the value only once. So, here we made a change in the program to print value continuously.
Assign proper sensor type to the sensor variable in this library. Here, we are using the DHT11 sensor.
sensor = Adafruit_DHT.DHT11
If anyone is using sensor DHT22 then we need to assign Adafruit_DHT.DHT22 to the sensor variable shown above.
Then assign pin no. to which DHT sensor’s data pin is connected. Here, data out of the DHT11 sensor is connected to GPIO4. As shown in the above interfacing diagram.
The temperature and humidity is uploaded to the cloud: