
Pin 15 can work but DHT must be disconnected during program upload. #define DHTPIN 4 // Digital pin connected to the DHT sensor REQUIRES the following Arduino libraries: Example testing sketch for various DHT humidity/temperature sensors written by ladyada
#Dht22 proteus library download code
Copy the following code to your Arduino IDE. To read temperature and humidity from the DHT sensor, we’ll use an example based on the Adafruit DHT library.

ESP32 Reading Temperature and Humidity Sketch

However, if you get your DHT sensor in a breakout board, it comes with only three pins and with an internal pull-up resistor on pin 2.Īfter installing the libraries, restart your Arduino IDE. DHT PinoutĭHT sensors have four pins as shown in the following figure. You just need to select in the code the sensor type you’re using. It’s also a bit cheaper.ĭespite their differences, they work in a similar way, and you can use the same code to read temperature and humidity. However, you can request sensor readings every second. The DHT11 has a smaller range and it’s less accurate. However, it is a bit more expensive, and you can only request readings with 2 seconds interval. The DHT22 sensor has a better resolution and a wider temperature and humidity measurement range. For a more in-depth analysis of these sensors, please check the sensors’ datasheet. The following table compares some of the most important specifications of the DHT11 and DHT22 temperature and humidity sensors. The DHT11 and DHT22 are very similar, but differ in their specifications.

This makes them very easy to use with any microcontroller. These sensors contain a chip that does analog to digital conversion and spit out a digital signal with the temperature and humidity.
