⚙️ Intermediate
📡 IoT
🟢 Wokwi
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.
0Requirements
Components Required (Wokwi)
Arduino UNO
Microcontroller board
DHT22 Sensor
Temp & Humidity
16×2 LCD (I2C)
Character display
Jumper Wires
For connections
All components are available virtually — no physical hardware needed. Use the free Wokwi Arduino Simulator at wokwi.com.
1Wokwi Setup
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
2Wiring
Circuit Connections
🌡️ DHT22 Sensor
| DHT22 Pin | Arduino Pin | Wire Color |
|---|---|---|
| VCC | 5V | 🔴 Red |
| GND | GND | ⚫ Black |
| DATA | Digital Pin 2 | 🟢 Green |
📟 16×2 LCD (Parallel, 4-bit mode)
| 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 |
3Wokwi Config
diagram.json
Paste this into the diagram.json tab in Wokwi to wire everything automatically.
diagram.json
{
"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": {}
}
4Sketch
Arduino Code
LCD output preview:
Temp: 24.0°C 75.2°F
Humidity: 65.0% 💧
sketch.ino — Arduino C++
/* * 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); }
5Libraries
Required Libraries
Add these via Wokwi's library manager or libraries.txt:
DHT sensor library
by Adafruit — reads DHT22 data
by Adafruit — reads DHT22 data
LiquidCrystal
Built-in — drives 16×2 LCD
Built-in — drives 16×2 LCD
Adafruit Unified Sensor
Required by DHT library
Required by DHT library
6Simulate
Run Simulation
Paste the Code
Copy the sketch into Wokwi's code editor tab.
Add diagram.json
Paste the diagram.json to auto-wire all components.
Start Simulation
Click the green ▶ Play button to run.
Adjust Sensor
Click the DHT22 to change temperature & humidity values live.
✅ Result
Project Output
Temp: 24.0°C 75.2°F
Humidity: 65.0% 💧
🌡️ Temperature in °C & °F
💧 Humidity in %
🔥 Heat Index
⏱️ Updates every 2 seconds
🖥️ Runs in Wokwi — no hardware
More Arduino Projects
🟢 Beginner — Foundation & Basics
01Intro to Wokwi Simulator
02Multiple LED Patterns (Traffic Light)
03Knight Rider LED Chaser
04RGB LED Color Mixing
05Potentiometer Analog Input
06Buzzer Sound Generation
07Photoresistor Light Sensor
🔵 Intermediate — Displays & Sensors
0116×2 LCD Text Output
0216×2 I2C LCD Display
037-Segment Display Counter
044-Digit 7-Segment Clock
05LCD + Ultrasonic Parking Sensor
06DHT22 + LCD Weather Station ← You are here
🔴 Advanced — Motors, Security & Expert
01Dual Servo Motor + OLED
02Stepper Motor (28BYJ-48)
03Password-Based Lock
04RFID Access Control (MFRC522)
05Biometric Dual Authentication
📡 IoT & Advanced Displays
Comments
Post a Comment