DHT22 Temperature and Humidity Sensor using Arduino IDE
Welcome to The Article...!
This article will show how to use DHT22 temperature and humidity sensor using Arduino IDE. Before assembling the circuit, I will give quick explanation about DHT22 sensor.
DHT22 Temperature and Humidity Sensor
DHT22 can measure temperature from -40 to 80 ºc and humidity from 0 to 100%. It has 4 pinouts and each pinout connect to different pin on ESP32. From left, pin 1 is going to be where we connect the VCC so it will connect to 3.3V pin on ESP32. Pin 2 will connect to any digital GPIO and connected to 10k Ohm pull-up resistor. Pin 3 will not connect to any pin and pin 4 will connect to ground (GND) pin on ESP32.
STEP 1: Required Hardware and Software
- ESP32 Development board
- DHT22 Humidity Sensor
- 10k Ohm resistor
- Breadboard
- Jumper wires
STEP 2: Assembling the circuit
Connect the ESP32 and the sensor based on the picture below. I will be using GPIO 4.
Installing the Libraries
For the source code, I will be using from DHT library from Adafruit.
Open the Arduino IDE and go to Sketch > Include Library > Manage Libraries. In the search box, search "DHT" and install DHT sensor library by Adafruit.
We also need adafruit unified sensor, so search "Adafruit unified sensor" and scroll all the way down to find it then install it.
The Code
Open the example "DHTtester" by going to File > Examples > DHT Sensor Library > DHTtester. Then the code will pop in the IDE.
The code will be as shown above. The example has so many comment, make sure to read all of it. The crucial thing to be noted is make sure the "#define DHTPIN" is set to whichever pin you are using. After everything is done, verify the code.
STEP 4: Uploading the code
After the code has been verified, connect ESP32 into the PC. After that upload the code to ESP32. In the PC, open serial monitor to track the measurement. Make sure to change the serial to which one you are using.
The result in serial monitor would be like above. It will measure the temperature and humidity every 2 seconds.
Comments
Post a Comment