Professional Documents
Culture Documents
Dr G RAGHOTHAM REDDY
Professor, Dept of ECE
04/27/2023
Lecture Outcomes
2
DHT11 Temperature And Humidity Sensor
Interfacing process
Data pin of
sensor to GPIO
21 (or 40 pin)
of RPi
GND pin of
sensor to GND
(or 39 pin) of
RPi
Vcc pin of sensor to 3.3V (or 1 pin) of RPi
• Power up the Rpi
• Enable SSH (Wi-Fi) communication
import time
import board
import adafruit_dht
#Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D17)
# GPIO 17 pin, board11 connected to Data pin
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))
except RuntimeError as error: # Errors happen fairly
often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
Simulation Results
pi@raspberrypi:~ $ python3 DHT11Test.py
Temp: 66.2 F / 19.0 C Humidity: 56%
Temp: 66.2 F / 19.0 C Humidity: 56%
Checksum did not validate. Try again.
Temp: 66.2 F / 19.0 C Humidity: 56%
A full buffer was not returned. Try again.
Temp: 66.2 F / 19.0 C Humidity: 56%
Checksum did not validate. Try again.
Temp: 66.2 F / 19.0 C Humidity: 56%
Temp: 66.2 F / 19.0 C Humidity: 56%
Temp: 66.2 F / 19.0 C Humidity: 56%
Temp: 66.2 F / 19.0 C Humidity: 56%
Summary
Working of DHT11
Measure temperature and humidity with RPi
using Python
Lecture Outcomes- Revisited