1. Introduction
The DHT11 sensor is used to measure temperature and humidity. It provides digital output, making it easy to interface with Raspberry Pi. This sensor is widely used in weather monitoring and smart home applications.
2. Components
- Raspberry Pi
- DHT11 Sensor Module
- 10kΩ Resistor (if required)
- Breadboard
- Jumper Wires
3. Circuit and connections
| Raspberry Pi Pinout Diagram |
| Pinout Diagram DHT11 Sensor Module |
Connections:
- VCC → 3.3V (Pin 1)
- GND → GND (Pin 6)
- DATA → GPIO17 (Pin 11)
(If using bare sensor, connect 10kΩ resistor between VCC and DATA)
4. Detailed Step By Step Circuit working
- DHT11 senses temperature and humidity
- It converts analog signals into digital data
- Data is sent through DATA pin
- Raspberry Pi reads this data
- Values are displayed on terminal
5. Libraries to be included
import Adafruit_DHT
6. Code
import Adafruit_DHT
import time
sensor = Adafruit_DHT.DHT11
pin = 17
while True:
humidity, temperature = Adafruit_DHT.read(sensor, pin)
if humidity is not None and temperature is not None:
print("Temp = {0:0.1f}°C Humidity = {1:0.1f}%".format(temperature, humidity))
else:
print("Sensor failure. Try again.")
time.sleep(2)
7. Detailed Step By Step Code working
- Import Adafruit_DHT library
- Define sensor type as DHT11
- Assign DATA pin to GPIO17
-
Use
read()function to get values - Store humidity and temperature
- Check if values are valid
- Print values on screen
- Add delay for stable reading
8. Tips
-
Use proper library installation (
pip install Adafruit_DHT) - Avoid touching sensor while reading
- Place sensor in open environment
- Wait few seconds between readings
9. Uses
- Weather monitoring systems
- Smart home automation
- Greenhouse monitoring
- Temperature logging systems
10. Conclusion
The DHT11 sensor is a simple and effective way to measure temperature and humidity. It is ideal for beginners working with Raspberry Pi and IoT projects.