Watch the complete video tutorials on “How to get Humidity and Temperature data to raspberry pi using DHT11 sensor” at our YouTube channel.
This tutorial will guide you how you can interface the DHT11/ DHT22 Sensor with Raspberry Pi Board.
As we all of know that the DHT-11 Digital Temperature And Humidity Sensor is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin (no analog input pins needed).
- Humidity measuring range: 20%~90%RH(0~50 degree (temperature compensation).
- Temperature measuring range: 0~+50degree.
- Humidity measurement accuracy: ±5.0%RH.
- Temperature measurement accuracy: ±2.0degree.
- Low power consumption.
- Relative humidity and temperature measurement
- All calibration, digital output
- Excellent long-term stability
As we know that Raspberry Pi is independent Operation system, based on Linux. Raspberry Pi is a series of small single-board computers (SBCs) developed in the United Kingdom by the Raspberry Pi Foundation in association with Broadcom.
For more details, visit to Raspberry Pi Wikipedia Page.
Let's interface the DHT11/DHT22 Sensor With Raspberry Pi Now.
So connect the DHT11/DHT22 Sensor with Raspberry Pi as shown in the Circuit Diagram.
DHT11/DHT22 pin connection with Raspberry Pi like shown in the Circuit Diagram:
- DHT11/22 Sensor Vcc+ to 5VÂ pin of Raspberry PiÂ
- DHT11/22 Sensor GND to GND pin of Raspberry Pi
- DHT11/22 Sensor Signal to GPIO4 no pin of Raspberry Pi
Now we need to install the DHT sensor poython library in the Raspberry Pi.Â
but before that Python must be installed in your Raspberry Pi OS. If not installed, then you need to installed by the following commands in the LX Teminal:Â
sudo apt update sudo apt install python3-pip sudo pip3 install --upgrade setuptools
Now install the DHT Sensor Pyhton Library:
sudo pip3 install Adafruit_DHT
Now, go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.
Now save this file in the root folder with name as DHTsensor.py
Now, go to the Accessories and open the TextEditor. Copy the below code and paste in to the file.
import Adafruit_DHT
import time
DHT_SENSOR = Adafruit_DHT.DHT11
DHT_PIN = 4
while True:
humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_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. Check wiring.");
time.sleep(2);
Now save this file in the root folder with name as DHTsensor.py
Once Saved, open the LX Terminal and Write this command:
Sudo python DHTsensor.py
Watch the complete video tutorials on “How to get Humidity and Temperature data to raspberry pi using DHT11 sensor” at our YouTube channel.