For this project i used the following:
Note: If I changed out the solenoids for 12VDC operation (this was an expensive option) and changed the power source for the Raspberry Pi to a cannibalised 12VDC car charger, the whole system could run off grid with solar power.
Setting up the Raspberry Pi and mounting it in an old PSU case that had failed made a nice secure enclosure that would keep hands away from the primary side of the transformer that would have 240VAC live on it. (Safety first).
To power the raspberry pi I utilised a spare phone charger and wired this directly to the 240VAC available on the inside of the PSU chassis, This PSU also had a switch which cam in handy.
To control the relays I utilised the Wiring Pi library allowing command line control of the GPIO pins.
git clone git://git.drogon.net/wiringPi
With the Wiring Pi library installed we can now control the state of the GPIO pins from the command line.
gpio write 0 1
This will bring GPIO pin 0 high which is connected to relay 0, (note that the relays were active low, so to turn on when the GPIO pins are low not high)
To automate the control of the valves a simple bash script scheduled via crontab was all that was needed to automate the watering of the garden.
gpio mode 0 out
gpio mode 1 out
gpio write 0 0 # Relay>On active low
sleep 300s # time out 5 minutes
gpio write 0 1 # Relay>Off
echo "Watering Garden Complete 5 minutes"
gpio write 1 0 # Relay>On
sleep 300s # time out 5m
gpio write 1 1 # Relay>Off
echo "Watering Shrubs Complete 5 minutes"
Below is a youtube video of the relays and raspberry pi in operation while mounted in the PSU chassis.
With no hose immediately available at my vegetable garden, I set about setting up a pair of 1000ltr water tanks to catch rain water off the garage roof. The garage is in close proximity to the garden and a perfect option for getting water available close by.
Next task running the irrigation pipes and setting up the spray jets, mounting the pump under the water tanks and connecting it all up.
Too operate the solenoid valves required 24VAC, Relays 0 and 1 were then connected to 2 solenoids and supplied 24VAC from the step down transformer. The water pump had a pressure switch that would turn off when the pressure built up (i.e. when the valves were closed) There was no need to connect the 12V pump via a relay and was connected directly to the 12 car battery. The solar panel was utilised to charge the car battery via a solar charge controller.
With everything in place it was just a case of testing and adjusting the water jets.
Watering the garden and shrubs at 6am every day using cron.
# m h dom mon dow command
00 06 * * * ./water.sh
2015-10-09 Update, now controllable via a web page to control from anywhere, This is for another day.