================================================================================
  Question 1: ESP32 DHT22 Temperature & Humidity Monitoring [30 Marks]
================================================================================

FULL QUESTION:
CAE 2 IoT Practical Exam - Section A (Answer either Q1 or Q2):
Q1. DHT22 Temperature and Humidity Monitoring [30 Marks]
Develop an ESP32-based temperature and humidity monitoring system using a DHT22 sensor.
The system should:
- Interface the DHT22 sensor with ESP32.
- Read the temperature and humidity values.
- Display the sensor readings through the Serial Monitor.
- Demonstrate the working of the system with suitable sensor readings.

SHORT QUESTION:
ESP32 DHT22 Temperature and Humidity Monitoring on Serial Monitor [30 Marks].

================================================================================
README & SETUP INSTRUCTIONS:
================================================================================
# Question 1: ESP32 DHT22 Temperature & Humidity Monitoring

## Problem Statement [30 Marks]
Develop an ESP32-based temperature and humidity monitoring system using a DHT22 sensor.
The system should:
1. Interface the DHT22 sensor with ESP32.
2. Read the temperature and humidity values.
3. Display the sensor readings through the Serial Monitor.
4. Demonstrate the working of the system with suitable sensor readings.

---

## Hardware Wiring
| DHT22 Sensor Pin | ESP32 Pin | Description |
| :--- | :--- | :--- |
| **VCC** | **3V3** | 3.3V Power Supply |
| **SDA / DATA** | **GPIO 18** | Digital Sensor Signal |
| **GND** | **GND** | Ground |

---

## How to Run in Wokwi Simulator
1. Navigate to [wokwi.com](https://wokwi.com) and create a new **ESP32** project.
2. Replace `sketch.ino` with the content of `sketch.ino` in this folder.
3. Replace `diagram.json` with `diagram.json` in this folder.
4. Add the libraries listed in `libraries.txt` (`DHT sensor library` and `Adafruit Unified Sensor`).
5. Click **Start Simulation (Play)**.
6. Open the **Serial Monitor** at **115200 baud**.
7. Click the DHT22 sensor icon and adjust the temperature and humidity sliders to observe real-time updates.

---

## Expected Output (Serial Monitor)
```text
==================================================
  ESP32 DHT22 Temperature & Humidity System
==================================================
DHT22 Sensor Initialized successfully.
Streaming readings every 2 seconds...

Temperature: 24.5 °C  |  Humidity: 50.0 %
Temperature: 28.2 °C  |  Humidity: 65.4 %
Temperature: 31.0 °C  |  Humidity: 72.1 %
```

================================================================================
SOURCE CODE FILES:
================================================================================

1. sketch.ino
--------------------------------------------------------------------------------
#include <DHT.h>

#define DHT_PIN 18
#define DHT_TYPE DHT22

DHT dht(DHT_PIN, DHT_TYPE);

void setup() {
  Serial.begin(115200);
  delay(1000);

  dht.begin();
  Serial.println("DHT22 Sensor Initialized successfully.");
  Serial.println("Streaming readings every 2 seconds...\n");
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("[ERROR] Failed to read from DHT22 sensor! Check wiring.");
    delay(2000);
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(temperature, 1);
  Serial.print(" °C  |  Humidity: ");
  Serial.print(humidity, 1);
  Serial.println(" %");

  delay(2000);
}
--------------------------------------------------------------------------------

2. diagram.json
--------------------------------------------------------------------------------
{
  "version": 1,
  "author": "IoT Practical Exam",
  "editor": "wokwi",
  "parts": [
    { "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} },
    { "type": "wokwi-dht22", "id": "dht1", "top": 0.3, "left": -159, "attrs": {} }
  ],
  "connections": [
    [ "esp:TX", "$serialMonitor:RX", "", [] ],
    [ "esp:RX", "$serialMonitor:TX", "", [] ],
    [ "dht1:GND", "esp:GND.2", "black", [ "v0" ] ],
    [ "dht1:VCC", "esp:3V3", "red", [ "v0" ] ],
    [ "dht1:SDA", "esp:18", "green", [ "v0" ] ]
  ],
  "dependencies": {}
}
--------------------------------------------------------------------------------

3. libraries.txt
--------------------------------------------------------------------------------
DHT sensor library
Adafruit Unified Sensor
--------------------------------------------------------------------------------
