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

Arduino Nano-Controlled Automated Irrigation System with Moisture Sensing and Water Level Detection

Image of Arduino Nano-Controlled Automated Irrigation System with Moisture Sensing and Water Level Detection

Circuit Documentation

Summary

The circuit is designed to automate the irrigation process based on soil moisture levels. It uses an Arduino Nano as the central microcontroller to read from multiple soil moisture sensors and control water pumps via a relay module. A water level float switch sensor is used to detect the water availability, and a red LED indicates the water level status. The system also includes a DIP switch for manual control over the irrigation process. Power management is handled by a solar panel, charge controller, and a battery setup.

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 Sensors (V1.0): Sensors that measure the moisture level in the soil.
  • Water Level Float Switch Sensor: A sensor that detects the presence or absence of water.

Actuators

  • Water Pumps: Devices used to pump water to the plants when the soil moisture level is below a certain threshold.

Indicators

  • LED (Red, Two Pin): An indicator light that signals the water level status.

Control

  • Relay 4 Channel 5v: A module with four relays to control high power devices such as the water pumps.
  • DIP Switch 4 Position: A manual switch that allows enabling or disabling individual irrigation lines.

Power Management

  • Solar Panel: A photovoltaic panel that converts sunlight into electrical energy.
  • Charge Controller (Do solara): Manages the charging of the battery from the solar panel and provides regulated output.
  • 18650 Battery in Holder: Provides power storage and supply for the system.
  • USB Male 2 Pin Connection: Used for connecting and powering the system through USB.

Connectors

  • Splicing Connector WAGO 221: Used to connect multiple wires together securely.

Switches

  • 2Pin Push Switch: A simple push button switch for manual control.

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 anode of the red LED.
  • 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.
  • Analog pins A0-A3 are connected to the soil moisture sensors.
  • 5V and GND pins are used to power the sensors and relay module.

DFRobot Capacitive Soil Moisture Sensors (V1.0)

  • Analog output pins are connected to the Arduino Nano's analog input pins A0-A3.
  • VCC and GND pins are connected to the 5V and GND distribution via WAGO connectors.

Water Pumps

  • VCC pins are connected to the normally open (NO) contacts of the relay module.
  • GND pins are connected together and to the GND distribution via a WAGO connector.

Relay 4 Channel 5v

  • IN1-IN4 pins are controlled by the Arduino Nano's digital pins D2-D5.
  • VCC is connected to the 5V distribution via a WAGO connector.
  • GND is connected to the GND distribution via a WAGO connector.
  • COM1-COM4 pins are connected together and to the 5V distribution via a WAGO connector.
  • NO1-NO4 pins are connected to the VCC pins of the water pumps.

LED (Red, Two Pin)

  • The anode is connected to the Arduino Nano's digital pin D7.
  • The cathode is connected to the GND distribution via a WAGO connector.

DIP Switch 4 Position

  • Pins 1-4 are connected to the GND distribution via a WAGO connector.
  • Pins 5-8 are connected to the Arduino Nano's digital pins D8-D11/MOSI.

Power Management Components

  • The solar panel is connected to the charge controller.
  • The charge controller's output is connected to the USB male 2 pin connection for power distribution.
  • The 18650 battery is connected to the charge controller for charging and power storage.

Splicing Connector WAGO 221

  • Used to distribute 5V and GND to various components in the circuit.

2Pin Push Switch

  • The input is connected to the GND distribution.
  • The output is connected to the Arduino Nano's digital pin D12/MISO.

Documented Code

// Definizione dei pin
const int sensoreUmidita[4] = {A0, A1, A2, A3};  // Pin dei sensori di umidità
const int rele[4] = {2, 3, 4, 5};  // Pin di controllo dei relè
const int dipSwitch[4] = {8, 9, 10, 11};  // Pin dei Dip Switch per attivare/disattivare le piante
const int galleggiantePin = 6;  // Pin del sensore a galleggiante
const int ledMancanzaAcqua = 7;  // Pin del LED di segnalazione per mancanza acqua

// Soglia di umidità sotto la quale si attiva la pompa
const int sogliaUmidita = 400;

// Variabili di controllo
unsigned long tempoUltimaIrrigazione[4];  // Tempo in millisecondi dell'ultima irrigazione per ogni pianta
const unsigned long intervallo24h = 86400000;  // 24 ore in millisecondi

void setup() {
  // Inizializzazione dei pin
  for (int i = 0; i < 4; i++) {
    pinMode(rele[i], OUTPUT);
    pinMode(dipSwitch[i], INPUT_PULLUP);  // Attiva la resistenza pull-up interna
    digitalWrite(rele[i], LOW); // Inizialmente le pompe sono spente
    tempoUltimaIrrigazione[i] = 0;  // Inizializza i tempi di irrigazione a 0
  }

  pinMode(galleggiantePin, INPUT);
  pinMode(ledMancanzaAcqua, OUTPUT);
  digitalWrite(ledMancanzaAcqua, LOW); // LED spento inizialmente
}

void loop() {
  bool cisternaPiena = digitalRead(galleggiantePin);
  bool pompaAccesa = false; // Variabile per controllare se una pompa è già accesa

  if (!cisternaPiena) {
    // Se la cisterna è vuota, accende il LED e non attiva le pompe
    digitalWrite(ledMancanzaAcqua, HIGH);
    for (int i = 0; i < 4; i++) {
      digitalWrite(rele[i], LOW); // Spegne tutte le pompe
    }
  } else {
    // Se la cisterna è piena, spegne il LED e controlla le piante
    digitalWrite(ledMancanzaAcqua, LOW);

    unsigned long tempoAttuale = millis();  // Ottiene il tempo attuale

    // Ciclo per controllare ogni pianta
    for (int i = 0; i < 4; i++) {
      // Se il dip switch è attivo, nessuna pompa è accesa, e sono trascorse 24 ore dall'ultima irrigazione
      if (!pompaAccesa && digitalRead(dipSwitch[i]) == LOW && (tempoAttuale - tempoUltimaIrrigazione[i]) >= intervallo24h) {
        int umidita = analogRead(sensoreUmidita[i]);
        if (umidita < sogliaUmidita) {
          digitalWrite(rele[i], HIGH); // Accende la pompa
          pompaAccesa = true; // Una pompa è ora accesa
          tempoUltimaIrrigazione[i] = tempoAttuale; // Aggiorna il tempo dell'ultima irrigazione
        } else {
          digitalWrite(rele[i], LOW); // Spegne la pompa se l'umidità è sufficiente
        }
      } else {
        digitalWrite(rele[i], LOW); // Spegne tutte le altre pompe
      }
    }
  }

  delay(1000); // Delay per evitare letture troppo frequenti
}

This code is responsible for controlling the irrigation system. It reads the soil moisture levels using the sensors and activates the pumps through the relay module when necessary. It also checks the water level using the float switch sensor and indicates the status using the red LED. The DIP switch allows for manual control over the irrigation process.