This project is an IoT-based environmental monitoring system built using an ESP32 microcontroller, various sensors, and ThingSpeak. It monitors soil moisture, water level, carbon monoxide (CO) levels, motion, light intensity, temperature, and humidity, sending the data to ThingSpeak for real-time visualization and analysis.
- Soil Moisture Monitoring: Tracks soil moisture levels.
- Water Level Monitoring: Detects water levels, triggers an alarm when the level is low.
- Carbon Monoxide Detection (MQ-7): Measures CO concentration in the air.
- Motion Detection: Detects motion and updates the status.
- Light Intensity Monitoring (LDR): Measures ambient light levels.
- Temperature and Humidity Monitoring (DHT22): Reads temperature and humidity.
- ThingSpeak Integration: Sends sensor data to ThingSpeak for remote monitoring.
- Buzzer Alert: Activates an alarm based on water level readings.
- ESP32 microcontroller
- DHT22 sensor (for temperature and humidity)
- Soil moisture sensor
- Water level sensor
- MQ-7 sensor (for carbon monoxide detection)
- Motion sensor
- LDR (Light Dependent Resistor) sensor
- Buzzer
Sensor | Pin |
---|---|
Soil Moisture | 34 |
Water Level | 35 |
MQ-7 (CO sensor) | 32 |
Motion Sensor | 18 |
LDR | 25 |
DHT22 | 2 |
Buzzer | 4 |
- Connect Sensors: Follow the pin configuration table to wire the sensors to the ESP32.
- Install Libraries:
- Install the
DHT
library for the DHT22 sensor. - Install the
ThingSpeak
library to communicate with the ThingSpeak API.
- Install the
- Configure WiFi:
- Update
ssid
andpassword
in the code with your WiFi credentials.
- Update
- ThingSpeak Settings:
- Set
myChannelNumber
andmyWriteAPIKey
with your ThingSpeak channel details.
- Set
WiFi.begin(ssid, password);
ThingSpeak.begin(client);
Establishes WiFi connection and initializes ThingSpeak.
Reads data from:
- Soil moisture sensor
- Water level sensor
- MQ-7 sensor
- Motion sensor
- LDR
- DHT22 sensor for temperature and humidity
if (waterLevelValue < 100) {
digitalWrite(buzzer_pin, HIGH); // Turn on buzzer
} else {
digitalWrite(buzzer_pin, LOW); // Turn off buzzer
}
Activates the buzzer if water level is below a certain threshold.
Sends sensor readings to ThingSpeak fields.
ThingSpeak.setField(1, waterLevelValue);
ThingSpeak.setField(2, mq7Value);
ThingSpeak.setField(3, ldrValue);
ThingSpeak.setField(4, humidity);
ThingSpeak.setField(5, temperature);
ThingSpeak.setField(6, soilMoistureValue);
ThingSpeak.setField(7, motionValue);
delay(5000);
Delays 5 seconds between updates.
- Open the serial monitor to view real-time sensor readings.
- Monitor data remotely via ThingSpeak.
- Ensure all sensor connections are secure.
- Check WiFi credentials if unable to connect.
- Verify ThingSpeak API key and channel number for successful data updates.
This project is licensed under the MIT License.