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

ESP32-Based Smart Irrigation System with Wi-Fi Connectivity and Dual Water Level Monitoring

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Irrigation System with Wi-Fi Connectivity and Dual Water Level Monitoring

Circuit Documentation

Summary

The circuit in question is designed to monitor environmental conditions such as humidity and water level, and to control a DC motor based on these readings. The core of the circuit is an ESP32 microcontroller, which is responsible for reading sensor data, controlling the motor driver, and communicating with a server over WiFi. The circuit includes a humidity sensor (YL-69), two water level sensors, a 18650 Li-Ion battery for power, a motor driver to control the DC motor, and the DC motor itself.

Component List

Humidity Sensor (YL-69)

18650 Li-Ion Battery

ESP32 Microcontroller

Motor Driver

DC Motor

Water Level Sensor

Wiring Details

Humidity Sensor (YL-69)

18650 Li-Ion Battery

ESP32 Microcontroller

Motor Driver

DC Motor

Water Level Sensor

Documented Code

ESP32 Microcontroller Code

#include <WiFi.h>
#include <HTTPClient.h>
#include <L298N.h>

// Pin Definitions
const int humidityAnalogPin = VP; // A0 pin of Humidity YL-69
const int humidityDigitalPin = D2; // D0 pin of Humidity YL-69
const int waterLevelPin = VN; // SIG pin of Water Level Sensor

// Motor Pins
const int motorPin1 = D18; // IN1 pin of L298N
const int motorPin2 = D19; // IN2 pin of L298N
const int enablePin = D5;  // ENA pin of L298N

// WiFi Credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// Create L298N instance
L298N motor(motorPin1, motorPin2, enablePin);

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Initialize Pins
  pinMode(humidityAnalogPin, INPUT);
  pinMode(humidityDigitalPin, INPUT);
  pinMode(waterLevelPin, INPUT);

  // Initialize Motor
  motor.setSpeed(0); // Set initial speed to 0

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  // Read Humidity Sensor
  int humidityValue = analogRead(humidityAnalogPin);
  int humidityDigitalValue = digitalRead(humidityDigitalPin);
  Serial.print("Humidity Analog Value: ");
  Serial.println(humidityValue);
  Serial.print("Humidity Digital Value: ");
  Serial.println(humidityDigitalValue);

  // Read Water Level Sensor
  int waterLevelValue = analogRead(waterLevelPin);
  Serial.print("Water Level Value: ");
  Serial.println(waterLevelValue);

  // Control Motor Based on Sensor Readings
  if (humidityDigitalValue == LOW || waterLevelValue < 500) {
    // Turn on Motor
    motor.setSpeed(255); // Set speed to maximum
    motor.forward();     // Move motor forward
  } else {
    // Turn off Motor
    motor.setSpeed(0);   // Stop motor
  }

  // Send Data to Server
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin("http://yourserver.com/api/data");
    http.addHeader("Content-Type", "application/json");

    String jsonData = "{\"humidityAnalog\":" + String(humidityValue) + 
                      ",\"humidityDigital\":" + String(humidityDigitalValue) + 
                      ",\"waterLevel\":" + String(waterLevelValue) + "}";

    int httpResponseCode = http.POST(jsonData);
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println(httpResponseCode);
      Serial.println(response);
    } else {
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  }

  // Delay for Stability
  delay(1000);
}

This code is responsible for initializing the ESP32 microcontroller and its connected components, reading sensor data, controlling the motor based on the sensor data, and sending the sensor data to a server over WiFi.