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

ESP32-Based Smart Greenhouse Monitoring System with Wi-Fi Control

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Greenhouse Monitoring System with Wi-Fi Control

Smart Green House Monitoring System

Summary

The Smart Green House Monitoring System is designed to automate and monitor various environmental parameters within a greenhouse. The system uses an ESP32 microcontroller to read data from sensors, control actuators, and communicate with a cloud service for remote monitoring and control. The system includes sensors for humidity, temperature, and soil moisture, as well as actuators like a water pump, fan, and buzzer. The system is powered by a 5V battery and uses relays to control the actuators.

Component List

Humidity YL-69

5V Mini Water Pump

Fan

5V Battery

ESP32 (30 pin)

DHT22

PIR/Motion Sensor

Peltier Module

5V Relay

Buzzer

Wiring Details

Humidity YL-69

5V Mini Water Pump

Fan

5V Battery

ESP32 (30 pin)

DHT22

PIR/Motion Sensor

Peltier Module

5V Relay

Buzzer

Documented Code

#define BLYNK_TEMPLATE_ID "TMPL6o0woVv00"
#define BLYNK_TEMPLATE_NAME "Smart Green House Monitoring System"
#define BLYNK_AUTH_TOKEN "AToqA3zayEOBl25VyE-lmPJIqbo1qABA"

#include <DHT.h>                  // Include the DHT library
#include <BlynkSimpleEsp32.h>    // Include the Blynk library
#include <WiFi.h>                // Include the WiFi library
#include <FirebaseESP32.h>       // Include Firebase library

// Firebase credentials
#define FIREBASE_HOST "smartgreenhouseprojectgroup05-default-rtdb.asia-southeast1.firebasedatabase.app"
#define FIREBASE_AUTH "ekbPCRO9qRZ8GBJI72HzHPoVKRRaf4E9i4IGVwwp" // Use your actual database secret

// Your Wi-Fi credentials
const char* ssid = "Maleesha";       // Replace with your Wi-Fi SSID
const char* password = "03022001";  // Replace with your Wi-Fi password

#define DHTPIN 5                    // DHT11 sensor connected to pin D5
#define DHTTYPE DHT11               // DHT 11 type
#define SOIL_MOISTURE_PIN 35        // Soil moisture sensor connected to pin D35
#define RELAY_PIN 15                // Relay is connected to pin D15
#define FAN_PIN 32                  // Fan is connected to pin D32

DHT dht(DHTPIN, DHTTYPE);             // Create a DHT object

int soilMoistureValue = 0;
const int soilMoistureThreshold = 2500;  // Threshold for dry soil (adjust as needed)
String waterPumpState = "OFF";             // Variable to track water pump state
String fanState = "OFF";                   // Variable to track fan state
const float fanTemperatureThreshold = 27.0; // Fan activation temperature threshold

// Firebase and Blynk data
FirebaseData firebaseData; // Firebase object
FirebaseConfig config;     // Firebase configuration
FirebaseAuth auth;         // Firebase authentication object

void setup() {
    // Initialize the serial monitor for debugging
    Serial.begin(115200);
    
    // Set pin modes
    pinMode(SOIL_MOISTURE_PIN, INPUT);
    pinMode(RELAY_PIN, OUTPUT);
    pinMode(FAN_PIN, OUTPUT);

    // Initially turn off relay and fan
    digitalWrite(RELAY_PIN, HIGH);  // HIGH turns OFF the pump
    digitalWrite(FAN_PIN, HIGH);     // HIGH turns OFF the fan

    // Initialize DHT sensor
    dht.begin();

    // Initialize Blynk with Wi-Fi credentials
    Blynk.begin(BLYNK_AUTH_TOKEN, ssid, password);

    // Initialize Firebase
    config.host = FIREBASE_HOST;
    config.signer.tokens.legacy_token = FIREBASE_AUTH;
    
    Firebase.begin(&config, &auth);   // Initialize Firebase with config and auth
    Firebase.reconnectWiFi(true);     // Reconnect Wi-Fi if disconnected

    Serial.println("System Initialized - Water pump OFF, Fan OFF");
}

void loop() {
    // Read the soil moisture level
    soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
    Serial.print("Soil Moisture Value: ");
    Serial.println(soilMoistureValue);

    // Control the water pump based on soil moisture
    if (soilMoistureValue > soilMoistureThreshold) {
        digitalWrite(RELAY_PIN, LOW);  // Turn ON the pump
        waterPumpState = "ON";
        Serial.println("Soil is dry, turning water pump ON");
        Blynk.virtualWrite(V3, 255);   // Update virtual LED on V3
    } else {
        digitalWrite(RELAY_PIN, HIGH);  // Turn OFF the pump
        waterPumpState = "OFF";
        Serial.println("Soil is moist, turning water pump OFF");
        Blynk.virtualWrite(V3, 0);      // Update virtual LED on V3
    }

    // Read humidity and temperature from the DHT sensor
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();

    // Check for valid readings
    if (isnan(humidity) || isnan(temperature)) {
        Serial.println("Failed to