DHT22 with Arduino UNO

DHT22 with Arduino UNO
Atribot team

Written by

Atribot team

Last updated

June 18, 2026

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

Swipe right to view full table
Item NameQtyAction
1
DHT22 Sensor
1
USB Cable
1
Breadboard
1
Jumper Wires
3

Tools Required

Swipe right to view full table
Item NameAction
Soldering Iron
Screwdriver

Software Required

Swipe right to view full table
Item NameAction
Arduio IDE

Circuit Diagram

DHT22 with Arduino UNO
DHT22 with Arduino UNO

Source Code

DHT22_with_Arduino_UNO.inocpp
#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:

Swipe right to view full table

DHT22

Arduino UNO

VCC

5V

GND

GND

DATA

D2

Step 2: Install Required Libraries

  1. Open Arduino IDE.

  2. Go to Sketch → Include Library → Manage Libraries.

  3. Search for DHT Sensor Library.

  4. Install DHT Sensor Library by Adafruit.

  5. Install Adafruit Unified Sensor Library.

Step 3: Open Arduino IDE

  1. Connect Arduino UNO using USB.

  2. 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

  1. Open Serial Monitor.

  2. Set the baud rate to 9600.

  3. 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°C

Conclusion

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.