DIY: Arduino DHT Humidity Sensor Project
DIY: Arduino DHT Humidity Sensor Project
If you’re interested in monitoring temperature and humidity, this Arduino project using the DHT22 sensor is perfect for you. Whether you’re building a weather station, a clock, or a measurement device for a computer or car, this project will guide you through the setup and code needed to get accurate readings.
Relative Humidity
The relative humidity (RH) is a measure of the amount of moisture in the air compared to the maximum amount of moisture the air can hold at a specific temperature. It is expressed as a percentage.
The formula to calculate relative humidity is:
$$RH = \left(\frac{{\text{actual vapor pressure}}}{{\text{saturation vapor pressure}}}\right) \times 100%$$
where:
- $RH$: Relative Humidity (in percentage)
- Actual vapor pressure: The pressure exerted by the water vapor present in the air.
- Saturation vapor pressure: The maximum pressure exerted by water vapor at a given temperature. It represents the point where the air is saturated with moisture.
Components Needed
- Arduino (Keyestudio Uno used in this example)
- DHT22/AM2302 Humidity and Temperature Sensor
- 3 Jumper Wires
- 10KΩ resistor
- Breadboard
- USB Data Cable (depends on the Arduino model)
![]() | ![]() |
|---|---|
| Board | Schematic |
Building the Circuit
The circuit is simple and quick to assemble on a breadboard. Here are the steps:
- Remove Power: Ensure the Arduino is powered off before starting.
- Insert Sensor: Fit the DHT22 sensor vertically across four separate rows on the breadboard.
- Connect Pins:
- Pin 1 (VCC) to 5V on the Arduino
- Pin 2 (DATA) to digital pin 2 on the Arduino
- Pin 4 (GND) to Ground on the Arduino
- Add Resistor: Place a 10KΩ resistor between Pin 1 (VCC) and Pin 2 (DATA) on the sensor.
That’s all for the hardware setup!
The Code
We’ll use the DHTtester example from Adafruit’s DHT sensor library, which supports DHT11, DHT21, and DHT22 sensors. You can download the library from Adafruit’s GitHub page. Once downloaded, open the Arduino IDE and use the following code:
| |
Code Explanation
- Library Import: The code begins by including the DHT sensor library.
- Define Pins: It defines the data pin and the type of DHT sensor being used.
- Setup: In the
setupfunction, the code initializes serial communication at 9600 baud rate and starts the DHT sensor. - Loop: The
loopfunction runs continuously, waiting for 2 seconds between each reading. It reads humidity and temperature from the sensor, calculates the heat index, and prints the results to the serial monitor.
Conclusion
You’ve now set up a simple yet effective humidity and temperature sensor using an Arduino and a DHT22 sensor. This project is a great starting point for creating more complex systems like weather stations or environmental monitors. With minimal components and straightforward code, you’ll have accurate readings displayed on your serial monitor in no time. Happy tinkering!

