Arduino DHT22 + LCD Weather Station using Wokwi Simulator (Step-by-Step Guide)

 

Build a real-time temperature and humidity monitoring system using Arduino UNO, DHT22 sensor, and 16x2 LCD in the Wokwi simulator. This beginner-friendly IoT project is perfect for students, makers, and STEM learners.


 Components Required (Wokwi)

  • Arduino UNO

  • DHT22 Temperature & Humidity Sensor

  • 16x2 LCD Display (I2C recommended)

  • Jumper wires

You can create this project online using Wokwi Arduino Simulator.


 Step 1: Create Project in Wokwi

  1. Go to wokwi.com

  2. Click New Project

  3. Select Arduino UNO

  4. Add components:

    • Search and add DHT22

    • Search and add LCD 16x2 I2C


 Step 2: Circuit Connections

 DHT22 Connections:

  • VCC → 5V

  • GND → GND

  • DATA → Digital Pin 2

 LCD I2C Connections:

  • VCC → 5V

  • GND → GND

  • SDA → A4

  • SCL → A5

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": {}
}

 Code:

/*
 * 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 connected to 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 characters for degree symbol
byte degreeSymbol[8] = {
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

// Custom character for humidity drop
byte dropSymbol[8] = {
  0b00100,
  0b00100,
  0b01010,
  0b01010,
  0b10001,
  0b10001,
  0b10001,
  0b01110
};

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(9600);
  Serial.println("Weather Station Initializing...");
 
  // Initialize DHT sensor
  dht.begin();
 
  // Initialize LCD (16x2 display)
  lcd.begin(16, 2);
 
  // Create custom characters
  lcd.createChar(0, degreeSymbol);
  lcd.createChar(1, dropSymbol);
 
  // Display welcome message
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Weather Station");
  lcd.setCursor(0, 1);
  lcd.print("Initializing...");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Wait a few seconds between measurements
  delay(2000);
 
  // Read humidity
  float humidity = dht.readHumidity();
 
  // Read temperature in Celsius
  float temperatureC = dht.readTemperature();
 
  // Read temperature in Fahrenheit
  float temperatureF = dht.readTemperature(true);
 
  // Check if any reads failed
  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;
  }
 
  // Calculate heat index in Fahrenheit
  float heatIndexF = dht.computeHeatIndex(temperatureF, humidity);
 
  // Calculate heat index in Celsius
  float heatIndexC = dht.computeHeatIndex(temperatureC, humidity, false);
 
  // Print to Serial Monitor for debugging
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.print("%  Temperature: ");
  Serial.print(temperatureC);
  Serial.print("°C / ");
  Serial.print(temperatureF);
  Serial.print("°F  Heat Index: ");
  Serial.print(heatIndexC);
  Serial.println("°C");
 
  // Display on LCD - Line 1: Temperature
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperatureC, 1);  // 1 decimal place
  lcd.write(byte(0));          // Degree symbol
  lcd.print("C ");
  lcd.print(temperatureF, 1);
  lcd.write(byte(0));
  lcd.print("F");
 
  // Display on LCD - Line 2: Humidity
  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(humidity, 1);
  lcd.print("%");
  lcd.write(byte(1));          // Drop symbol
 
  // Alternate display every 5 seconds to show heat index
  delay(5000);
 
  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);
}

Step 3: Install Required Libraries (Wokwi)

Add these libraries in the code:

  • DHT sensor library

  • LiquidCrystal_I2C



Step 5: Run Simulation

  1. Click Start Simulation

  2. Adjust temperature and humidity values in DHT22

  3. Observe live weather data on LCD


🌟 Project Output

  • Displays Temperature in Celsius

  • Displays Humidity in Percentage

  • Updates every 2 seconds

  • Fully simulated in Wokwi


Comments