Digital Room Temperature and Humidity Monitoring System
DHT22 readings shown live on an LCD
Aim
To measure room temperature and relative humidity with a DHT22 sensor and display both values in real time on a 16x2 LCD.
Overview
The DHT22 digital sensor sends calibrated temperature and humidity readings over a single-wire protocol. The Arduino reads it every two seconds, applies sanity checks (valid range, NaN handling), and prints the values to a 16x2 character LCD over the 4-bit data bus (or I2C). The serial monitor provides a secondary logging output.
Components Required
- Arduino Uno
- DHT22 / AM2302 temperature-humidity sensor
- 10k pull-up resistor for the data line (often built into modules)
- 16x2 LCD display (parallel or I2C backpack)
- 10k potentiometer for LCD contrast (parallel version)
- Breadboard and jumper wires
Circuit Connections
| From | To | Note |
|---|---|---|
| DHT22 VCC | Arduino 5V | - |
| DHT22 GND | Arduino GND | - |
| DHT22 DATA | Arduino D2 | With 10k pull-up to 5V |
| I2C LCD VCC / GND | Arduino 5V / GND | - |
| I2C LCD SDA / SCL | Arduino A4 / A5 | - |
Interactive Circuit Diagram
Simulate the circuit: adjust the sensor inputs below and watch the outputs react according to the control logic.
Loading Wokwi components...
Working
- The Arduino initializes the DHT22 and the LCD in setup().
- Every two seconds it requests a fresh reading from the sensor.
- If isnan(t) or isnan(h), the display shows a Sensor error message instead of bogus values.
- Valid readings are printed as temperature in C on line 1 and humidity in % on line 2.
- The same values are echoed to the serial port for logging.
Control Logic
Sampling period must be at least 2 s for the DHT22. Readings outside 0.1-99.9 or NaN are rejected as errors, which is the standard validation pattern for one-wire sensors.
Arduino Code
1// Practical 6: Digital Room Temperature and Humidity Monitor2#include <DHT.h>3#include <LiquidCrystal_I2C.h>45#define DHTPIN 2 // DHT22 data pin6#define DHTTYPE DHT2278DHT dht(DHTPIN, DHTTYPE);9LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD: SDA-A4, SCL-A51011void setup() {12 lcd.init();13 lcd.backlight();14 lcd.print("T/H Monitor");15 dht.begin();16 Serial.begin(9600);17}1819void loop() {20 float humidity = dht.readHumidity();21 float tempC = dht.readTemperature(); // Celsius2223 lcd.clear();24 if (isnan(humidity) || isnan(tempC)) { // Validate the reading25 lcd.print("Sensor error!");26 Serial.println("Failed to read from DHT sensor!");27 } else {28 lcd.setCursor(0, 0);29 lcd.print("Temp: ");30 lcd.print(tempC, 1);31 lcd.print((char)223); // Degree symbol32 lcd.print("C");33 lcd.setCursor(0, 1);34 lcd.print("Hum: ");35 lcd.print(humidity, 1);36 lcd.print(" %");3738 Serial.print("Temp: ");39 Serial.print(tempC);40 Serial.print(" C, Hum: ");41 Serial.print(humidity);42 Serial.println(" %");43 }44 delay(2000); // DHT22 needs >= 2 s between reads45}