
DHT22 Temperature and Humidity Meter
Beginner20 minA project that measures humidity and temperature, in both Celsius and Fahrenheit, with a DHT22 sensor and writes them to the Serial Monitor every two seconds. It is more precise than the DHT11 and has a wider measuring range. Before uploading the code, install Adafruit's "DHT sensor library" in the Arduino IDE (and the "Adafruit Unified Sensor" library it asks for).

What you need
Wiring steps
- 1
Power the sensor

Plug a red jumper wire into the 5V pin on the Arduino's POWER header. With the DHT22's front facing you, connect the other end to its top pin, pin 1 (VCC).
- Arduino 5V → DHT22 VCC (red wire)
- 2
Connect the data line

Plug a blue jumper wire into the Arduino's digital pin 2. Connect its other end to the DHT22's pin 2 (DATA), just below. The code reads the sensor on this pin (DHTPIN 2).
- Arduino pin 2 → DHT22 DATA (blue wire)
- 3
Ground (GND) connection

Plug a black jumper wire into the GND pin on the Arduino's digital header, next to pin 13. Connect its other end to the DHT22's bottom pin, pin 4 (GND). Pin 3 stays free; do not connect anything to it.
- Arduino GND → DHT22 GND (black wire)
Arduino sketch
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin(); // initialize the sensor
}
void loop() {
// wait a few seconds
// between measurements.
delay(2000);
// read humidity
float humi = dht.readHumidity();
// read temperature as Celsius
float tempC = dht.readTemperature();
// read temperature as Fahrenheit
float tempF = dht.readTemperature(true);
// check if any reads failed
if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
}
}
What the Serial Monitor shows
Humidity: 45.50% | Temperature: 23.40°C ~ 74.12°F Humidity: 45.60% | Temperature: 23.40°C ~ 74.12°F
Similar projects
DHT11 Temperature and Humidity MeterBeginner20 minA starter project that measures the room's temperature and humidity with a DHT11 sensor and writes the values to the Arduino IDE's Serial Monitor once a second. Before uploading the code, install the DHTlib library in the Arduino IDE.Open project
HC-SR04 Ultrasonic Distance MeterBeginner20 minA project that measures the distance to the object in front of an HC-SR04 ultrasonic sensor in centimetres and writes it to the Serial Monitor about 10 times a second. The sensor measures how long the echo of its sound wave takes to come back; the code turns that time into centimetres by dividing it by 58. No extra library needed.Open project
Night Light (LDR)Beginner20 minA night light that turns itself on as the room gets dark. An LDR (light sensor) and a 100 kΩ resistor form a voltage divider; the Arduino reads the light level on pin A0 and, in the dark, dims the LED on pin 9 with PWM. It teaches analog reading, thresholds and PWM. No extra library needed.Open project
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
