This project demonstrates how to interface the DHT22 temperature and humidity sensor with Arduino UNO to measure ambient temperature and humidity. The DHT22 is a versatile, cost-effective digital sensor that provides high-accuracy measurements with a resolution of 0.1Β°C for temperature and 0.1% for humidity. The sensor readings are displayed on both the Serial Monitor and an optional OLED display.
- High Accuracy: Temperature measurement with Β±0.5Β°C accuracy
- Wide Range: Temperature range from -40Β°C to +125Β°C
- Low Power: Operates on 3.3V to 5V, suitable for battery-powered projects
- Digital Output: Uses single-bus digital communication protocol
- Dual Display: Shows readings on Serial Monitor and OLED display
- Real-time Monitoring: Continuous temperature and humidity readings
Component | Quantity | Description |
---|---|---|
Arduino UNO | 1 | Microcontroller board |
DHT22 Sensor Module | 1 | Temperature & Humidity sensor |
OLED Display (SSD1306) | 1 | 128x64 I2C OLED display (optional) |
Jumper Wires | 3-6 | For connections |
Breadboard | 1 | For prototyping (optional) |
DHT22 to Arduino:
- VCC β 5V
- GND β GND
- DATA β Digital Pin 2
OLED Display to Arduino (Optional):
- VCC β 5V
- GND β GND
- SDA β A4
- SCL β A5
- Temperature Range: -40Β°C to +125Β°C
- Temperature Accuracy: Β±0.5Β°C
- Humidity Range: 0-100% RH
- Humidity Accuracy: Β±2% RH
- Operating Voltage: 3.3V - 5V DC
- Output Signal: Digital signal via single-bus
- Sampling Rate: 1Hz (once per second)
- Resolution: 0.1Β°C / 0.1% RH
The DHT22 sensor consists of:
- Capacitive Humidity Sensor: Uses a moisture-holding substrate between two electrodes. As humidity changes, the resistance between electrodes varies proportionally.
- NTC Thermistor: Measures temperature changes through resistance variation.
- Onboard MCU: Processes sensor data and communicates via single-bus protocol.
The DHT22 uses a proprietary single-bus communication protocol:
- Data transmission takes approximately 4ms
- Total data length: 40 bits (MSB format)
- Data format: 8-bit integral RH + 8-bit decimal RH + 8-bit integral T + 8-bit decimal T + 8-bit checksum
- The MCU sends a start signal, and DHT22 responds with all 40 bits of data
Install the following libraries through Arduino IDE Library Manager:
- DHT sensor library by Adafruit
- Adafruit Unified Sensor Driver
- Adafruit GFX Library (for OLED)
- Adafruit SSD1306 (for OLED)
Installation Steps:
- Open Arduino IDE
- Go to
Sketch β Include Library β Manage Libraries
- Search for each library and click "Install"
- Connect the DHT22 sensor to Arduino as per the pin connections above
- (Optional) Connect the OLED display for visual output
- Connect Arduino to your computer via USB cable
- Open the provided Arduino sketch
- Select the correct board:
Tools β Board β Arduino UNO
- Select the correct port:
Tools β Port β (Your Arduino Port)
- Click the "Upload" button
// Library includes
#include <Wire.h>
#include "DHT.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Sensor configuration
#define DHTTYPE DHT22
uint8_t DHTPin = 2;
DHT dht(DHTPin, DHTTYPE);
// Variables for sensor data
float Temperature;
float Humidity;
float Temp_Fahrenheit;
- setup(): Initializes serial communication, DHT sensor, and OLED display
- loop(): Continuously reads sensor data, validates it, and displays on Serial Monitor and OLED
Humidity: 55.20% Temperature: 24.50Β°C 76.10Β°F
Humidity: 55.30% Temperature: 24.60Β°C 76.28Β°F
Temperature:
24.5 Β°C
Humidity:
55.2 %
- HVAC Systems: Climate control automation
- Weather Stations: Local weather monitoring
- Indoor Air Quality: Monitoring home/office environments
- Smart Home: Temperature-based automation
- Agriculture: Greenhouse monitoring
- Data Centers: Environmental monitoring
"Failed to read from DHT sensor!"
- Check wiring connections
- Ensure sensor is powered properly
- Verify correct pin assignment in code
- Wait 2 seconds after power-up for sensor to stabilize
Incorrect Readings
- Ensure sensor is not exposed to direct heat sources
- Allow sensor to stabilize for a few seconds
- Check for loose connections
OLED Display Not Working
- Verify I2C address (default: 0x3C)
- Check SDA/SCL connections
- Test I2C scanner to confirm address
- Temperature-Controlled Fan using Arduino
- ESP Mesh Network Configuration
- Automatic AC Temperature Controller
- IoT Weather Station using NodeMCU
- Arduino Projects
uint8_t DHTPin = 2; // Change to your preferred pin
// For Celsius only
Temperature = dht.readTemperature();
// For Fahrenheit
Temperature = dht.readTemperature(true);
delay(1000); // Change delay time (in milliseconds)
This project is open-source and available for educational and commercial purposes.
Full tutorial and detailed explanation available at: Interface DHT22 Sensor Module with Arduino
Feel free to fork this project and submit pull requests for improvements or bug fixes.
For questions and support, visit the Circuit Digest community forums or leave a comment on the project page.
Note: Ensure you use genuine DHT22 sensors for accurate readings. Many counterfeit sensors are available in the market with inferior performance.
Happy Making! π οΈ