How to control Sprinkler system with a Raspberry Pi
I decided to take some time off this week to work around the house and finish things I have neglected at home. We have one area of our yard that has underground sprinklers, but they need to be manually turned on. This is because it is difficult to get a wire to the controller – it would require a significant amount of drilling through brick and concrete. I keep forgetting to water this part, and all the plants start to wilt – I wanted it automatic like the rest of the yard.
Step 1: keep the rain out
I could have purchased one of these…a simple timer based valve:
What fun would that be?
My only orders from the boss (wife) were “If you could get that part of the yard on the sprinkler system, that would be great.”
I had a Raspberry pi sitting around (I bought one a few months back to play with). I knew there had to be a way to use it in this project.
The PI is a small computer about the size of a pack of cigarettes. It runs Linux, and you can even hook it up to a keyboard, mouse, monitor and use it as a desktop computer.
I thought it would be a fun little project to sharpen up my Linux chops, and do something geeky over my vacation. Somehow I was going to put that Raspberry Pi in my yard, and have it control my sprinklers.
Luckily there is a outdoor power outlet right near the sprinkler valve. This would be a perfect place to put it.
My first worry was how I could keep the rain out. I dug through my basement and found a outdoor network control box from my contracting days:
Then I took some standoffs from an old computer case, and screwed them at the right positions for the Raspberry PI board:
Later, I did the same for the other supporting boards (Relay, and power converter)
Step 2: Switch the valve
Next step..how would I switch the valve? The sprinkler valves use 24VAC and a relay would be a perfect fit for this.
I found a relay board on Amazon that is made for the PI:
Under $10 – great price.
Now I had to hook it up to my Raspberry PI. To do that I connected the IO lines to the relay inputs, and then ran the +5VDC and ground from the PI.
I had gotten this far, so I wanted to test to see if I could activate the relay.
This took a few more steps than I thought, but really it is easy.
First you need to export the interface you want to use. I was using GPIO port 4.
This is the command I used to do that:
echo “4″ > /sys/class/gpio/export
Then the PI needs to know if it is for input or output.
I sent this to tell it I was going to use it for output:
echo “out” > /sys/class/gpio/gpio4/direction
Now I was ready to turn it on and off
Sending a 1 will turn it on:
echo “1″ > /sys/class/gpio/gpio4alue
And a zero will turn it off:
echo “0″ > /sys/class/gpio/gpio4alue
After some messing around with my wiring I finally got it to work. I could hear the relay clicking when I switched it on and off. Yea!
Now I had to hook it up to my Raspberry PI. To do that I connected the IO lines to the relay inputs, and then ran the +5VDC and ground from the PI.
I had gotten this far, so I wanted to test to see if I could activate the relay.
This took a few more steps than I thought, but really it is easy.
First you need to export the interface you want to use. I was using GPIO port 4.
This is the command I used to do that:
echo “4″ > /sys/class/gpio/export
Then the PI needs to know if it is for input or output.
I sent this to tell it I was going to use it for output:
echo “out” > /sys/class/gpio/gpio4/direction
Now I was ready to turn it on and off
Sending a 1 will turn it on:
echo “1″ > /sys/class/gpio/gpio4alue
And a zero will turn it off:
echo “0″ > /sys/class/gpio/gpio4alue
After some messing around with my wiring I finally got it to work. I could hear the relay clicking when I switched it on and off. Yea!
Step 3: Use an off the shelf cigarette lighter plug
Hmm…but now I had a problem. I did not have a 24VAC power adapter for the valve. I would have to go buy one. I hate when that happens.
Then I remembered I had done this before.
Back in 1988 I was just a kid living at home with my parents. I had my own garden in the back yard, and needed an automated system to water the plants (Since we were about to leave for a week on Vacation). In that project I used a Commodore 64, a few transistors, and an automotive relay. The important part is I used 12 VDC to activate that sprinkler valve. The valves have not changed much over the years. That same valve back from the 80s says it requires 24VAC
So I wondered…could I use 12VCD instead for the sprinkler valve I had in my yard? I pulled a scrap power plug rated for 2A at 12VDC and put the wires across the valve. Click..I could hear the solenoid activate!
I had another reason for liking 12 volts for my supply. It would allow me to use an off the shelf cigarette lighter plug to convert that 12VDC to 5VDC that the PI needed to operate.
That was my next step. I bought a $6 USB adapter for the car:
I broke it out of its case and soldered some wires on the input and output. On the 5V side I connected a mini USB adapter…from that same plug – just really short. On the 12V side I connected some wires to share with the valve.
Here is what it looks like with the relays, the power converter, and the PI all put together:
Step 4: Add a wireless USB
The last step was to add a wireless USB. This would allow me to tinker with it from the house, and setup the schedule using a cron job.
I got this one from amazon. Another good buy – under $10. It worked right out of the box with the PI.
I mounted my box to a piece of scrap wood, and hid it behind the plants:
So far it has been working for a week now with no issues. Every once and a while I SSH into it and start poking around my Linux box running in my front yard
Mar 20,2015
2,335 viewsReport item
- Comments(3)
- Likes(1)
Upload photo
You can only upload 5 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000