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

ESP32-Based Smart Greenhouse Monitoring System with Wi-Fi and Firebase Integration

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

Smart Greenhouse Monitoring System Circuit Documentation

Summary

The Smart Greenhouse Monitoring System is designed to monitor and control environmental conditions within a greenhouse. It utilizes an ESP32 microcontroller to interface with various sensors and actuators, including a DHT11 temperature and humidity sensor, a YL-69 soil moisture sensor, a water level sensor, relays for controlling a water pump and a fan, and a 5V power supply. The system is capable of reading environmental data and adjusting the conditions by controlling the water pump and fan based on predefined thresholds. The ESP32 is also connected to Blynk and Firebase for remote monitoring and data logging.

Component List

DHT11 Sensor V2

Humidity YL-69

5V Mini Water Pump

Fan

5V Battery

ESP32 (30 Pin)

5V Relay

Water Level Sensor

Wiring Details

DHT11 Sensor V2

Humidity YL-69

5V Mini Water Pump

Fan

5V Battery

ESP32 (30 Pin)

5V Relay (for water pump)

5V Relay (for fan)

Water Level Sensor

Documented Code

The code for the ESP32 microcontroller is written in C++ and is designed to be compiled and uploaded using the Arduino IDE. The code includes libraries for the DHT sensor, Blynk, WiFi, and Firebase to facilitate sensor readings, control actuators, and communicate with remote services for data logging and monitoring.

// Include necessary libraries
#include <DHT.h>
#include <BlynkSimpleEsp32.h>
#include <WiFi.h>
#include <FirebaseESP32.h>

// Define constants for Blynk and Firebase
#define BLYNK_TEMPLATE_ID "TMPL6o0woVv00"
#define BLYNK_TEMPLATE_NAME "Smart Green House Monitoring System"
#define BLYNK_AUTH_TOKEN "AToqA3zayEOBl25VyE-lmPJIqbo1qABA"
#define FIREBASE_HOST "smartgreenhouseprojectgroup05-default-rtdb.asia-southeast1.firebasedatabase.app"
#define FIREBASE_AUTH "ekbPCRO9qRZ8GBJI72HzHPoVKRRaf4E9i4IGVwwp"

// Wi-Fi credentials
const char* ssid = "Maleesha";
const char* password = "03022001";

// Pin definitions
#define DHTPIN 5
#define DHTTYPE DHT11
#define SOIL_MOISTURE_PIN 35
#define RELAY_PIN 15
#define FAN_PIN 32

// Create sensor and control objects
DHT dht(DHTPIN, DHTTYPE);

// Variables for sensor readings and control states
int soilMoistureValue = 0;
const int soilMoistureThreshold = 2500;
String waterPumpState = "OFF";
String fanState = "OFF";
const float fanTemperatureThreshold = 27.0;

// Firebase and Blynk data objects
FirebaseData firebaseData;
FirebaseConfig config;
FirebaseAuth auth;

// Setup function to initialize components
void setup() {
    Serial.begin(115200);
    pinMode(SOIL_MOISTURE_PIN, INPUT);
    pinMode(RELAY_PIN, OUTPUT);
    pinMode(FAN_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, HIGH);
    digitalWrite(FAN_PIN, HIGH);
    dht.begin();
    Blynk.begin(BLYNK_AUTH_TOKEN, ssid, password);
    config.host = FIREBASE_HOST;
    config.signer.tokens.legacy_token = FIREBASE_AUTH;
    Firebase.begin(&config, &auth);
    Firebase.reconnectWiFi(true);
    Serial.println("System Initialized - Water pump OFF, Fan OFF");
}

// Main loop function
void loop() {
    // Read sensors and control actuators
    // ... (code continues with sensor reading, control logic, and communication)
}

// ... (rest of the code)

The code is structured with a setup function to initialize the system and a loop function that continuously reads sensor data, controls the actuators, and communicates with Blynk and Firebase. The ESP32 reads the soil moisture level and controls the water pump based on the threshold. It also reads temperature and humidity from the DHT11 sensor and controls the fan based on the temperature threshold. Sensor data is sent to Blynk for real-time monitoring and to Firebase for data logging.