Project tutorial

Automatic Watering System © Apache-2.0

Water your garden with up to three sprinklers directly from your water tap.

  • 6,974 views
  • 8 comments
  • 16 respects

Components and supplies

A000066 iso both
Arduino UNO & Genuino UNO
×1
DS3231
×1
4 Channel MOSFET IRF540
×1
RGB 3 Color Full Color LED SMD Module For Arduino
×1
Red DS-333B Waterproof Button
×1
Black DS-333B Waterproof Button
×1
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×1
Clear Waterproof Plastic Box, about 200x120x56mm
×1
Power Supply 12VDC 2.0A
×1
DC 12V 1/2" Electric Solenoid Valve Normally Closed
I recommend one with a plastic cap and screws to attach the wires.
×4
Hall Effect Water Flow Sensor 1/2"
×1
Connection from garden tap to 1/2" female
×1
Connector with 1/2" female on both sides
×1
4 way cross coupling with 4x 1/2" female
×1
Thread joint connector 1/2" female to quick connector of garden hoses
×3
Thread Seal Tape
×1
Cables to connect valves and water flow sensor
×1

Necessary tools and machines

Drilling Machine

Apps and online services

About this project

Your garden or backyard needs frequent watering in summer, especially here in Australia. To make sure it happens on regular basis I decided to design such a watering system.

Disclaimer

The author is not liable in any way for malfunction or damage that may occur when reproducing and using this project. Please also see the license the source code is distributed on.

Functional Description

This project consists of up to four valves and can control up to 3 sprinklers or other kinds of watering devices. It uses one extra valve in order to be more resistant against valve failure and also implements a leak check if you decide to use the water flow sensor.

The three watering devices can water up to 3 different areas of your garden. They are called area 1, area 2 and area 3 and you can configure their duration in minutes separately along with the time each day watering starts.

There are two buttons and one color LED to control/show the state of the device. The red button is used to show and switch the mode as well as switching watering off immediately. The black button starts watering and switches to the next area if it is running already.

When you press the red button in idle mode, it will first show the current mode on the color LED and then switch between the modes as follows:

  • mode off (color LED red)
  • mode on (color LED green)
  • mode off once (color LED purple)

What if you sit in your backyard with your guests and forget to switch it off? For this reason I added a warn activation of the watering devices.

When it is time to start watering, the following happens:

  • Leak check (if activated)
  • Switch area 1 on for 1 sec
  • Pause for one minute (to allow you to switch it of if you have guests..)
  • Start watering of area 1 for the given time in minutes
  • Switch area 2 on for 1 sec
  • Pause for one minute
  • Start watering of area 2 for the given time in minutes
  • Switch area 3 on for 1 sec
  • Pause for one minute
  • Start watering of area 3 for the given time in minutes

When you press the red button any time during this time, watering will stop immediately and not start anymore until the next scheduled watering. If you press the black button, it will switch to the next area.

Software Prerequisites

In order to install the sketch for this project, you obviously need the Arduino IDE installed on your PC. The sketch and some of the test sketches in the assembly section also need the libraries listed below to be installed in the Arduino IDE.

The recommended way to install them is as follows (works for all except DS3232RTC).

  • Menu Sketch->Include Library->Manage Libraries...
  • On top right in "Filter your search..." type the library's name
  • Click on it and then click "Install"

Required libraries:

Electrical Assembly

The electrical part consists mainly of Arduino Uno, DS3231 RTC, MOSFET4 board, color LED board and the two buttons.

If you are experienced with Arduino, skip the following chapters and assemble according to the image above.

Connect and Test DS3231 RTC

Put a watch battery on the DS3231 RTC board and connect it as shown in the overview image. The connections are as follows:

  • RTC PIN SDA = Arduino PIN A4 (SDA)
  • RTC PIN SCL = Arduino PIN A5 (SCL
  • RTC PIN SQW = Arduino PIN 8
  • RTC PIN GND = Breadboard GND (can also be any of Arduino GND for testing)
  • RTC PIN VCC = Breadboard VCC (5V, can also be Arduino 5V for testing)

Upload the following sketch to Arduino Uno to check if the RTC chip is connected correctly.

#include <DS3232RTC.h>    // http://github.com/JChristensen/DS3232RTC 
#include <EnableInterrupt.h> // https://github.com/GreyGnome/EnableInterrupt 
#define SLEEP_MODE SLEEP_MODE_IDLE 
#include <DeepSleepScheduler.h> // https://github.com/PRosenb/DeepSleepScheduler 
#define RTC_INT_PIN 8 
boolean alarmReceived = false; 
void setup() { 
 Serial.begin(9600); 
 Serial.println(F("Startup ------------")); 
 initRtc(); 
 setSyncProvider(RTC.get); 
 if (timeStatus() != timeSet) { 
   Serial.println(F("RTC not found")); 
 } else { 
   Serial.println(F("RTC found")); 
   Serial.println(F("Testing interrupt connection..")); 
   time_t rtcTime = now(); 
   unsigned int hours = hour(rtcTime); 
   unsigned int minutes = minute(rtcTime); 
   unsigned int seconds = second(rtcTime); 
   // trigger alarm in 5 seconds 
   seconds += 5; 
   if (seconds >= 60) { 
     seconds -= 60; 
     minutes++; 
   } 
   if (minutes >= 60) { 
     minutes -= 60; 
     hours++; 
   } 
   if (hours >= 24) { 
     hours -= 24; 
   } 
   Serial.print(F("Trigger alarm at RTC time ")); 
   Serial.print(hours); 
   Serial.print(F(":")); 
   Serial.print(minutes); 
   Serial.print(F(":")); 
   Serial.println(seconds); 
   RTC.setAlarm(ALM1_MATCH_MINUTES, seconds, minutes, hours, 0); 
   scheduler.scheduleDelayed(checkIfReceived, 10000); 
 } 
} 
void loop() { 
 scheduler.execute(); 
} 
inline void initRtc() { 
 RTC.alarmInterrupt(ALARM_1, true); 
 RTC.alarmInterrupt(ALARM_2, false); 
 // reset alarms if active 
 RTC.alarm(ALARM_1); 
 RTC.alarm(ALARM_2); 
 delay(1000); 
 pinMode(RTC_INT_PIN, INPUT_PULLUP); 
 enableInterrupt(RTC_INT_PIN, isrRtc, FALLING); 
} 
void checkIfReceived() { 
 if (!alarmReceived) { 
   Serial.println(F("Alarm not received, interrupt wire seams not okay.")); 
 } 
} 
void isrRtc() { 
 scheduler.schedule(rtcScheduled); 
} 
void rtcScheduled() { 
 alarmReceived = true; 
 Serial.println(F("Interrupt received, wire looks fine.")); 
 if (RTC.alarm(ALARM_1)) { 
   Serial.println(F("Alarm received, connection of RTC looks fine.")); 
 } else { 
   Serial.println(F("Alarm not received, something looks wrong with the RTC.")); 
 } 
} 

In Arduino IDE click on Menu Tools->Serial Monitor and check the output.

Connect and Test Color LED

The RGB color LED used in this project contains current limiting resistors on the board itself (see image above). Please make sure that's the case for the one you use too to prevent damage. If it does not have them, you need to put separate resistors.

There are different RGB color LEDs. The one I use in this project has a PIN labelled with "GND". If you use one with a PIN labelled as +, the test sketch and the production sketches need to be adjusted accordingly (see COLOR_LED_INVERTED in Constants.h).

Connect the color LED as shown in the overview image. The connections are as follows:

  • Color LED G = Arduino A0
  • Color LED R = Arduino A1
  • Color LED B = Arduino A2
  • Color LED GND = Breadboard GND (can also be any of Arduino GND for testing)

Upload the following sketch to Arduino Uno to check if the color LED is connected correctly.

#define MODE_COLOR_GREEN_PIN A0 
#define MODE_COLOR_RED_PIN A1 
#define MODE_COLOR_BLUE_PIN A2 
void setup() { 
 Serial.begin(9600); 
 pinMode(MODE_COLOR_GREEN_PIN, OUTPUT); 
 digitalWrite(MODE_COLOR_GREEN_PIN, LOW); 
 pinMode(MODE_COLOR_RED_PIN, OUTPUT); 
 digitalWrite(MODE_COLOR_RED_PIN, LOW); 
 pinMode(MODE_COLOR_BLUE_PIN, OUTPUT); 
 digitalWrite(MODE_COLOR_BLUE_PIN, LOW); 
} 
void loop() { 
 Serial.println(F("green")); 
 digitalWrite(MODE_COLOR_GREEN_PIN, HIGH); 
 delay(1000); 
 digitalWrite(MODE_COLOR_GREEN_PIN, LOW); 
 Serial.println(F("red")); 
 digitalWrite(MODE_COLOR_RED_PIN, HIGH); 
 delay(1000); 
 digitalWrite(MODE_COLOR_RED_PIN, LOW); 
 Serial.println(F("blue")); 
 digitalWrite(MODE_COLOR_BLUE_PIN, HIGH); 
 delay(1000); 
 digitalWrite(MODE_COLOR_BLUE_PIN, LOW); 
} 

In Arduino IDE click on Menu Tools->Serial Monitor and watch if the color of the LED matches the color printed on the console.

Connect and Test MOSFET4

The MOSFET4 board used in this project contains 4 IRF540 MOSFETS including all necessary parts to control them by an Arduino PIN. You can also use other MOSFETs or boards with single IRF540 on them.

Connect the MOSFET4 board as shown in the overview image. Pin S is the left pin and pin "-" is the right pin in the input connector as shown above (MOSFET4 inputs). The middle PIN is + what we do not need for this project. The connections are as follows.

  • MOSFET4 CH1 S = Arduino 4
  • MOSFET4 CH2 S = Arduino 5
  • MOSFET4 CH3 S = Arduino 6
  • MOSFET4 CH4 S = Arduino 7
  • MOSFET4 CH1 - = Breadboard GND (can also be any of Arduino GND for testing)

Upload the following sketch to Arduino Uno to check if the MOSFET4 board is connected correctly.

#define VALVE1_PIN 4 
#define VALVE2_PIN 5 
#define VALVE3_PIN 6 
#define VALVE4_PIN 7 
void setup() { 
 Serial.begin(9600); 
 pinMode(VALVE1_PIN, OUTPUT); 
 pinMode(VALVE2_PIN, OUTPUT); 
 pinMode(VALVE3_PIN, OUTPUT); 
 pinMode(VALVE4_PIN, OUTPUT); 
} 
void loop() { 
 Serial.println(F("Valve 1")); 
 digitalWrite(VALVE1_PIN, HIGH); 
 delay(1000); 
 digitalWrite(VALVE1_PIN, LOW); 
 Serial.println(F("Valve 2")); 
 digitalWrite(VALVE2_PIN, HIGH); 
 delay(1000); 
 digitalWrite(VALVE2_PIN, LOW); 
 Serial.println(F("Valve 3")); 
 digitalWrite(VALVE3_PIN, HIGH); 
 delay(1000); 
 digitalWrite(VALVE3_PIN, LOW); 
 Serial.println(F("Valve 4")); 
 digitalWrite(VALVE4_PIN, HIGH); 
 delay(1000); 
 digitalWrite(VALVE4_PIN, LOW); 
} 

You should see that the 4 LEDs on the MOSFET4 board are lighting up one after the other.

Connect and Test Buttons

Connect the black and red button as shown in the overview image. The connections are as follows:

  • Any PIN of black button = Arduino 10
  • Other PIN of black button = Breadboard GND (can also be any of Arduino GND for testing)
  • Any PIN of red button = Arduino 11
  • Other PIN of red button = Breadboard GND (can also be any of Arduino GND for testing)

Upload the following sketch to Arduino Uno to check if the buttons are connected correctly.

#include <EnableInterrupt.h> // https://github.com/GreyGnome/EnableInterrupt 
#define START_AUTOMATIC_PIN 10 
#define MODE_PIN 11 
void setup() { 
 Serial.begin(9600); 
 pinMode(START_AUTOMATIC_PIN, INPUT_PULLUP); 
 enableInterrupt(START_AUTOMATIC_PIN, isrStartAutomatic, FALLING); 
 pinMode(MODE_PIN, INPUT_PULLUP); 
 enableInterrupt(MODE_PIN, isrMode, FALLING); 
} 
void loop() { 
 // empty 
} 
void isrStartAutomatic() { 
 // only done in test, do not println in interrupt in production sketch 
 Serial.println(F("black button")); 
} 
void isrMode() { 
 // only done in test, do not println in interrupt in production sketch 
 Serial.println(F("red button")); 
} 

In Arduino IDE click on Menu Tools->Serial Monitor and watch if you see "black button" and "red button" on the console while you click the respective buttons.

Finish electrical assembly

Finally connect the water flow sensor plug and the 12V supply but do not yet connect the orange wire.

Mechanical Assembly

The mechanical part of this project consists of connectors, water flow sensor, valves and outlets. It is recommended to attach all parts until at least the first valve with threads and not with quick connectors. This means mechanically it is assembled as follows.

The order is as follows:

  • garden tap with thread
  • connector from garden tap thread to 1/2" valve
  • main valve: 1/2" male on both ends
  • connector from main valve to water meter: 1/2" female on both ends
  • water meter: 1/2" male on both ends
  • 4 way cross coupling: all threads 1/2" female
  • area 1/2/3 valve: 1/2" male on both ends
  • area 1/2/3 thread joint connector: 1/2" female to quick connector of garden houses

Connect the valves/water flow sensor:

  • main valve = mosfet4 CH1 (polarity does not matter)
  • area 1 valve = mosfet4 CH2
  • area 2 valve = mosfet4 CH3
  • area 3 valve = mosfet4 CH4
  • water flow sensor = water flow sensor plug, see water flow sensor description about what wire is VCC, GND and signal

Mount the electrical parts in an appropriate box. I recommend one with a transparent front so that the internals and the color LED can be seen.

Please double check that the box is water resistant. I used a box that is sold as water resistant but in reality it was not. As you can image, the system started to behave pretty weird, so I put a plastic foil around the front to better protect it against the rain.

Integration test

When electrical and mechanical assembly is finished you can test it as a whole.

First remove the orange connection on the overview image so that you can use the USB cable of Arduino Uno. It is important to no power the Arduino Uno through its Vin while you use USB, otherwise the USB port of the PC could get in troubles.

Configuration

  • Disconnect the orange connection you see in overview image
  • Connect Arduino Uno to your PC with its USB cable
  • Upload Main Sketch "Watering System"
  • In Arduino IDE click on Menu Tools->Serial Monitor
  • Choose 9600 Baud
  • You see initialization output in the console
  • Press h and the "enter" key
  • The console shows the available commands
  • Set the current time with d<YYYY>-<MM>-<DD>T<hh>:<mm> (24 hours day), e.g. d2017-11-11T20:00
  • Set watering time with a<hh>:<mm> (24 hours day), e.g. a21:00
  • Set zone 1 duration: wz1:<minutes, 3 digits>, e.g. wz1:010
  • Set zone 2 duration: wz2:<minutes, 3 digits>, e.g. wz2:010
  • Set zone 3 duration: wz3:<minutes, 3 digits>, e.g. wz3:010
  • Print status: s
  • Check if values and time set correctly
  • The values and time are stored in EEPROM and on the RTC chip. They are kept while powered down as long as the RTCs watch battery is present not empty

First test

  • After configuration press the red button multiple times to see if the mode switches by lighting up the color LED in the colors red, purple and green
  • Press the black button to see if the main valve and the valve of area 1 correctly release
  • Press the black button again to switch to area 2 and area 3
  • Press the red button to check if watering stops

Finish setup

  • Disconnect the PC
  • Reconnect the orange wire to power Arduino Uno with the 12V supply
  • Use the buttons to check if it all still works as expected
  • Supervise all automated and manual runs from now on to make sure no damage can occur

Videos

Below you can some some short videos to explain how to operate the watering system.

The first video shows how you can see which mode the watering system is in. In this video it lights up in green what means "Mode on".

Show Current Mode

The second video demonstrates how to switch between the three modes "Mode on", "Mode off once" and "Mode off".

Mode Switching

The following video shows how to manually start watering, switch between the three zones and turn watering off again. Note that the LED lights up in green in the end what indicates that the system is currently in state "Mode on".

Show watering and zones

..and that's how it looks for your neighbours ;-).

Automatic Watering

Code

Arduino Watering System
Software running on the Arduino Uno.

Schematics

Schematics
wateringsystem_IX37ZrM4hZ.fzz

Comments

Similar projects you might like

Arduino LIDAR

Project tutorial by abhinav

  • 3,487 views
  • 4 comments
  • 11 respects

Arduino Mega Chess

Project showcase by Sergey_Urusov

  • 1,888 views
  • 10 comments
  • 15 respects

Sprout: Modern Indoor Self Watering Planter

Project tutorial by Jonathan Pereira

  • 1,819 views
  • 2 comments
  • 11 respects

Arduino-Powered Smart Light (Works with Amazon Echo)

Project tutorial by Tinker Project

  • 4,452 views
  • 4 comments
  • 13 respects

LTE Arduino GPS Tracker + IoT Dashboard

by Timothy Woo

  • 8,141 views
  • 9 comments
  • 28 respects
Add projectSign up / Login