DHT22 with Arduino UNO

Introduction
The DHT22 is a digital temperature and humidity sensor that provides higher accuracy and a wider measurement range than the DHT11. It is commonly used in weather stations, greenhouse monitoring systems, smart home automation, and IoT projects where reliable environmental data is required.
In this tutorial, you will learn how to connect the DHT22 Sensor to an Arduino UNO, install the required libraries, upload the code, and monitor temperature and humidity values using the Serial Monitor. By the end of this guide, you'll be able to collect accurate environmental data for your Arduino projects.
Components Required
Tools Required
Software Required
| Item Name | Action |
|---|---|
Arduio IDE | Download |
Circuit Diagram
Source Code
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("°C");
delay(2000);
}Step by Step Instructions
Step 1: Connect the DHT22 Sensor
Make the following connections:
DHT22 | Arduino UNO |
|---|---|
VCC | 5V |
GND | GND |
DATA | D2 |
Step 2: Install Required Libraries
Open Arduino IDE.
Go to Sketch → Include Library → Manage Libraries.
Search for DHT Sensor Library.
Install DHT Sensor Library by Adafruit.
Install Adafruit Unified Sensor Library.
Step 3: Open Arduino IDE
Connect Arduino UNO using USB.
Select:
Board → Arduino UNO
Port → Correct COM Port
Step 4: Create a New Sketch
Create a new Arduino sketch and paste the provided code.
Step 5: Verify the Code
Click the Verify button to check for syntax errors.
Step 6: Upload the Code
Click Upload and wait until the upload process completes successfully.
Step 7: Open Serial Monitor
Open Serial Monitor.
Set the baud rate to 9600.
Wait a few seconds for the sensor to initialize.
The Serial Monitor will display real-time temperature and humidity readings.
Expected Output
Humidity: 55.40% Temperature: 28.60°C
Humidity: 55.60% Temperature: 28.70°C
Humidity: 55.30% Temperature: 28.50°CConclusion
In this tutorial, you learned how to interface the DHT22 Sensor with Arduino UNO and measure temperature and humidity with improved accuracy. This setup can be used in environmental monitoring systems, weather stations, smart agriculture, and various IoT applications that require reliable climate data.









