Skip to content

Auto-Watering System

Automatic Garden Irrigation

Garden Watering System

Automated Garden Irrigation

Specifications

The rainfall in mm per year may be equal to Zero in this region of the world, so the system is connected to the water supply network.

The watering will is initiated when the system is powered and depending on the mode selected will repeat once or twice (every 12 or 24h) a day for a certain time.

Changing the watering mode should not affect the watering time which must remain the same (Based on the time the system was powered on)

Design

A 12V electrovalve is used and connected directely to the tap. The hose pass throught the plants which are watered from the drip heads along the line.

To power the device, we are using is an old Laptop Power Supply 19.3 V DC output and some stepdown to get the expected Power Input.

A simple push button will allow you to switch between the two mode “Summer” and “Winter” defined beforehand in the code.

0
Hours of conception
0
Hours of Coding
0
Years of Automated Watering
0
Breakdown
  • 2 x LM 2596 Board - StepDown

    The LM2596 is a commonly used popular step-down switching regulator IC. The adjustable version can take in input voltage from 4.5V to 40V (Here 19.3V from an old Laptop Power Supply) and convert it to variable voltage sourcing upto of 3A of continues current.

  • 1 x Arduino Nano

    Open-source electronic prototyping platform enabling users to create interactive electronic objects.

  • 1 x Relay

    A relay simply is an electrically operated switch.

  • 1 x Rectifier Diode L4007

    Will absorbe Parasites generated by the movement of the solenoïd when it's turning On / Off.

  • 2 x Resistor 220 Ohm + LED

    To indicate the Mode selected

  • 1 x 12V DC Electrovalve

    Normally Closed type. Will let water run under 12V DC

About the Rectifier Diode

The rectifier diode is mandatory here. If missing, some parasites may disturb the functionment of the entire system each time the solenoïd turn on/off. The Rectifier Diode must be as close as possible from the solenoïd itself.

Before to find this solution, I had tried many options to limit the parasites. Using 2 No. of LM 2596 is one of my tentative to limit the problems. But it was not enough.

It’s possible to use only one LM2596 with 12V Output since both the Arduino and the Valve work with that  voltage and wouldn’t reach a consumption  of 3 Ampers.

// Creative Commons - www.ben-amar.com - 2021
// This Code was written for Ben-Amar.com under CC license: BY-NC-SA  (Attribution Mandatory, NonCommercial & ShareAlike)
// You must you credit "Ben-Amar.com" to remix, adapt, and build upon your work non-commercially. You must license your new creations under the identical terms.

//===========================================
//=========== VARIABLES DECLARATION =========
//===========================================

const byte ledhiv = 7;                // Indication LED "Winter"
const byte ledete = 8;                // Indication LED "Summer"
const byte interruptPin = 3;          // Pin for Push Button to switch Summer to Winter
const byte relay1 = 12;               // Relay to operat the Electric Transformer (230V)
volatile long jour = 86400000;        // Millis in 24h
unsigned long debut = 0;              // Variable to start counting a 24h or 12h sequence
unsigned long gHiv = 120000;           // Time to irrigate during winter (120s)
unsigned long gEte = 160000;           // Time to irrigate during winter (160s)
volatile int season = 0;              // Variable for season in ISR
int seasonapplied = season;           // Variable for season in void Loop (Is it necessary? Does Volatile In works in "Switch" and "If"?)
int trigger = 0;                      // Button trigger: variable used to detect a change of season and turn the adequat ledPin High
volatile long debounce = 0;           // To insure NO button bouncing
volatile long test = 0;
volatile long testint = 0;

//===========================================
//===================== SETUP ===============
//===========================================



void setup() {
  Serial.begin(9600);                                                               // Start Serial Monitor to follow step on Screen (Problem solving)
  Serial.println("--- Start Serial Monitor ---");                                   // Serial Monitor Information
  pinMode(ledhiv, OUTPUT);                                                          // Set ledhiv pin as Output
  pinMode(ledete, OUTPUT);                                                          // Set ledete pin as Output
  pinMode(relay1, OUTPUT);                                                          // Set relay1 pin as Output
  pinMode(interruptPin, INPUT_PULLUP);                                              // Set button pin as Interrupt
  Serial.println("...");                                                            // Serial Monitor Information
  Serial.println("--- PinMode Set");                                                // Serial Monitor Information
  attachInterrupt(digitalPinToInterrupt(interruptPin), timetogive, FALLING);        // Interrupt mode Definition (Pin, ISR loop to execute, Mode)
  Serial.println("--- Interrupt Set");                                              // Serial Monitor Information
  digitalWrite (ledhiv, HIGH);
  digitalWrite (relay1, LOW);                                                       // Set relay1 pin LOW => Power transformer ON (the Relay trigger "LOW")
  Serial.println("--- Setup Watering initiated");                                   // Serial Monitor Information
  delay (120000);                                                                    // Delay 120 seconds to water as Initialisation mode
  digitalWrite (relay1, HIGH);                                                      // Set relay1 pin LOW => Watering OFF (the Relay trigger "LOW")
  digitalWrite (ledhiv, LOW);
  Serial.println("--- Setup Watering Finished: 30 seconds");                        // Serial Monitor Information
  season = 0;                                                                       // Set season variable as Winter (0) - if Value = 1: Summer
  Serial.print("Season : ");
  Serial.println(season);
}

//===========================================
//======================== LOOP =============
//===========================================


void loop() {
  seasonapplied = season;                                                           // copy the ISR variable value to the Variable used in the loop
  if (seasonapplied == 0) {                                                         // Main IF : Season checking
    if ((millis() - debut >= (jour - gHiv)) && (digitalRead(relay1) == HIGH)) {     // Compare "jour" Value - time to give in winter with the actual amount of millis (interval)
      digitalWrite (relay1, LOW);                                                   // Set relay1 pin LOW => Power transformer ON (the Relay trigger "LOW")
      Serial.print(" Season = ");                                                   // Serial Monitor Information
      Serial.print(seasonapplied);                                                  // Serial Monitor Information
      Serial.print(" --- Hiver watering ON: ");                                     // Serial Monitor Information
      Serial.print(" millis = ");                                                   // Serial Monitor Information
      Serial.println(millis());                                                     // Serial Monitor Information
      digitalWrite (ledhiv, HIGH);                                                  // Turn On the LED indicating the WINTER mode is giving water
    }

    else if ((millis() - debut >= jour) && (digitalRead(relay1) == LOW)) {            // Compare "jour" Value with the actual amount of millis (jour is the laps of time during watering (here 23h:59m:30s)
      digitalWrite (relay1, HIGH);                                                    // Set relay1 pin HIGH => Watering OFF (the Relay trigger "LOW")
      debut = millis();                                                               // Update of the value debut to check the following interval starting from this instant!
      Serial.print(" Season = ");                                                     // Serial Monitor Information
      Serial.print(seasonapplied);                                                    // Serial Monitor Information
      Serial.print(" --- Hiver watering OFF: ");                                      // Serial Monitor Information
      Serial.print(" millis = ");                                                     // Serial Monitor Information
      Serial.println(millis());                                                       // Serial Monitor Information
      digitalWrite (ledhiv, LOW);                                                     // Turn OHH the LED indicating the WINTER mode
      season = 0;
    }
  }
  if (seasonapplied == 1) {                                                             // Main IF : Season checking
    if ((millis() - debut >= ((jour / 2) - gEte)) && (digitalRead(relay1) == HIGH)) {   // Compare "jour" Value - time to give in summer with the actual amount of millis (interval)
      digitalWrite (relay1, LOW);                                                       // Set relay1 pin LOW => Power transformer ON (the Relay trigger "LOW")
      Serial.print(" Season = ");                                                       // Serial Monitor Information
      Serial.print(seasonapplied);                                                      // Serial Monitor Information
      Serial.print(" --- Summer watering ON: ");                                        // Serial Monitor Information
      Serial.print(" millis = ");                                                       // Serial Monitor Information
      Serial.println(millis());                                                         // Serial Monitor Information
      digitalWrite (ledete, HIGH);                                                      // Turn On the LED indicating the SUMMER mode
    }
    else if ((millis() - debut >= (jour / 2)) && (digitalRead(relay1) == LOW)) {          // Compare "jour" Value with the actual amount of millis (jour is the laps of time during watering (here 11h:59m:00s)
      digitalWrite (relay1, HIGH);                                                        // Set relay1 pin HIGH => Watering OFF (the Relay trigger "LOW")
      debut = millis();                                                                   // Update of the value debut to check the following interval starting from this instant!
      Serial.print(" Season = ");                                                         // Serial Monitor Information
      Serial.print(seasonapplied);                                                        // Serial Monitor Information
      Serial.print(" --- Summer watering OFF: ");                                         // Serial Monitor Information
      Serial.print(" millis = ");                                                         // Serial Monitor Information
      Serial.println(millis());                                                           // Serial Monitor Information
      digitalWrite (ledete, LOW);                                                         // Turn OFF the LED indicating the SUMMER mode
      season = 1;
    }
  }
  if (trigger != season) {                                                              // This if detect the change of season with the varible volatile in the ISR. Then it light the appropriate LED.
    trigger = season;                                                                   // We reset trigger as Season to detect further change
    if (season == 0) {                                                                  // If variable season = 0 : winter light activated
      digitalWrite (relay1, HIGH);                                                      // Set relay1 pin LOW => Power transformer OFF (the Relay trigger "LOW") FOR SAFETY : Don't let the water Run by mistake.
      digitalWrite (ledhiv, HIGH);                                                      // Turn ON the LED indicating the WINTER mode. It will stay On until next watering.
      digitalWrite (ledete, LOW);                                                       // Turn OFF the LED indicating the SUMMER mode
      Serial.println("button has been pressed now Hiver mode");                         // Serial Monitor Information
    }
    else if (season == 1) {                                                             // If variable season = 1 : summer light activated
      digitalWrite (relay1, HIGH);                                                      // Set relay1 pin LOW => Power transformer OFF (the Relay trigger "LOW") FOR SAFETY : Don't let the water Run by mistake.
      digitalWrite (ledete, HIGH);                                                      // Turn ON the LED indicating the SUMMER mode. It will stay On until next watering.
      digitalWrite (ledhiv, LOW);                                                       // Turn OFF the LED indicating the WINTER mode
      Serial.println("button has been pressed now summer mode");                        // Serial Monitor Information
    }
  }
}

//===========================================
//========================= ISR =============
//===========================================

//=== ISR ===
void timetogive() {                 // Name the ISR, it will be executed if the pushbutton pressed
if (millis() - debounce > 500) {    //Comparison to avoid Bouncing Button!
if (season == 1) {                  // Change the Variable Season value IF == 1 turn it to 0
season = 0;
}
else if (season == 0) {             // Change the Variable Season value IF == 0 turn it to 1
season = 1;
}
debounce = millis ();               //New value for further comparison
}
}

// Creative Commons - www.ben-amar.com - 2021
// This Code was written for Ben-Amar.com under CC license: BY-NC-SA  (Attribution Mandatory, NonCommercial & ShareAlike)
// You must you credit "Ben-Amar.com" to remix, adapt, and build upon your work non-commercially. You must license your new creations under the identical terms. 

About the ISR

Using an ISR (Interruption Service Routine) wasn’t really necessary. The ISR is interesting if your code is running step by step and you need to interrupt it as any moment to execute a certain action (For Example during a “Delay”).
But here I have used a “Blink with No Delay” type of program which doesn’t stop at all. It’s just comparing the time set for each action with the clock and execute tasks when necessary.
A simple Input Pullup would have done the job since its detection could have been done at any moment.

Conclusion

The system is very satisfying. Over 4 Years of use by the time I’m uploading this project here and I had only one breakdown: The relay stop working. Easily replaced and since, the system working like a charm.

Potential Improvements:

  1. Potentiometer to increase / reduce the watering time.
  2. Development of a “non stop watering” mode to calibrate the dripping head without hassle.
  3. Integration of a screen with the time since last watering, the mode selected instead of the LED, the amount of watering / day.
  4. Integration of a Soil mosturising control system to avoid wasting water on raining days.
  5. Integration of a Solar Panel Based power supply to reduce it’s Carbon Footprint.
  6. Creation of a 3D printed Box to improve the hardware organisation & wiring.