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.
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.
- 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
| 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 |
- Sensor Reading: The system reads temperature and humidity from the DHT22 sensor and analog values from the LDR and potentiometer
- Data Processing: Raw values are converted to user-friendly units (temperature in °C, humidity in %, light level 0-100%, air quality 0-500 scale)
- Serial Output: Data is printed to the serial console for real-time monitoring
- WiFi Connection: Establishes connection to the configured WiFi network
- Cloud Upload: Every 15 seconds, data is sent to ThingSpeak using HTTP GET requests
- Data Visualization: ThingSpeak displays the data in real-time charts and graphs
- 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
- 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
The libraries are automatically imported from libraries.txt. The required libraries are:
- DHT sensor library
- Adafruit Unified Sensor
Edit the credentials in sketch.ino:
const char* ssid = "Wokwi-GUEST"; // Your network SSID
const char* password = ""; // Your network passwordUpdate the API key in sketch.ino:
String apiKey = "DOVDZPTBBR0G7NNU"; // Your ThingSpeak API key- Connect DHT22 data pin to GPIO4
- Connect LDR analog output to GPIO34
- Connect potentiometer wiper to GPIO35
- 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
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.
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
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
- 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)
| 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 |
- 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
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.
This project is open-source and available for educational and personal use.