Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Weather Station with Humidity and Temperature Alerts

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Weather Station with Humidity and Temperature Alerts

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

  1. 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
  2. Piezo Buzzer

    • Description: An audio signaling device that produces sound.
    • Pins: Negative pin, Positive pin
  3. Soil Moisture Sensor

    • Description: A sensor used to measure the moisture content in the soil.
    • Pins: VCC, GND, SIG
  4. YL-83 Rain Sensor - Control Board

    • Description: A sensor used to detect the presence of rain.
    • Pins: VCC, GND, DO, AO, POS, NEG
  5. LED: Two Pin (yellow)

    • Description: A yellow LED used for visual indication.
    • Pins: Cathode, Anode
  6. DHT11 Humidity and Temperature Sensor

    • Description: A sensor used to measure temperature and humidity.
    • Pins: VDD, DATA, NULL, GND
  7. LED: Two Pin (red)

    • Description: A red LED used for visual indication.
    • Pins: Cathode, Anode
  8. LED: Two Pin (blue)

    • Description: A blue LED used for visual indication.
    • Pins: Cathode, Anode
  9. MQ-4

    • Description: A gas sensor used to detect methane (CH4).
    • Pins: A0, D0, GND, VCC
  10. LED: Two Pin (green)

    • Description: A green LED used for visual indication.
    • Pins: Cathode, Anode
  11. BH1750

    • Description: A light sensor used to measure ambient light intensity.
    • Pins: VCC, GND, SCL, SDA, ADDR
  12. LED: Two Pin (white)

    • Description: A white LED used for visual indication.
    • Pins: Cathode, Anode

Wiring Details

ESP32 (30 pin)

Piezo Buzzer

Soil Moisture Sensor

YL-83 Rain Sensor - Control Board

LED: Two Pin (yellow)

DHT11 Humidity and Temperature Sensor

LED: Two Pin (red)

LED: Two Pin (blue)

MQ-4

LED: Two Pin (green)

BH1750

LED: Two Pin (white)

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.