For this project, I have used:
If you're considering this yourself, a word of warning
This probably won't save you money. It may not even save your garden.
For me, excluding the cost of the Pi and Grove (which I already had) the total cost of this experiment has probably been about $180AUD allowing $150 for plumbing supplies, $30 for additional power boards, ethernet cables etc. This actually isn't insane given that it will easily cost about $100 to buy a controller at your hardware shop and then you'll have to hand over more for solenoids, pipes, wires etc.
For me, the most important thing I've learnt through this project is the consequences actions can have when you move from the digital world into the real world. Most web developers and designers play in a world where the worst that can happen to them personally as a result of a failure in their decisions is that they get less conversions on a transactions, or their site goes offline for a few hours.
In this project, making a mistake could cost me my garden (which could die or be drowned) or damage the foundations of my house (if the manifold or pipes burst and spew water out, underneath my house, for days while I'm away from home).
Still, I'd recommend this regardless. It's been great fun. I hope if you do go down the automation route that this helps in some way.
This document is broken into four sections for easy reference, and the code is really simple. I'll try and keep the software concerns seperate as I build this project out over time so you can pick it up and use what you need without needing to understand lots of complicated code. I'll also try and remember to comment lots so it's easy to understand. Thank you to all the other open source projects that do this also! It's only because of the forethought and generosity of time others have given that I've been able to learn how to do any of this.
Using my existing watering system, essentially my goal was to create an intelligent hub through which the water flowed when I wanted to.
To do this, the mains water goes into the manifold, where it is then stopped by the solenoids. When the solenoid is opened by the relays attached to the RPi, the water flows. By default, the relays are closed and take electric current to keep them open. This works for me because it means that in the event of a power-failure I won't flood my house.
Once I had this all assembled, I set up a
cron job to trigger my watering system on and off for a minute at a time in order to pressure test and rock/jerk the system around a bit. Turning water one and off with a solenoid is quite a violent process (you'll hear it - there is quite a bit of pressure involved in mains water) and I think this is what caused my first iteration to fail. Turning it on and off rapidly means you get to i) see if it leaks and ii) hopefully accelerate any failure so you can fix it before you come to rely on it working properly.
From an electronics perspective, it took me a while to figure out what was needed. Thanks to by Grove Pi kit, I had a relay, but just no real idea how to use it. Also no idea how to avoid electrocute myself.
Enter many hours of youtube research and videos.
Through this research I found that I'd need to do the following:
Because water is being used in close proximity to electricity here, I wouldn't recommend doing this unless you felt pretty confident in your knowledge. There are a few things I did to keep myself safe.
Putting it all together I ended up with a situation like this. Here you can see:
For me there were are a few challenges I have/will faced in this project.
To help myself overcome some of these issues, I've broken the challenge down into some smaller steps to knock over one at a time. I'll keep this list updated as I go.
nminutes" and actually have that work…because we live in the future (also gives me a good reason to buy said assistant)
This was easy. I managed to do this using a built in Python script provided by the GrovePi Software
This was also achievable using a modified version of the script. Basically, adjusting the sleep duration after turning the Relay "On" was enough to make this work.
- Set up a cronjob to run every
Ruby (scheduling, APIs)
Time.now.min using Ruby.
Min are within a target range at the time of checking, run a python script.
- Run an
on script for a
period of time. This would run for n minutes and then turn off. Eventually, I could probably set
n using the duration of a google calendar item.
- Close the script and python.
System - Restart
This would let me run most of the logic in ruby and only dive into Python when I need to toggle the systems on or off.
Got this working quite easily and much like the above.
I did run into a small issue whereby the Seed grove that I was using the control the relay would error and display a red RST light. Reading on the forums this is a relatively common issue with the board.
Apart from disconnecting the power, the only solution to the issue is to run a reset command for the board, which I've now put into a seperate ruby script so I can run it when I need to.
Another issue I've come across is that while the script seems to work all of the time, occasionally, the solenoid does not work. I'm not sure what could be causing this. It's either that the relay is not closing properly or that the solenoid isn't working. Potentially this could be to do with the mechanical components within the solenoid not making contact correctly, and therefore the solenoid circuit not being completed. Strangely it does not happen every time though.
The crontab is pretty simple. Every hour, at 5 minutes past the hour, run the
schedule.rb file. If the hour is correct, run the
water.py script for the length of time provided in the original command parameter (in this case, 1800 seconds, or 30 minutes).
5 * * * * ruby /home/pi/Projects/garden/scheduler.rb 1800 >> /tmp/cron_output
Eventually I'll need to expand this to allow for more parameters - for example, zones (-z) or time (-t).
Success. After assembling the solenoids, pi and watering systems, rewiring my shed with additional ethernet cables and bashing a hole through the tin side of my shed with a back-hoe, I've had my first successful test firing. I've been able to control the flow of water in my back garden safely using the internet! What a time to be alive. The joy, the wonder. Amaze.
The issue I found before whereby the solenoid would not fire has also seemingly resolved itself. Perhaps the solenoids work differently under pressure from the water than they do without this. Interesting.
My script also checks the time correctly in production, which is great.
My first trial only includes a single bed and I need one more relay before I can move onto the second step - controlling more than one zone. It's all wired up though, so should just be a question of ordering a few more relays (I suspect I want to move onto my garden lights next). I suspect the limiting factor for my beds will end up being water pressure. I also may need additional zones to cater to the fact that some plants need more water (usually vegetables) and some less (usually flowers and natives).
Just before leaving, I was showing @arcarson went to look at the system and found that the three way manifold I'd created from poly pipe (leading from the mains and to the solenoids) had failed. This was due to the fact that the hoses before the manifold had popped off the valve due to the mains pressure. I was very glad this happened as it showed that my initial plumbing design had been flawed…if it hadn't failed when it did, my shed would've become even more flooded (the plastic box well and was overflowing with water when I found it).
I replaced the failed-manifold with one that was far better constructed, as well as the various connectors. This added $100 to the cost, but now I'm relatively confident that it won't burst again. I just need to remember to drain the irrigation system before winter sets in (and the pipes potentially freeze).
Note: Hardware list above has been updated.
After being away at the beach for a week with only as neighbour to check on the system, I've returned home and there is neither water leaking everywhere or a dry garden. The system worked. Although I initially had the system watering for 1 hour at 5am, I decided to change this to 30 minutes.
The logs I set up were also of great use. I was able to check each morning to make sure that, at least according to the logs, the system had turned off each morning.