How to Connect DHT11/DHT22 Temperature Sensor to ESP32

preview_player
Показать описание
Here's a quick tutorial that shows you how to connect up an ESP32 microcontroller to either the DHT11 or DHT22 low cost temperature and humidity sensors. The DHT11 is cheaper but the DHT22 is a better option if you want more accurate readings.

00:00 - DHT11 vs DHT22
00:30 - Connecting DHT to ESP32
01:30 - Arduino DHT library
02:48 - Configure the sketch
03:26 - Code walkthrough
03:54 - DHT22 test
06:04 - Using data in other applications

You can connect the DHT sensor to any digital pin on the ESP32. GPIO2 (G2) is a good choice because this is the pin the Adafruit DHT sensor library example uses by default. With a 3 pin DHT sensor the + pin goes to either 3.3V or 5V and the - pin goes to ground. The data pin is usually the one in the middle.

In the video I had problems uploading the sketch because the PC couldn't connect to the ESP32 via the USB port. This seems somehow related to the DHT22. When I disconnect the data cable it uploads perfectly.

Incidentally neither sensor is suitable for use in mission critical environments. My own tests showed I got the same humidity readings with the DHT22 as with my two existing commercially bought thermometers. However, the DHT22 was overstating the temperature by at least 2°C. Other users have reported that the temperature readings were quite accurate, but humidity measurements were highly inaccurate. Apparently the BME280 is a good potential alternative to both the DHT11 and DHT22.

If you're intending to use either sensor outdoors, then be sure to put them in a weather proof casing.
Рекомендации по теме