Arduino DHT22 + LCD
Weather Station
Build a real-time temperature & humidity monitor using Arduino UNO, DHT22 sensor, and a 16×2 LCD — simulated entirely in Wokwi. Beginner-friendly with full code and diagram.
Components Required (Wokwi)
All components are available virtually — no physical hardware needed. Use the free Wokwi Arduino Simulator at wokwi.com.
Create Project in Wokwi
- Go to wokwi.com
- Click New Project
- Select Arduino UNO as the board
- In the component panel, search and add DHT22
- Search and add LCD 16×2 I2C
Circuit Connections
| DHT22 Pin | Arduino Pin | Wire Color |
|---|---|---|
| VCC | 5V | 🔴 Red |
| GND | GND | ⚫ Black |
| DATA | Digital Pin 2 | 🟢 Green |
| LCD Pin | Arduino Pin | Wire Color |
|---|---|---|
| VSS / VDD Power | GND / 5V | ⚫ / 🔴 |
| V0 (contrast) | GND | ⚫ Black |
| RS | Pin 7 | 🔵 Blue |
| RW | GND | ⚫ Black |
| E (Enable) | Pin 8 | 🩵 Cyan |
| D4 | Pin 9 | 🟡 Yellow |
| D5 | Pin 10 | 🟠 Orange |
| D6 | Pin 11 | 🟣 Purple |
| D7 | Pin 12 | ⚪ Gray |
| A (backlight +) | 5V | 🔴 Red |
| K (backlight −) | GND | ⚫ Black |
diagram.json
Paste this into the diagram.json tab in Wokwi to wire everything automatically.
{
"version": 1,
"author": "Arduino Weather Station",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-uno", "id": "uno", "top": 77.4, "left": -77.4, "attrs": {} },
{
"type": "wokwi-dht22",
"id": "dht1",
"top": -95.7,
"left": 225,
"attrs": { "temperature": "24", "humidity": "65" }
},
{ "type": "wokwi-lcd1602", "id": "lcd1", "top": -207.77, "left": -185.6, "attrs": {} }
],
"connections": [
[ "dht1:GND", "uno:GND.1", "black", [ "h0" ] ],
[ "dht1:VCC", "uno:5V", "red", [ "h0" ] ],
[ "dht1:SDA", "uno:2", "green", [ "h0" ] ],
[ "lcd1:VSS", "uno:GND.2", "black", [ "h0" ] ],
[ "lcd1:VDD", "uno:5V", "red", [ "h0" ] ],
[ "lcd1:V0", "uno:GND.2", "black", [ "h0" ] ],
[ "lcd1:RS", "uno:7", "blue", [ "h0" ] ],
[ "lcd1:RW", "uno:GND.2", "black", [ "h0" ] ],
[ "lcd1:E", "uno:8", "cyan", [ "h0" ] ],
[ "lcd1:D4", "uno:9", "yellow", [ "h0" ] ],
[ "lcd1:D5", "uno:10", "orange", [ "h0" ] ],
[ "lcd1:D6", "uno:11", "purple", [ "h0" ] ],
[ "lcd1:D7", "uno:12", "gray", [ "h0" ] ],
[ "lcd1:A", "uno:5V", "red", [ "h0" ] ],
[ "lcd1:K", "uno:GND.2", "black", [ "h0" ] ]
],
"dependencies": {}
}
Arduino Code
LCD output preview:
/* * Arduino Weather Station * DHT22 Temperature & Humidity Sensor with LCD Display * Created for Wokwi Simulator */ #include <LiquidCrystal.h> #include <DHT.h> // DHT22 Sensor Configuration #define DHTPIN 2 // DHT22 data pin → Arduino pin 2 #define DHTTYPE DHT22 // DHT 22 (AM2302) // Initialize DHT sensor DHT dht(DHTPIN, DHTTYPE); // LCD Configuration (RS, E, D4, D5, D6, D7) LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Custom character: degree symbol byte degreeSymbol[8] = { 0b00110, 0b01001, 0b01001, 0b00110, 0b00000, 0b00000, 0b00000, 0b00000 }; // Custom character: humidity drop byte dropSymbol[8] = { 0b00100, 0b00100, 0b01010, 0b01010, 0b10001, 0b10001, 0b10001, 0b01110 }; void setup() { Serial.begin(9600); Serial.println("Weather Station Initializing..."); dht.begin(); lcd.begin(16, 2); lcd.createChar(0, degreeSymbol); lcd.createChar(1, dropSymbol); // Welcome splash screen lcd.clear(); lcd.setCursor(0, 0); lcd.print("Weather Station"); lcd.setCursor(0, 1); lcd.print("Initializing..."); delay(2000); lcd.clear(); } void loop() { delay(2000); // DHT22 sampling interval float humidity = dht.readHumidity(); float temperatureC = dht.readTemperature(); float temperatureF = dht.readTemperature(true); // Guard against failed reads if (isnan(humidity) || isnan(temperatureC) || isnan(temperatureF)) { Serial.println("Failed to read from DHT sensor!"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Sensor Error!"); lcd.setCursor(0, 1); lcd.print("Check Connection"); return; } float heatIndexF = dht.computeHeatIndex(temperatureF, humidity); float heatIndexC = dht.computeHeatIndex(temperatureC, humidity, false); // Serial Monitor debug output Serial.print("Humidity: "); Serial.print(humidity); Serial.print("% Temp: "); Serial.print(temperatureC); Serial.print("°C / "); Serial.print(temperatureF); Serial.print("°F Heat: "); Serial.print(heatIndexC); Serial.println("°C"); // ── Screen 1: Temperature + Humidity ── lcd.clear(); lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(temperatureC, 1); lcd.write(byte(0)); // ° symbol lcd.print("C "); lcd.print(temperatureF, 1); lcd.write(byte(0)); lcd.print("F"); lcd.setCursor(0, 1); lcd.print("Humidity: "); lcd.print(humidity, 1); lcd.print("%"); lcd.write(byte(1)); // 💧 drop symbol delay(5000); // ── Screen 2: Heat Index ── lcd.clear(); lcd.setCursor(0, 0); lcd.print("Heat Index:"); lcd.setCursor(0, 1); lcd.print(heatIndexC, 1); lcd.write(byte(0)); lcd.print("C / "); lcd.print(heatIndexF, 1); lcd.write(byte(0)); lcd.print("F"); delay(3000); }
Required Libraries
Add these via Wokwi's library manager or libraries.txt:
by Adafruit — reads DHT22 data
Built-in — drives 16×2 LCD
Required by DHT library
Run Simulation
Copy the sketch into Wokwi's code editor tab.
Paste the diagram.json to auto-wire all components.
Click the green ▶ Play button to run.
Click the DHT22 to change temperature & humidity values live.
Comments
Post a Comment