I'm keeping this post updated to reflect some changes I've made based on the comments posted by other users below. Last update: March 07, 2013
https://docs.google.com/file/d/0B5-HND9 ... sp=sharing
I’m not going to cover the software/programming side of things because I am a Linux/Python/Bash newb, and I will leave that to others more qualified. I am also still experimenting with different methods to find what works best for me. This write-up also assumes that you possess a little basic electronics knowledge (like how to solder, etc).
Although I do have a dusty degree in EET, it’s been 15 years since I’ve done anything like this, so If anyone spots some egregious errors on my part, please correct me.
What you’ll need/What I used:
- Raspberry Pi Model B (Rev 2.0)
- Sainsmart 8-channel DC 5V Relay Module (Got mine for $12 on Amazon)
- Some jumper wires. I used some 5” ones and some 3” ones from Radio Shack:
5”: http://www.radioshack.com/product/index ... d=16637366
3”: http://www.radioshack.com/product/index ... d=12825859
* These also come with header pins which I used.
** The product descriptions say 10.3” and 10.5”, but the 10 is quantity... confusing.
- +5V power supply.
The Raspberry pi requires up to about 500mA, and each relay requires about 72mA (total: ~1.1A for 8 relays), so be sure to chose a supply capable of 1.5A or more to leave a little headroom.
- 2.2k ohm +/-5% resistors (color code: Red red red - gold).
You’ll need one for each relay you plan to operate.
- 10k ohm +/-5% resistors (color code: Brown Black Orange - Gold).
You'll need one for each relay you plan to operate.
- Some NPN transistors. I used some 2N222’s from Radio Shack (bag of 15 for $3.49).
You’ll need one for each relay.
http://www.radioshack.com/product/index ... Id=2062586
- A small project circuit board. I used one from Radio Shack like this:
http://www.radioshack.com/product/index ... Id=2102845
- A terminal/barrier strip like this (not shown in photo):
http://www.radioshack.com/product/index ... Id=2103982
I cut the small plug off the end of the power supply leads, stripped the wires, and added some crimp-on spade connectors to attach them to the barrier strip. This will allow me to remove the power supply if necessary. I will also connect the 24V sprinkler supply to this barrier strip.
- The diagram only shows 4 GPIO pins connected to the relay module... that’s just because I am only using 4... connecting additional pins/relays would work exactly the same way.
- I opted to not use the micro-USB port to supply power to the Pi, and instead soldered some header pins to TP1 and TP2 to provide +5V and GND respectively. This avoided having to cut/splice a USB cable and made for cleaner wiring. The header pins came with some jumper leads I bought at Radio Shack that I used to make all the connections. The header pins are a pain to solder if you're only doing one at a time. I had a spare 5V 2.0Amp Wall-wart charger laying around, so I used that to power everything instead of having a supply for the RPi, a supply for the relay module, and another supply for the sprinkler valves.
- I used +5V to power the relays and the opto isolators by connecting 5V from the supply to VCC on the 10-pin header and then using the supplied jumper between VCC and JDVCC on the 3-pin header.
- On the relay board, there are two VCC pins and two GND pins. The VCC pins are electrically identical, as are the GND pins, so you only need to connect to one (each) of them.
- !!!!!!! GPIO pins are slightly different on Rev 1.0 and Rev 2.0 boards !!!!!!! Also, there are different numbering schemes depending on which programming library you plan to use to control the GPIO pins (Either BCM or Wiring Pi).
- The Sainsmart relays are "active low", which means that instead of turning on when they get a 3.3V signal from a GPIO port, they turn off... This is contrary to what you would think (or would want). In any event, you need a way to translate the high (3.3V) output of the GPIO pin to 0V for each input of the relay board. This is done using a 2.2kohm resistor and an NPN transistor. I used 2N222 transistors from Radio Shack (got 15 of them for ~$3.50 US). A voltage at the base of the transistor effectively shorts the relay input to ground (0V) turning the relay on.
- Each relay has 3 terminals which I’ve labeled A, B, and C in the diagram. While “active”, each relays’ A and B terminals are connected, and while “inactive”, B and C are connected. A and C are never electrically connected. For a sprinkler system, you would probably want to connect +24V (or whatever voltage your sprinkler valves/whatever require) to each “A” terminal, and then connect the lead for each sprinkler zone to the “B” terminal. You will also need to connect the common wire of your sprinkler wiring to the ground terminal of your 24V supply.
- I used the long traces in the middle of the project circuit board as power/ground busses, although that’s not shown in the diagram. I grounded the emitters of the transistors to the ground bus. I also soldered some header pins to the busses as a means of distributing power to the RPi and Relay Module.