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

ESP32-Based Smart Soil and Rain Monitoring System with Buzzer Alert

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Soil and Rain Monitoring System with Buzzer Alert

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that includes an ESP32 microcontroller, a piezo buzzer, a soil moisture sensor, a rain sensor control board, and a yellow LED. The circuit is designed to monitor environmental conditions such as soil moisture and rain, and it provides visual and auditory alerts based on these conditions.

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 electronic device that produces a tone when a voltage is applied.
    • Pins: Negative pin, Positive pin
  3. Soil Moisture Sensor

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

    • Description: A control board for the YL-83 rain sensor, used to detect rain.
    • Pins: VCC, GND, DO, AO, POS, NEG
  5. LED: Two Pin (yellow)

    • Description: A yellow light-emitting diode 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)

Code Documentation

sketch.ino

#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 is designed to read temperature and humidity values from a DHT11 sensor connected to the ESP32. Based on the readings, it controls an LED and a piezo buzzer to provide visual and auditory alerts when the temperature or humidity goes beyond predefined thresholds. The data is also printed to the serial monitor every 30 seconds.