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

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

View and Edit Project In Cirkit DesignerImage 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

Sensors

Actuators

Indicators

Control

Power Management

Connectors

Switches

Wiring Details

Arduino Nano

DFRobot Capacitive Soil Moisture Sensors (V1.0)

Water Pumps

Relay 4 Channel 5v

LED (Red, Two Pin)

DIP Switch 4 Position

Power Management Components

Splicing Connector WAGO 221

2Pin Push Switch

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.