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

ESP32-Based Automated Irrigation System with Soil Moisture and Water Level Sensors

View and Edit Project In Cirkit DesignerImage of ESP32-Based Automated Irrigation System with Soil Moisture and Water Level Sensors

Circuit Documentation

Summary

This circuit is designed to control a system with two fields, each having a motor, a soil moisture sensor, and a water level sensor. The system monitors the soil moisture levels and water levels in each field. When a field is detected to be dry, the corresponding water pump is activated to balance the water levels.

Component List

  1. 5V Mini Water Pump

    • Description: A small water pump used to irrigate the fields.
    • Pins: Positive pin, Negative pin
  2. SparkFun Soil Moisture Sensor

    • Description: A sensor used to measure the moisture level in the soil.
    • Pins: VCC, GND, SIG
  3. XL4015 5A DC Buck Step-down

    • Description: A DC-DC buck converter used to step down the voltage.
    • Pins: Output +, Output -, Input +, Input -
  4. L298N 2A Dual Motor Driver Module with PWM Control

    • Description: A motor driver module used to control the water pumps.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT4, OUT3, ENA, IN1, IN2, IN3, ENB, IN4
  5. Water Sensor

    • Description: A sensor used to detect the water level.
    • Pins: Signal, VCC, GND
  6. ESP32

    • Description: A microcontroller used to control the entire system.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  7. 12V Power Supply

    • Description: A power supply providing 12V to the circuit.
    • Pins: +, -

Wiring Details

5V Mini Water Pump

SparkFun Soil Moisture Sensor

XL4015 5A DC Buck Step-down

L298N 2A Dual Motor Driver Module with PWM Control

Water Sensor

ESP32

Code Documentation

/*
 * This Arduino Sketch controls a system with two fields, each having a motor,
 * a soil moisture sensor, and a water level sensor. When a field is detected
 * to be dry, the corresponding water pump is activated to balance the water
 * levels.
 */

// Pin definitions
const int soilMoisturePin1 = 2;
const int soilMoisturePin2 = 15;
const int waterSensorPin1 = 4;
const int waterSensorPin2 = 5;
const int motorPin1 = 13;
const int motorPin2 = 27;
const int motorControlPin1A = 12;
const int motorControlPin1B = 14;
const int motorControlPin2A = 25;
const int motorControlPin2B = 33;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(soilMoisturePin1, INPUT);
  pinMode(soilMoisturePin2, INPUT);
  pinMode(waterSensorPin1, INPUT);
  pinMode(waterSensorPin2, INPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorControlPin1A, OUTPUT);
  pinMode(motorControlPin1B, OUTPUT);
  pinMode(motorControlPin2A, OUTPUT);
  pinMode(motorControlPin2B, OUTPUT);
}

void loop() {
  // Read soil moisture levels
  int soilMoisture1 = analogRead(soilMoisturePin1);
  int soilMoisture2 = analogRead(soilMoisturePin2);

  // Read water levels
  int waterLevel1 = digitalRead(waterSensorPin1);
  int waterLevel2 = digitalRead(waterSensorPin2);

  // Check if field 1 is dry
  if (soilMoisture1 < 500) {
    // Activate motor 1 to balance water levels
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorControlPin1A, HIGH);
    digitalWrite(motorControlPin1B, LOW);
  } else {
    // Deactivate motor 1