Skip to content

Latest commit

 

History

History
145 lines (109 loc) · 6.19 KB

File metadata and controls

145 lines (109 loc) · 6.19 KB

IoT-Based Environmental Monitoring System

A real-time environmental monitoring system built with ESP32 that collects and transmits temperature, humidity, air quality, and light level data to ThingSpeak for cloud-based logging and visualization.

Overview

This project implements a complete IoT solution for environmental monitoring. The system continuously reads sensor data from a network of environmental sensors connected to an ESP32 microcontroller, processes the readings, and uploads them to ThingSpeak—a popular IoT analytics platform—where data can be visualized, analyzed, and stored indefinitely.

Features

  • Real-time Data Collection: Continuously monitors environmental parameters every 15 seconds
  • Temperature & Humidity Monitoring: Uses DHT22 sensor for accurate climate readings
  • Light Level Detection: LDR sensor measures ambient light intensity
  • Air Quality Simulation: Potentiometer simulates MQ-135 air quality sensor for testing
  • WiFi Connectivity: ESP32 connects to networks for seamless cloud data transmission
  • ThingSpeak Integration: Automatic data upload to ThingSpeak platform for cloud storage and visualization
  • Serial Monitoring: Real-time data display via serial console for debugging and verification
  • Optimized Update Interval: 15-second intervals respect ThingSpeak API rate limits

Hardware Requirements

Component Specifications GPIO Pin
ESP32 Microcontroller with WiFi/Bluetooth N/A
DHT22 Temperature & Humidity Sensor GPIO4
LDR Light Dependent Resistor (Photoresistor) GPIO34 (ADC)
Potentiometer 10kΩ resistor (simulates MQ-135 air quality) GPIO35 (ADC)
Wokwi Simulator Online simulation platform N/A

How It Works

  1. Sensor Reading: The system reads temperature and humidity from the DHT22 sensor and analog values from the LDR and potentiometer
  2. Data Processing: Raw values are converted to user-friendly units (temperature in °C, humidity in %, light level 0-100%, air quality 0-500 scale)
  3. Serial Output: Data is printed to the serial console for real-time monitoring
  4. WiFi Connection: Establishes connection to the configured WiFi network
  5. Cloud Upload: Every 15 seconds, data is sent to ThingSpeak using HTTP GET requests
  6. Data Visualization: ThingSpeak displays the data in real-time charts and graphs

Measured Parameters

  • Temperature: Measured in Celsius (°C) via DHT22
  • Humidity: Measured as percentage (%) via DHT22
  • Air Quality: Mapped to 0-500 scale (simulated with potentiometer)
  • Light Level: Measured as percentage (0-100%) via LDR

Required Libraries

  • DHT sensor library: Handles DHT22 temperature and humidity sensor communication
  • Adafruit Unified Sensor: Provides standardized sensor interface
  • WiFi.h: Built-in ESP32 library for WiFi connectivity
  • HTTPClient.h: Built-in ESP32 library for HTTP communications

Setup Instructions

1. Install Required Libraries (Wokwi)

The libraries are automatically imported from libraries.txt. The required libraries are:

  • DHT sensor library
  • Adafruit Unified Sensor

2. Configure WiFi Credentials

Edit the credentials in sketch.ino:

const char* ssid = "Wokwi-GUEST";        // Your network SSID
const char* password = "";                 // Your network password

3. Set ThingSpeak API Key

Update the API key in sketch.ino:

String apiKey = "DOVDZPTBBR0G7NNU";       // Your ThingSpeak API key

4. Hardware Wiring

  • Connect DHT22 data pin to GPIO4
  • Connect LDR analog output to GPIO34
  • Connect potentiometer wiper to GPIO35

5. Upload & Monitor

  • Upload the sketch to your ESP32
  • Open the Serial Monitor at 115200 baud to view real-time data
  • Visit ThingSpeak to see cloud-stored data and visualizations

ThingSpeak Channel Configuration

The system sends data to four ThingSpeak fields:

  • Field 1: Temperature (°C)
  • Field 2: Humidity (%)
  • Field 3: Air Quality (0-500)
  • Field 4: Light Level (0-100%)

Visit ThingSpeak to create a channel and view your environmental data in real-time charts.

Project Structure

IoT-Based-Environmental-Monitoring-System/
├── README.md                    # Project documentation
├── code/
│   ├── sketch.ino              # ESP32 Arduino sketch (main code)
│   └── libraries.txt           # Required libraries list
└── media/
    ├── circuit-diagram.png     # Hardware connection diagram
    └── ThingSpeak_chart.png    # Example data visualization

Serial Output Example

WiFi connected!
Temp: 28.45 °C, Hum: 65.30 %, Air: 245.67, Light: 78.50 %
ThingSpeak response: 200
Temp: 28.47 °C, Hum: 65.28 %, Air: 246.12, Light: 79.10 %
ThingSpeak response: 200

Sensor Calibration

  • LDR: Mapped to 0-100% where 0 is complete darkness and 100 is maximum brightness
  • Air Quality Potentiometer: Mapped to 0-500 scale to simulate realistic MQ-135 readings (in a real deployment, this would be replaced with an actual MQ-135 sensor)

Troubleshooting

Issue Solution
DHT22 read failures Ensure sensor is properly wired and powered; check GPIO4 connection
WiFi connection fails Verify SSID and password are correct for your network
ThingSpeak errors Confirm API key is valid and has write permissions; check internet connectivity
Serial shows no data Verify baud rate is set to 115200 and correct COM port is selected

Future Enhancements

  • Add actual MQ-135 air quality sensor for real air quality measurements
  • Implement data logging to SD card for local backup
  • Add mobile app for remote monitoring
  • Integrate alerts for abnormal environmental conditions
  • Support multiple sensor nodes with mesh networking
  • Add battery power with low-power sleep modes

Platform Notes

This project is designed to run on the Wokwi Online Simulator for Arduino/ESP32, making it accessible without physical hardware. For production deployment on real hardware, ensure proper power supply and environmental protection for outdoor sensors.

License

This project is open-source and available for educational and personal use.