Exp 6
Exp 6
➢ DHT11 uses a Single bus data format for communication. Only a single data line between an
MCU like Arduino or Raspberry Pi and the DHT11 Sensor is sufficient for exchange of
information.
➢ Microcontroller acts as a Master and the DHT11 Sensor acts as a Slave. The Data OUT of the
DHT11 Sensor is in open-drain configuration and hence it must always be pulled HIGH with
the help of a 5.1KΩ Resistor.
➢ This pull-up will ensure that the status of the Data is HIGH when the Master doesn’t request
the data (DHT11 will not send the data unless requested by the Master).
➢ Whenever the Microcontroller wants to acquire information from DHT11 Sensor, the pin of the
Microcontroller is configured as OUTPUT and it will make the Data Line low for a minimum
time of 18ms and releases the line. After this, the Microcontroller pin is made as INPUT.
➢ The data pin of the DHT11 Sensor, which is an INPUT pin, reads the LOW made by the
Microcontroller and acts as an OUTPUT pin and sends a response of LOW signal on the data
line for about 80µs and then pulls-up the line for another 80µs.
➢ After this, the DHT11 Sensor sends a 40 bit data with Logic ‘0’ being a combination of 50µs
of LOW and 26 to 28µs of HIGH and Logic ‘1’ being 50µs of LOW and 70 to 80µs of HIGH.
➢ After transmitting 40 bits of data, the DHT11 Data Pin stays LOW for another 50µs and finally
changes its state to input to accept the request from the Microcontroller.
Circuit Diagram
The following is the circuit diagram of the DHT11 and Raspberry Pi Interface.
import time
import board
import adafruit_dht
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
time.sleep(2.0)
Sample Output:
Installing DTH11 Library
➢ Using a library called Adafruit_DHT provided by Adafruit for this project, So first
install this library into Raspberry Pi.
➢ First step is to download the library from GitHub. But before this, need to create a
folder called ‘library’ on the desktop of the Raspberry Pi to place the downloaded
files.
➢ Now, enter the following command to download the files related to the Adafruit_DHT
library.
➢ In that folder, there is file called ‘setup.py’. We need to install this file using the
following command.