Automated Irrigation Project

10 posts / 0 new
Last post
Luke Moffat's picture
Luke Moffat
Status: Gold Member (Offline)
Joined: Jan 25 2014
Posts: 377
Automated Irrigation Project

Hi all,

Taking inspiration from Sand Puppy's Rainwater Collection Project I've decided to crack on with my Automated Irrigation Project and chart my progress. This initial post is more of a 'proof of concept' just to show how I've wired up my circuit along with the source code that drives it and what it actually does.

The list of components are mostly Arduino based and are readily available online should you want to build the circuit and upload the Source Code below.

The principle is rather simple; the Arduino Board counts for a set time using its internal clock before energising and taking a reading of the moisture sensor buried in the soil. If there is adequate moisture in the soil then nothing happens. If the moisture level in the soil has dropped below the required level then the system will turn on a water pump to water the plants/soil preventing them from drying out. The sensor works by trying to pass a current between its electrodes. If water is present in the soil then conduction occurs, if not then conduction doesn't occur. The Arduino Board then determines whether to turn on the water pump (Red LED in this example) based upon the sensor's value.

So what's the point of it? Why not just buy a timer and connect it to a hose? Well for that you need a constant water flow and pressure - you can't just fill up a barrel and expect it to water your plants. With this I'll be able to water plants away from current infrastructure - which is the plan. Secondly, it doesn't have the level of intelligence that I require. A timer on a hose will still water even if it has rained so I wanted to eliminate water wastage. I also intend to have it hold off its water cycle if rain is expected within the next couple of hours - but that is for later. Essentially I want an efficient, off-grid, automated watering system. Also, not mentioned in the attached video is the desire to power the battery from solar panels.

Below is a little video I've made to demonstrate how it all works;

Here is the circuit if you want to wire it up. Don't be put off by the symbols (I've just added them for completeness). Once you've got the main components it's just a matter of connecting wires, LEDs and resistors.

 

Source Code below;

Quote:
//simple circuit to see if Arduino draws enough current to
//power a relay
 
//define global terms
const int PUMP = 11; //Pump connected to digital pin 11
const int RELAY = 12; //Relay connected to digital pin 12
const int SENSOR = 0; //Sensor set to analogue pin 0
int val = 0; //store value coming from sensor
 
//setup block function
 
void setup ()
{
  pinMode(PUMP, OUTPUT); //sets the digital pin as output
  pinMode(RELAY, OUTPUT); //sets the digital pin as output
}
 
//void loop to set Relay low for ten seconds then set High - cycle
void loop ()
{
  //val = digitalRead(BUTTON); //read value of BUTTON and store it
  //if (val == HIGH)
  digitalWrite(RELAY, LOW);
  delay(500);    //delay needed to give relay time to throw
  digitalWrite(RELAY, HIGH);
  {
    val = analogRead(SENSOR); //read voltage at pin 0 and assign it
                              // a value
                              
 //if resistance across sensor is high due to little water then
 //turn on PUMP. In code, if value on A0 is less than 200 set
 //PUMP output high. Note: value is between 0 and 1054
 
 //Note: Normally Closed - Normally Open Contacts seem confused on
 //Songle relay. After testing output with LED using digitalWrite
 //(RELAY, LOW) the IN1 onboard LED lights and sets sets Normally
 //Open contact to close thus lighting up LED. removing IN1 connection
 //extinguishes IN1 LED and output LED, thus Normally Closing Relay.
 //What happens is setting RELAY to Low in the code actually powers
 //up the coil. Also, reconnecting sensor shows sensor light up on RELAY
 //LOW step. This should actually happen on RELAY HIGH step. Anyway,
 //now that I know how it should be working I can manipulate the code
 //accordingly
 
    if (val < 200)
    {
    digitalWrite(PUMP, HIGH);
    delay(3000);
    }
    else
    {
    digitalWrite(PUMP, LOW);
    }
    
  }
  digitalWrite(PUMP, LOW); //ensures pump is turned off after cycle
  delay(12000);    //delay to take power off sensor to reduce corrosion
}
 
//Code is working as intended but with the oditty of RELAY LOW function
//setting IN1 HIGH. Anyway, code is good enough to be developed further
 
//I believe code is reading relay just before it throws due to switching
//time (lines 23 - 25) which negates the oddity of LOW driving IN1 High.
//But it does what I want it to do so I'll let it slide.
 

More to follow...

Oliveoilguy's picture
Oliveoilguy
Status: Platinum Member (Offline)
Joined: Jun 29 2012
Posts: 578
Thanks Luke

Gonna require some study on my part.....but love the concept.

Thanks for the post.

sand_puppy's picture
sand_puppy
Status: Diamond Member (Offline)
Joined: Apr 13 2011
Posts: 1884
Hobbies for a simpler world

Thanks Luke,

I especially appreciate the links to specific products so that someone like me-- with little experience -- could actually hook up a similar system.

Amazingly inexpensive control system.

robshepler's picture
robshepler
Status: Silver Member (Offline)
Joined: Apr 16 2010
Posts: 108
Watering systems

I would sure plan in some redundancy should you have a system failure and parts are not available for repair.

I tend to plan our projects pretty low tech with that in mind. We are irrigating about an acre with drip tape from frost free hydrants and battery operated timers. It is all gravity fed out of our ditch. I can just close the hydrant if I expect rain. We have a 3,000 gallon tank in line for surge should we have a neighbor up line that need to irrigate, should last us a week to 10 days.

We also have about 13,000 gallons of rainwater storage that we mostly use in our high tunnel greenhouses and about 14,000 gallons of well water stored that could come into play as an emergency. It is probably over kill, but I am a guy that spent 50 years in the Sonoran desert, we just can't do anything without water.

If it can break, it will!

Plan for it.

Rob

robshepler's picture
robshepler
Status: Silver Member (Offline)
Joined: Apr 16 2010
Posts: 108
By the way...

That is really cool!

Luke Moffat's picture
Luke Moffat
Status: Gold Member (Offline)
Joined: Jan 25 2014
Posts: 377
Update of Stage 1

I've trimmed down the Source Code and reduced my waffle in the code comments so that people can focus on the actual logic if they wish to dissect it. I also noticed that I missed 'JD-VCC' off the circuit sheet so I've updated that as well;

Circuit;

 

And here is the source Code;

Quote:
//Timer cycle circuit with LED to indicate low moisture
 
//The circuit will check the state of the moisture sensor
//every 12 seconds. If the moisture level is adequate then LED
//remains unlit (pin 11 LOW) and the circuit counts for another
//12 seconds. If the moisture level is inadequate then the
//LED illuminates (pin 11 HIGH) and remains on for 3 seconds
//before the circuit continues counting for another 12 seconds.
 
//define global terms
const int LED = 11; //LED connected to digital pin 11
const int RELAY = 12; //Relay connected to digital pin 12
const int SENSOR = 0; //Sensor set to analogue pin 0
int val = 0; //store value coming from sensor
 
//setup block function
 
void setup ()
{
  pinMode(LED, OUTPUT); //sets the digital pin as output
  pinMode(RELAY, OUTPUT); //sets the digital pin as output
}
 
//void loop to set internal clock to count for 12 seconds
//before determing state of sensor
void loop ()
{
  digitalWrite(RELAY, LOW);
  delay(500);    //delay needed to give relay time to throw
  digitalWrite(RELAY, HIGH);
  {
    val = analogRead(SENSOR); //read voltage at pin 0 and assign it
                              // a value
                              
 //if resistance across sensor is high due to little water then
 //turn on LED. In code, if value on A0 is less than 200 set
 //LED output high. Note: value is between 0 and 1054
 
    if (val < 200)
    {
    digitalWrite(LED, HIGH);
    delay(3000);
    }
    else
    {
    digitalWrite(LED, LOW);
    }
    
  }
  digitalWrite(LED, LOW); //ensures LED is turned off after cycle
  delay(12000);    //delay to take power off sensor to reduce corrosion
}
 
Luke Moffat's picture
Luke Moffat
Status: Gold Member (Offline)
Joined: Jan 25 2014
Posts: 377
Stage 2
robshepler wrote:

I would sure plan in some redundancy should you have a system failure and parts are not available for repair.

If it can break, it will!

Plan for it.

Rob

Hi Rob, I couldn't agree more. I'm thinking of trying nails for the electrodes and building my own potential divider circuit to see how it performs. Also, I think the relays that I've used are actually rather complex in hindsight and standard off-the-shelf ones should work fine - to be tested later. I'll probably upload a few boards with the source code as spares in case of failure.

For the Stage 2 updates I've replaced my output LED with a pump and battery and have tested my sensor in wet soil rather than just use a glass of water.

Video demonstration below;

Circuit is now;

 

Source Code;

Quote:
//Timer cycle circuit to power PUMP if mositure level falls
//below defined threshold (sensor value less than 200 - i.e.
//1 Volt)
 
//The circuit will check the state of the moisture sensor
//every 12 seconds. If the moisture level is adequate then PUMP
//remains off (pin 11 LOW) and the circuit counts for another
//12 seconds. If the moisture level is inadequate then the
//PUMP turns on (pin 11 HIGH) and remains on for 3 seconds
//before the circuit continues counting for another 12 seconds.
 
//define global terms
const int PUMP = 11; //Pump connected to digital pin 11
const int RELAY = 12; //Relay connected to digital pin 12
const int SENSOR = 0; //Sensor set to analogue pin 0
int val = 0; //store value coming from sensor
 
//setup block function
 
void setup ()
{
  pinMode(PUMP, OUTPUT); //sets the digital pin as output
  pinMode(RELAY, OUTPUT); //sets the digital pin as output
}
 
//void loop to set Relay low for twelve seconds then set High - cycle
void loop ()
{
  //val = digitalRead(BUTTON); //read value of BUTTON and store it
  //if (val == HIGH)
  digitalWrite(RELAY, LOW);
  delay(500);    //delay needed to give relay time to throw
  digitalWrite(RELAY, HIGH);
  {
    val = analogRead(SENSOR); //read voltage at pin 0 and assign it
                              // a value
                              
 //if resistance across sensor is high due to little water then
 //turn on PUMP. In code, if value on A0 is less than 200 set
 //PUMP output high. Note: value is between 0 and 1054
 
    if (val < 200)
    {
    digitalWrite(PUMP, LOW);
    delay(3000);
    }
    else
    {
    digitalWrite(PUMP, HIGH);
    }
    
  }
  digitalWrite(PUMP, HIGH); //ensures pump is turned off after cycle
  delay(12000);    //delay to take power off sensor to reduce corrosion
}
 
//NOTE: Logic of Relay appears inverted. For some reason setting it
//LOW appears to put voltage on IN1. For this reason I've had to invert
//LOW and HIGH setting to get it to function correctly.
 
leweke1's picture
leweke1
Status: Silver Member (Offline)
Joined: Dec 18 2008
Posts: 101
Sensor corrosion

Very nicely done!  I just wonder how long it will take for the resistance measurement electrodes to corrode due to ionic electrolysis from the DC.  Would take some experimentation and might take a while but eventually could compromise the measurement integrity.

 

Luke Moffat's picture
Luke Moffat
Status: Gold Member (Offline)
Joined: Jan 25 2014
Posts: 377
Power Cycle

Hi Leweke,

To limit the effects of ionic electrolysis I only power the sensor for half a second every twelve seconds in the example. It was one of the things I was cautious of; i.e. to limit the need for spare parts due to corrosion and to save power by not having the electrodes continuously powered. When I transfer it outside I will have the circuit cycle power to the sensor every 2 - 6 hours and leave it on for about 5 seconds each cycle. With those measures in place I hope they'll last a couple of years. But yes, you're right, corrosion will eventually take its toll on the voltage sensitivity and it's something i'll have to monitor. As a replacement you can also use nails (more robust) but then you'd have to build the potential divider circuit (which should be fairly simple in all honesty).

Thanks for the interest! All the best,

Luke 

Luke Moffat's picture
Luke Moffat
Status: Gold Member (Offline)
Joined: Jan 25 2014
Posts: 377
Outdoor Connections and Functionality - Video 3

Evening all,

An update of sorts.

I've managed to assemble the system outdoors without the moisture sensor attached so that it works from a switch but isn't yet automated. This was just to see if the concept works outdoors - i.e. can I move water from the butt to the soil with the pump with sufficient pressure to generate a 'sprinkler' effect. In short the answer is 'yes'.

Here is how the setup currently looks;

How it's connected in brief;

Water is stored in the water butt and has an external tap which connects to the consumer unit (mid-right of photo attached to the wall) via a 13mm yellow hose. Inside the consumer unit is a solenoid valve which passes water from the water butt to the pump via 10mm hose (also inside the consumer unit). Water then flows from the pump back outside to the raised beds via a 10mm hose which then connects to a 2-way split feeding both yellow hoses in the beds which have been pierced using 1mm hoses to generate the 'sprinkler' effect. Both hoses are fitted with stoppers at the end to pressurise them.

Things to do moving forward;

  1. Seal the leaks at the 2-way split to maintain the pressure
  2. Connect the soil moisture sensor to make it automated
  3. Connect the solar panel to recharge the motorcycle battery
  4. Review water coverage and sensor placement

A word about the hoses and connections; I had intended to use 13mm diameter hose throughout but as the pump has 10mm connections it forced a a bit of a faff with connectors and hose attachments, perhaps getting a pump with 13mm hose connections may save a bit of money and not have the need to carry both 10mm and 13mm hose spares.

Anyway, the latest video is below;

Cheers Luke

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Login or Register to post comments