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

ESP32-Based Smart Irrigation System with Water Level and NPK Soil Sensors

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

Circuit Documentation

Summary

This circuit is designed to control water pumps based on the readings from water level sensors and an NPK soil sensor. The system uses an ESP32 microcontroller to read sensor data and control relays that activate the water pumps. The circuit also includes a voltage regulator to step down the voltage from a 12V power supply to 5V for the relays and the ESP32.

Component List

  1. 5V Relay

    • Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
    • Description: Used to control the water pumps based on signals from the ESP32.
  2. Water Pump

    • Pins: VCC, GND
    • Description: Pumps water when activated by the relay.
  3. Water Level Sensor

    • Pins: SIG, VCC, GND
    • Description: Measures the water level and sends the data to the ESP32.
  4. 12V Power Supply

    • Pins: +, -
    • Description: Provides 12V power to the circuit.
  5. nMOS Transistor (MOSFET)

    • Pins: gate, drain, source
    • Description: Used for switching and amplification.
  6. Voltage Regulator

    • Pins: IN, GND, OUT
    • Description: Steps down the voltage from 12V to 5V.
  7. Resistor

    • Pins: pin1, pin2
    • Description: 10k Ohm resistors used for current limiting and voltage division.
  8. ESP32-WROOM-32UE

    • Pins: 3v3, EN, VP, VN, 34, 35, 32, 33, 25, 26, 27, 14, 12, GND, 13, D2, D3, 5V, 23, 22, TX, RX, 21, 19, 18, 5, 17, 16, 4, 0, 2, 15, D1, D0, CKL
    • Description: Microcontroller used to read sensor data and control the relays.
  9. NPK Soil Sensor

    • Pins: 12V DC, A, B, GND
    • Description: Measures the nutrient content in the soil.

Wiring Details

5V Relay

Water Pump

Water Level Sensor

12V Power Supply

nMOS Transistor (MOSFET)

Voltage Regulator

Resistor

ESP32-WROOM-32UE

NPK Soil Sensor

Code Documentation

// Define pin connections
#define WATER_LEVEL_SENSOR_1_PIN 12
#define WATER_LEVEL_SENSOR_2_PIN 13
#define RELAY_1_PIN D1
#define RELAY_2_PIN D2
#define NPK_SENSOR_ANALOG_PIN 34
#define NPK_SENSOR_DIGITAL_PIN 35

// Threshold values for water level sensors
#define WATER_LEVEL_THRESHOLD 500  // Adjust this value based on your sensor's output

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

  // Initialize water level sensor pins as input
  pinMode(WATER_LEVEL_SENSOR_1_PIN, INPUT);
  pinMode(WATER_LEVEL_SENSOR_2_PIN, INPUT);

  // Initialize relay pins as output
  pinMode(RELAY_1_PIN, OUTPUT);
  pinMode(RELAY_2_PIN, OUTPUT);

  // Initialize NPK sensor pins
  pinMode(NPK_SENSOR_ANALOG_PIN, INPUT);
  pinMode(NPK_SENSOR_DIGITAL_PIN, INPUT);

  // Turn off relays initially
  digitalWrite(RELAY_1_PIN, LOW);
  digitalWrite(RELAY_2_PIN, LOW);
}

void loop() {
  // Read water level sensor values
  int waterLevel1 = analogRead(WATER_LEVEL_SENSOR_1_PIN);
  int waterLevel2 = analogRead(WATER_LEVEL_SENSOR_2_PIN);

  // Read NPK sensor values
  int npkAnalogValue = analogRead(NPK_SENSOR_ANALOG_PIN);
  int npkDigitalValue = digitalRead(NPK_SENSOR_DIGITAL_PIN);

  // Print sensor values to serial monitor
  Serial.print("Water Level Sensor 1: ");
  Serial.println(waterLevel1);
  Serial.print("Water Level Sensor 2: ");
  Serial.println(waterLevel2);
  Serial.print("NPK Sensor Analog Value: ");
  Serial.println(npkAnalogValue);
  Serial.print("NPK Sensor Digital Value: ");
  Serial.println(npkDigitalValue);

  // Control water pumps based on water level sensor readings
  if (waterLevel1 < WATER_LEVEL_THRESHOLD) {
    digitalWrite(RELAY_1_PIN, HIGH);  // Turn on pump 1
  } else {
    digitalWrite(RELAY_1_PIN, LOW);   // Turn off pump 1
  }

  if (waterLevel2 < WATER_LEVEL_THRESHOLD) {
    digitalWrite(RELAY_2_PIN, HIGH);  // Turn on pump 2
  } else {
    digitalWrite(RELAY_2_PIN, LOW);   // Turn off pump 2
  }

  // Add a delay to avoid flooding the serial monitor
  delay(1000);
}

This code initializes the pins for the water level sensors, relays, and NPK sensor. It reads the sensor values and controls the relays to turn the water pumps on or off based on the water level readings. The sensor values are also printed to the serial monitor for debugging and monitoring purposes.