Introduction: Beginner’s Guide to Use DHT11/DHT22 Sensors W/ Arduino
You can read this and other amazing tutorials on ElectroPeak's official website
In this tutorial, you will learn how to set up DHT11 and DHT22 sensors, and measure the environment temperature and humidity.
What You Will Learn:
- DHT11 and DHT22 features and differences
- DHT11 and DHT22 structure
- How to set up DHT11 and DHT22 sensors with Arduino
Step 1: DHT11 and DHT22 Temperature and Humidity Sensor
Due to the importance of parameters such as temperature and humidity in many projects, the correct selection of sensors that are capable of measuring temperature and humidity is very important. The DHT family named as DHT11 and DHT22 are the most popular and common sensors among the temperature and humidity sensors.
You can see their features in this step table.
Low price is the most important feature of DHT11, but it does not have a highaccuracy and a Wide measurement range. On the other hand DHT22, with a wide range and high accuracy for measurement is more than 2.5 times more expensive than the other one in the family.
Step 2: Measuring Temperature and Humidity Using DHT11 and Arduino
Step 3: Circuit
DHT11 contains 4 pins. 2pins for supply, 1 for sending data, and the other one is useless. To make this sensor work properly and give you the correct data, you must pull up the data pin with a 4.7 k resistance. Leave the -third pin of the sensor without any connection.
Be careful about the sensor and the pin direction, your sensor will be damaged in case of a mistake.
Step 4: Code
To begin transferring data, upload this code to your Arduino and open the serial monitor.
DHT.humidity returns humidity in percent and DHT.temperature returns the temperature in Celsius.
We have to wait for 2 seconds between each measurement. Otherwise, the sensor will return wrong data.
Instead of displaying information on the computer, you can display the temperature and humidity on the LCD.
For more information see this tutorial: Using 1602 LCD Keypad Shield w/ Arduino
Step 5: Measuring Temperature and Humidity Using DHT22 and Arduino
setting up and using the DHT22 sensor is almost the same as DHT11.
Step 6: Required Materials
Step 7: Circuit
Step 8: Code
The only difference is in DHT.trad function, where you should write 22 instead of 11. Also, you can define temperature and humidity parameters as floats for DHT22 to see them more accurate.
Upload this code on your Arduino board and watch the results in Serial monitor.
Step 9: What's Next?
- Try to make a smart fan