Interfacing Raspberry Pi 3 with a Temperature Sensor (DHT11) - English & Marathi
Introduction
The DHT11 sensor is a simple and popular sensor used to measure temperature and humidity. In this tutorial, we will learn how to interface the DHT11 sensor with Raspberry Pi 3 and display the temperature and humidity readings on the terminal.
DHT11 рд╕реЗрдиреНрд╕рд░ рддрд╛рдкрдорд╛рди рдЖрдгрд┐ рдЖрд░реНрджреНрд░рддрд╛ рдореЛрдЬрдгреНрдпрд╛рд╕рд╛рдареА рд╡рд╛рдкрд░рд▓рд╛ рдЬрд╛рдгрд╛рд░рд╛ рдПрдХ рд╕реЛрдкрд╛ рдЖрдгрд┐ рд▓реЛрдХрдкреНрд░рд┐рдп рд╕реЗрдиреНрд╕рд░ рдЖрд╣реЗ. рдпрд╛ рдЯреНрдпреВрдЯреЛрд░рд┐рдпрд▓рдордзреНрдпреЗ, рдЖрдкрдг DHT11 рд╕реЗрдиреНрд╕рд░рд▓рд╛ Raspberry Pi 3 рд╢реА рдХрд╕реЗ рдЬреЛрдбрд╛рдпрдЪреЗ рдЖрдгрд┐ рдЯрд░реНрдорд┐рдирд▓рд╡рд░ рд╡рд╛рдЪрди рдХрд╕реЗ рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░рд╛рдпрдЪреЗ рд╣реЗ рд╢рд┐рдХреВ.
Components Required | рдЖрд╡рд╢реНрдпрдХ рдШрдЯрдХ:
- Raspberry Pi 3
- DHT11 Temperature and Humidity Sensor
- 10K╬й Resistor
- Jumper Wires
- Breadboard
Circuit Diagram | рд╕рд░реНрдХрд┐рдЯ рдЬреЛрдбрдгреА:
Connections:
- DHT11 VCC тЖТ 3.3V (Pin 1)
- DHT11 GND тЖТ GND (Pin 6)
- DHT11 Data тЖТ GPIO4 (Pin 7)
- 10K╬й resistor between VCC and Data pin
Python Code | рдкрд╛рдпрдерди рдХреЛрдб:
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 4 # GPIO4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print(f"Temperature: {temperature}┬░C")
print(f"Humidity: {humidity}%")
else:
print("Failed to retrieve data from sensor")
Explanation | рд╕рдордЬрд╛рд╡рдгреА:
- We use the
Adafruit_DHT
library to read data from the sensor. - The sensor is connected to GPIO4 on the Raspberry Pi.
- The program continuously reads the temperature and humidity values and displays them.
рдЖрдкрдг Adafruit_DHT
рд▓рд╛рдпрдмреНрд░рд░реАрдЪрд╛ рд╡рд╛рдкрд░ рдХрд░реВрди рд╕реЗрдиреНрд╕рд░рдХрдбреВрди рдбреЗрдЯрд╛ рд╡рд╛рдЪрддреЛ. рд╕реЗрдиреНрд╕рд░ GPIO4 рд╢реА рдЬреЛрдбрд▓реЗрд▓рд╛ рдЖрд╣реЗ рдЖрдгрд┐ рддреЛ рддрд╛рдкрдорд╛рди рдЖрдгрд┐ рдЖрд░реНрджреНрд░рддреЗрдЪреНрдпрд╛ рдореВрд▓реНрдпрд╛рдВрдЪреЗ рд╡рд╛рдЪрди рдХрд░рддреЛ.
Running the Code | рдХреЛрдб рдЪрд╛рд▓рд╡рд┐рдгреЗ:
- Install the required library:
pip install Adafruit_DHT
- Save the Python script as
dht11.py
- Run the script:
python dht11.py
Output | рдЖрдЙрдЯрдкреБрдЯ:
Temperature: 25┬░C
Humidity: 60%
Conclusion | рдирд┐рд╖реНрдХрд░реНрд╖:
Now, you have successfully interfaced the DHT11 temperature and humidity sensor with the Raspberry Pi 3! ЁЯОЙ
рдЖрддрд╛ рддреБрдореНрд╣реА DHT11 рддрд╛рдкрдорд╛рди рдЖрдгрд┐ рдЖрд░реНрджреНрд░рддрд╛ рд╕реЗрдиреНрд╕рд░рд▓рд╛ Raspberry Pi 3 рд╕реЛрдмрдд рдпрд╢рд╕реНрд╡реАрдкрдгреЗ рдЬреЛрдбрд▓реЗ рдЖрд╣реЗ! ЁЯОЙ
Stay tuned for the next sensor tutorial! ЁЯЪА | рдкреБрдвреАрд▓ рд╕реЗрдиреНрд╕рд░ рдЯреНрдпреВрдЯреЛрд░рд┐рдпрд▓рд╕рд╛рдареА рддрдпрд╛рд░ рд░рд╣рд╛! ЁЯЪА
Comments