How to use a ESP32 development board to read temperature and humidity from a DHT22 sensor
When you have a DHT22 / AM2302 sensor, you will be able to get the temperature and humidity of your environment.
Given that, this post shows how to use ESP32 development board to read temperature and humidity from a DHT22 sensor.
Wiring your DHT22 sensor to your ESP32 development board
When you look at your DHT22 sensor, you can see three pins labeled +, out and -. Connect the:
- + pin to a 3v3 pin on your board
- out pin to GPIO27 on your board
- - pin to a GND pin on your board
Enabling ESP32 Development on Arduino IDE
At this point in time, you are ready to flash a program into your ESP32 board to read from the DHT22 sensor..
Installing the DHT sensor library for ESPx to read temperature and humidity from DHT22 sensor
After you had started your Arduino IDE, proceed to install a Arduino Library to read temperature and humidity from DHT22 sensor.
In order to do so, first go to Tools -> Manage Libraries.... After you had done so, the Library Manager window will appear. Search for DHT22 and install the DHT sensor library for ESPx by beegee_tokyo:
After you had installed the library, you will be able to write the Arduino sketch to read temperature and humidity from your DHT22 sensor.
Arduino sketch example to read temperature and humidity from the DHT22 sensor
Once you had installed the DHT sensor library for ESPx, upload the following sketch to your ESP32 board:
#include "DHTesp.h" DHTesp dht; void setup() { Serial.begin(9600); dht.setup(27, DHTesp::DHT22);:
