Understanding Temperature & Humidity Sensors
The DHT11 and DHT22 are the most popular temperature and humidity sensors in the maker community. While the DHT11 is cheaper, the DHT22 offers far greater precision and range. In this guide, we will connect them to an ESP32 Development Board.
Wiring the Sensor
Both sensors have a similar pinout: VCC, DATA, and GND. Connect VCC to the 3.3V pin on your ESP32, GND to GND, and the DATA pin to GPIO 4. Make sure to place a 10K pull-up resistor between VCC and DATA to keep the signal stable.
The Arduino Code
To read the data, you will need to install the “DHT sensor library” by Adafruit in your Arduino IDE. Simply include the library, define the pin, and call dht.readTemperature() to get live readings!