ESP32-Based Smart Weather Station with Humidity and Temperature Alerts
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor environmental conditions such as temperature, humidity, soil moisture, and rain detection. It uses an ESP32 microcontroller to read data from various sensors and control LEDs and a piezo buzzer based on the sensor readings. The circuit includes a DHT11 sensor for temperature and humidity, a soil moisture sensor, a rain sensor, an MQ-4 gas sensor, a BH1750 light sensor, and multiple LEDs for visual indicators.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
Piezo Buzzer
- Description: An audio signaling device that produces sound.
- Pins: Negative pin, Positive pin
Soil Moisture Sensor
- Description: A sensor used to measure the moisture content in the soil.
- Pins: VCC, GND, SIG
YL-83 Rain Sensor - Control Board
- Description: A sensor used to detect the presence of rain.
- Pins: VCC, GND, DO, AO, POS, NEG
LED: Two Pin (yellow)
- Description: A yellow LED used for visual indication.
- Pins: Cathode, Anode
DHT11 Humidity and Temperature Sensor
- Description: A sensor used to measure temperature and humidity.
- Pins: VDD, DATA, NULL, GND
LED: Two Pin (red)
- Description: A red LED used for visual indication.
- Pins: Cathode, Anode
LED: Two Pin (blue)
- Description: A blue LED used for visual indication.
- Pins: Cathode, Anode
MQ-4
- Description: A gas sensor used to detect methane (CH4).
- Pins: A0, D0, GND, VCC
LED: Two Pin (green)
- Description: A green LED used for visual indication.
- Pins: Cathode, Anode
BH1750
- Description: A light sensor used to measure ambient light intensity.
- Pins: VCC, GND, SCL, SDA, ADDR
LED: Two Pin (white)
- Description: A white LED used for visual indication.
- Pins: Cathode, Anode
Wiring Details
ESP32 (30 pin)
- GND: Connected to the negative pin of the Piezo Buzzer, GND of the MQ-4, cathode of the yellow LED, and GND of the YL-83 Rain Sensor.
- D4: Connected to the positive pin of the Piezo Buzzer.
- 3V3: Connected to VCC of the MQ-4, VCC of the YL-83 Rain Sensor, VDD of the DHT11, and VCC of the BH1750.
- D35: Connected to A0 of the MQ-4.
- D32: Connected to AO of the YL-83 Rain Sensor.
- D14: Connected to the anode of the red LED.
- D12: Connected to the anode of the white LED.
- D13: Connected to the anode of the yellow LED.
- D22: Connected to SCL of the BH1750.
- D21: Connected to SDA of the BH1750.
- D5: Connected to DATA of the DHT11.
- D2: Connected to the anode of the blue LED.
- D15: Connected to the anode of the green LED.
Piezo Buzzer
- Negative pin: Connected to GND of the ESP32.
- Positive pin: Connected to D4 of the ESP32.
Soil Moisture Sensor
- VCC: Connected to POS of the YL-83 Rain Sensor.
- GND: Connected to NEG of the YL-83 Rain Sensor.
YL-83 Rain Sensor - Control Board
- GND: Connected to GND of the ESP32.
- VCC: Connected to 3V3 of the ESP32.
- AO: Connected to D32 of the ESP32.
- POS: Connected to VCC of the Soil Moisture Sensor.
- NEG: Connected to GND of the Soil Moisture Sensor.
LED: Two Pin (yellow)
- Cathode: Connected to GND of the ESP32.
- Anode: Connected to D13 of the ESP32.
DHT11 Humidity and Temperature Sensor
- VDD: Connected to 3V3 of the ESP32.
- DATA: Connected to D5 of the ESP32.
- GND: Connected to GND of the ESP32.
LED: Two Pin (red)
- Cathode: Connected to GND of the ESP32.
- Anode: Connected to D14 of the ESP32.
LED: Two Pin (blue)
- Cathode: Connected to GND of the ESP32.
- Anode: Connected to D2 of the ESP32.
MQ-4
- A0: Connected to D35 of the ESP32.
- GND: Connected to GND of the ESP32.
- VCC: Connected to 3V3 of the ESP32.
LED: Two Pin (green)
- Cathode: Connected to GND of the ESP32.
- Anode: Connected to D15 of the ESP32.
BH1750
- VCC: Connected to 3V3 of the ESP32.
- GND: Connected to GND of the ESP32.
- SCL: Connected to D22 of the ESP32.
- SDA: Connected to D21 of the ESP32.
LED: Two Pin (white)
- Cathode: Connected to GND of the ESP32.
- Anode: Connected to D12 of the ESP32.
Code Documentation
#include <DHT.h>
#define DHTPIN 5 // Pin where the DHT11 data pin is connected
#define DHTTYPE DHT11
const int tempLedPin = 14; // LED pin for Temperature
const int humidityLedPin = 2; // LED pin for Humidity
const int buzzerPin = 4; // Buzzer pin
const float HUMIDITY_HIGH_THRESHOLD = 85.0; // High humidity threshold
const float HUMIDITY_LOW_THRESHOLD = 65.0; // Low humidity threshold
const float TEMP_HIGH_THRESHOLD = 20.0; // High temperature threshold
const float TEMP_LOW_THRESHOLD = 18.0; // Low temperature threshold
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
pinMode(tempLedPin, OUTPUT);
pinMode(humidityLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
if (humidity > HUMIDITY_HIGH_THRESHOLD || humidity < HUMIDITY_LOW_THRESHOLD) {
digitalWrite(humidityLedPin, HIGH);
tone(buzzerPin, 3000);
} else {
digitalWrite(humidityLedPin, LOW);
noTone(buzzerPin);
}
if (temperatureC > TEMP_HIGH_THRESHOLD || temperatureC < TEMP_LOW_THRESHOLD) {
digitalWrite(tempLedPin, HIGH);
tone(buzzerPin, 3000);
} else {
digitalWrite(tempLedPin, LOW);
noTone(buzzerPin);
}
Serial.print("Temperature (°C): ");
Serial.print(temperatureC);
Serial.print(" , Humidity (RH %): ");
Serial.println(humidity);
delay(30000); // Wait for 30 seconds
}
This code initializes the DHT11 sensor and sets up the pins for the LEDs and the buzzer. In the loop function, it reads the temperature and humidity values and checks if they are within the defined thresholds. If the values are outside the thresholds, it turns on the corresponding LED and activates the buzzer. The values are also printed to the serial monitor every 30 seconds.