Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Nano-Based Automated Irrigation System with Solar Charging and Water Level Monitoring

Image of Arduino Nano-Based Automated Irrigation System with Solar Charging and Water Level Monitoring

Circuit Documentation

Summary

This circuit is designed to automate a watering system using an Arduino Nano as the central controller. The system monitors soil moisture levels using multiple DFRobot Capacitive Soil Moisture Sensors and controls water pumps to irrigate plants as needed. A water level float switch sensor is used to detect the presence of water in a reservoir, and a relay module is employed to control the water pumps. The system also includes a red LED indicator for signaling the water level status and a DIP switch for manual control over the watering process. The power supply is managed through a solar panel and a charge controller, with an 18650 battery holder for energy storage. A USB connection is provided for alternative power input.

Component List

Microcontroller

  • Arduino Nano: A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.

Sensors

  • DFRobot Capacitive Soil Moisture Sensor (V1.0): Measures soil moisture levels using capacitive sensing.
  • Water Level Float Switch Sensor: Detects the presence of water in the reservoir.

Actuators

  • Water Pump: Pumps water from the reservoir to the plants when activated.

Indicators

  • LED (Red, Two Pin): Serves as an indicator for the water level status.

Control

  • Relay 4 Channel 5v: Controls the high-power circuits of the water pumps.
  • DIP Switch 4 Position: Allows manual control over the watering process.

Power Management

  • Solar Panel: Provides renewable energy to power the system.
  • Do solara (Charge Controller): Manages the charging of the battery from the solar panel.
  • 18650 Battery Holder: Stores energy for the system.
  • USB Male 2 Pin Connection: Alternative power input for the system.

Connectors

  • Splicing Connector WAGO 221: Used for creating wire connections without soldering.
  • 2Pin Push Switch: Allows manual triggering of an action within the circuit.

Wiring Details

Arduino Nano

  • Digital pins D2-D5 are connected to the relay module to control the water pumps.
  • Digital pin D6 is connected to the water level float switch sensor.
  • Digital pin D7 is connected to the red LED indicator.
  • Digital pins D8-D11/MOSI are connected to the DIP switch for manual control.
  • Digital pin D12/MISO is connected to the 2Pin Push Switch.
  • The GND pin is connected to the ground of various components for a common ground.
  • The 5V pin is connected to the Splicing Connector WAGO 221 to distribute power.
  • Analog pins A0-A3 are connected to the soil moisture sensors.

DFRobot Capacitive Soil Moisture Sensors

  • The A pin of each sensor is connected to a corresponding analog input on the Arduino Nano.
  • The VCC and GND pins are connected to the power distribution via the WAGO connectors.

Water Pumps

  • The VCC pin of each pump is connected to the normally open (NO) contacts of the relay module.
  • The GND pins are connected together and to the ground distribution via the WAGO connector.

Relay 4 Channel 5v

  • The IN1-IN4 pins are controlled by the Arduino Nano.
  • The VCC and GND pins are connected to the power distribution via the WAGO connectors.
  • The COM pins are connected together and to the power distribution via the WAGO connector.
  • The NO contacts are connected to the water pumps.

LED (Red, Two Pin)

  • The anode is connected to the Arduino Nano.
  • The cathode is connected to the ground distribution via the WAGO connector.

DIP Switch 4 Position

  • Pins 1-4 are connected to the ground distribution via the WAGO connector.
  • Pins 5-8 are connected to the Arduino Nano for manual control.

Power Management Components

  • The solar panel is connected to the charge controller.
  • The charge controller's output is connected to the USB connection and the 18650 battery holder.
  • The battery holder is connected to the charge controller for charging.

Connectors

  • The WAGO 221 connectors are used to distribute power and ground connections throughout the circuit.

Documented Code

// Definition of pins
const int soilMoistureSensors[4] = {A0, A1, A2, A3};  // Soil moisture sensor pins
const int relays[4] = {2, 3, 4, 5};  // Relay control pins
const int dipSwitch[4] = {8, 9, 10, 11};  // DIP switch pins for plant activation/deactivation
const int floatSensorPin = 6;  // Float switch sensor pin
const int waterLackLed = 7;  // Water lack LED indicator pin

// Moisture threshold below which the pump is activated
const int moistureThreshold = 400;

// Control variables
unsigned long lastIrrigationTime[4];  // Time in milliseconds of the last irrigation for each plant
const unsigned long interval24h = 86400000;  // 24 hours in milliseconds

void setup() {
  // Pin initialization
  for (int i = 0; i < 4; i++) {
    pinMode(relays[i], OUTPUT);
    pinMode(dipSwitch[i], INPUT_PULLUP);  // Activate internal pull-up resistor
    digitalWrite(relays[i], LOW); // Initially, the pumps are off
    lastIrrigationTime[i] = 0;  // Initialize irrigation times to 0
  }

  pinMode(floatSensorPin, INPUT);
  pinMode(waterLackLed, OUTPUT);
  digitalWrite(waterLackLed, LOW); // Initially, the LED is off
}

void loop() {
  bool isReservoirFull = digitalRead(floatSensorPin);
  bool isPumpOn = false; // Variable to check if a pump is already on

  if (!isReservoirFull) {
    // If the reservoir is empty, turn on the LED and do not activate the pumps
    digitalWrite(waterLackLed, HIGH);
    for (int i = 0; i < 4; i++) {
      digitalWrite(relays[i], LOW); // Turn off all pumps
    }
  } else {
    // If the reservoir is full, turn off the LED and check the plants
    digitalWrite(waterLackLed, LOW);

    unsigned long currentTime = millis();  // Get the current time

    // Loop to check each plant
    for (int i = 0; i < 4; i++) {
      // If the DIP switch is active, no pump is on, and 24 hours have passed since the last irrigation
      if (!isPumpOn && digitalRead(dipSwitch[i]) == LOW && (currentTime - lastIrrigationTime[i]) >= interval24h) {
        int moisture = analogRead(soilMoistureSensors[i]);
        if (moisture < moistureThreshold) {
          digitalWrite(relays[i], HIGH); // Turn on the pump
          isPumpOn = true; // A pump is now on
          lastIrrigationTime[i] = currentTime; // Update the time of the last irrigation
        } else {
          digitalWrite(relays[i], LOW); // Turn off the pump if the moisture is sufficient
        }
      } else {
        digitalWrite(relays[i], LOW); // Turn off all other pumps
      }
    }
  }

  delay(1000); // Delay to avoid too frequent readings
}

This code is designed to run on the Arduino Nano and controls the automated watering system. It reads the soil moisture levels and the water level in the reservoir, and based on these readings, it decides whether to activate the water pumps. The DIP switches provide manual control over the system, allowing individual pumps to be turned on or off. The LED indicator is used to signal when the water level in the reservoir is low.