How to wire a Raspberry Pi to a Sainsmart 5v Relay Board


61 posts   Page 1 of 3   1, 2, 3
by mchlwllmthms » Wed Mar 06, 2013 6:23 pm
Okay, I tore my hair out trying to get this information for myself. Now that I've got it figured out, I thought I would share a diagram I made of my setup and some other information in hopes that it may help someone else get it sorted out. Again, this is a diagram of how I have wired up my Raspberry Pi (Model B, Rev 2.0) to a Sainsmart 8-channel 5V Relay Board. This project was specifically done for controlling my sprinkler zones which require 24V.

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

Diagram:
Image

Diagram (pdf):
https://docs.google.com/file/d/0B5-HND9HJkXWSTQtYlFTZ3VyODA/edit?usp=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:


Things to note:

  • 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.
Anyways, that's about it. Hope this helps someone, and if you have anything to add, post up!

-Mike
Last edited by mchlwllmthms on Sun Dec 01, 2013 11:13 pm, edited 2 times in total.
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by pjc123 » Wed Mar 06, 2013 9:33 pm
Interesting, I have a very similar setup, but I was not able to reliably trigger the optos with 3.3V, and had to use 5V. Are you sure that your relays are all clicking consistently, because that is the problem that I ran into; sometimes they would trip, other times not, still other times a barely audible click? I didn't notice it at first until I tried all 8 relays. If they work OK, then there must have been a design change done on the relay board, or the only other difference I can think of is that I am using a Rev 1 board, but that should not matter. Could you measure or read the number value of the opto resistor (R1 for example) and the part number on the opto? Also, could you measure the current flow through that part of the circuitry (measured at the collector of the transistor)? I would be very interested in knowing.

One improvement that I made over yours (recommendation from Gordon on this forum) is that I added a 10K resistor as follows, because the GPIO can be in a floating state and this pulls it low so you are in a know state, and the circuit will not trigger accidentally.

relay2.png
relay2.png (18.5 KiB) Viewed 119691 times


By the way, My EET degree is 25 years old so I may have you beat :D
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by mchlwllmthms » Wed Mar 06, 2013 9:54 pm
pjc123 wrote:Are you sure that your relays are all clicking consistently, because that is the problem that I ran into; sometimes they would trip, other times not, still other times a barely audible click?


No issues that I've encountered with that. They all seem to activate just fine. If it's an issue for others, I would recommend using +5V from the power supply for the VCC and JDVCC.

pjc123 wrote:Could you measure or read the number value of the opto resistor (R1 for example) and the part number on the opto? Also, could you measure the current flow through that part of the circuitry (measured at the collector of the transistor)?


I will do this when I get home.

pjc123 wrote:One improvement that I made over yours (recommendation from Gordon on this forum) is that I added a 10K resistor as follows, because the GPIO can be in a floating state and this pulls it low so you are in a know state, and the circuit will not trigger accidentally.


The Pi, the relay module, and the circuit board with the transistors are all grounded together, so that shouldn't be an unknown state... it's 3.3V from ground. If you were using two separate power supplies for the pi and the relay board, I could see how that may be an issue. Unless there's something I'm missing, that shouldn't be necessary.
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by pjc123 » Wed Mar 06, 2013 10:37 pm
mchlwllmthms wrote:The Pi, the relay module, and the circuit board with the transistors are all grounded together, so that shouldn't be an unknown state... it's 3.3V from ground. If you were using two separate power supplies for the pi and the relay board, I could see how that may be an issue. Unless there's something I'm missing, that shouldn't be necessary.



The problem is with the boot up state, as I believe Gordon has stated correctly:

"I'd be careful here - if you reboot the Pi, the GPIOs will default to inputs and unless the internal pull-up/down resistors are activated (they are "remembered" over a power cycle) the input pins are effectively floating, so stray capacitance could drive the transistors you're using and enable a relay. This may have unintended consequences. I'd be tempted to stick a 10K resistor to 0v at the gpio pin, or enable the internal pull-down resistors (Which are also 10K IIRC)."

Perhaps it does not matter in your application, but it is imperative in my project that the GPIO pins are in a known state at boot, namely a low condition.

Also, several pins are actually set to outputs during boot, for example UART TXD, so I am very careful not to select any of those pins as well. On the Rev 1 board, GPIO ports (not physical pins) 0, 1, 7, 8, 14 and 15 are all outputting 3.3 volts (or "HIGH") at boot. All other GPIO ports at boot are not "HIGH". Actually I use UART TXD for a different purpose, it indicates when the pi is on or off, so I have an LED hooked up to it on the outside of my chassis.
Last edited by pjc123 on Thu Mar 07, 2013 12:25 am, edited 1 time in total.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by pjc123 » Thu Mar 07, 2013 12:05 am
Also,

mchlwllmthms wrote: +5V power supply.
The Raspberry pi requires up to about 500mA, and each relay requires 15-20mA (total: ~660mA), so be sure to chose a supply capable of 1A or more to leave a little headroom


The 15-20ma spec for this device is a typo as noted below, unless this changed with your board as well:

Using a 5V supply for the opto circuit:
The opto circuit draws about 1.5ma.

Using a 3.3V supply for the opto circuit:
The opto circuit draws only about 0.49ma, causing problems activating the opto in my experience. Even grounding the relay board input pins without the transistor still causes problems.

In addition to this, each relay coil draws about 60ma.

Total current draw with all relays on (with a 5v supply for both VCC and JD-VCC) is (60ma x8) + (1.5ma x 8) = 492ma. This is in addition to the current required to operate the pi. Thus, if you need to operate all the relays simultaneously, you need an external power supply connected to JD-VCC to drive all 8 coils at the same time, separate from the pi's power supply connected to VCC which will easily drive all 8 optos at the same time, especially if you have multiple devices plugged into the usb ports drawing current.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by mchlwllmthms » Thu Mar 07, 2013 5:48 pm
Okay, took some current measurements and played with the configuration a little.

As I said, I have no problem activating relays using 3.3v for the VCC, but after playing around a bit, I found that the relays seem to engage more solidly using 5V (either from GPIO or direct from the supply), and the LED's are brighter, so I plan to run the VCC with 5V directly from the supply and jumper between VCC and JDVCC.

You are correct about adding a resistor to pull the GPIO voltage down. When I turn on the cluster, one of the relays that I'm using is consistently activated during boot, but only for half a second or so (which isn't a big deal for a sprinkler system, but might as well do things right).

So, current at the collector of the NPN transistors is consistently between 2.17mA and 2.2mA, regardless of whether I'm using 3.3V or 5V for the VCC.

I also measured current at JD-VCC under two different configurations:

+5V JDVCC and +3.3V VCC:
1 relay active: 43.6mA
4 relays active: 171.4mA
So, total current draw (for the relay module in this configuration) should be around 343mA

+5V JDVCC and +5V VCC (jumpered, 5V direct from supply, not GPIO)
1 relay active: 71.5mA
4 relays active: 280mA
So, total current draw (for 8 active relays using this setup) should be close to 560mA

so, clearly that 15-20mA spec is crap.

I forgot to get the opto P/N and resistor value for you, I'll try and get that for you this evening.

Anyways, I plan on updating the information in my original post/diagram to include the 10k pull-down resistor and nix the 3.3v VCC in favor of a jumpered +5V configuration.

Thanks for your help! If there's anything else I've missed, let me know!

-Mike
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by joan » Thu Mar 07, 2013 5:54 pm
The only concern I would have is that a VCC of 5V might get fed back to the 3V3 gpio.
User avatar
Posts: 11168
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by pjc123 » Thu Mar 07, 2013 8:01 pm
mchlwllmthms wrote:So, current at the collector of the NPN transistors is consistently between 2.17mA and 2.2mA, regardless of whether I'm using 3.3V or 5V for the VCC.
-Mike


Thanks for getting that. You are indeed seeing higher current flow than me, in both cases a matter of fact.

mchlwllmthms wrote:I forgot to get the opto P/N and resistor value for you, I'll try and get that for you this evening.
-Mike


Whenever you get a chance. It has to be a change in either those things (or external indicator LED), or the quality and/or parts binning of the opto.

mchlwllmthms wrote:Thanks for your help! If there's anything else I've missed, let me know!
-Mike


Glad I could help. My setup is the same and has been running for 8 months, so you are good to go. By the way, there are quite a few trolls with regards to this board. People that have never owned one, others with incorrect and/or dangerous advice, etc. One of the big problems that I have seen over time, and that adds to the confusion, is that there are copies of this board with minor differences, so what applies to one board may not apply to another. Sainsmart itself has a myriad of different relay board configurations.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by darkcape » Fri Mar 15, 2013 7:20 pm
Thanks so much for posting this it is exactly what I was looking for. I do have one question through couldn't all the grounds go through the Raspberry Pi gpio 6? Not an electronic guru by any means but I think this would clean up my bread board a bit. or is it needed because of the TP1 connection? and along the line of the TP1 for 5V is this used to not leach too much power from the Pi? or could we also use gpio 2 instead?

Sorry if these are basic questions still trying to learn basic electronic design.
Posts: 1
Joined: Fri Mar 15, 2013 7:06 pm
by mchlwllmthms » Fri Mar 15, 2013 9:05 pm
darkcape wrote:Thanks so much for posting this it is exactly what I was looking for. I do have one question through couldn't all the grounds go through the Raspberry Pi gpio 6? Not an electronic guru by any means but I think this would clean up my bread board a bit. or is it needed because of the TP1 connection? and along the line of the TP1 for 5V is this used to not leach too much power from the Pi? or could we also use gpio 2 instead?

Sorry if these are basic questions still trying to learn basic electronic design.


Great, glad this helps... I had the same "basic questions" when I embarked on this project, that's why I thought this post might help someone!

One thing to note is that you can wire the GPIO ports directly to the relay board if you don't want to bother with the transistors, but it means that a 1 (high value) on a GPIO port will turn a relay off and a low value will turn the relay on which is counter-intuitive. You would probably still want the 10k resistors in there somewhere though. I just found it easier to do it this way instead of having to transpose my 1's and 0's when it comes to programming.

You should be able to ground through the GPIO if you want. However, I'm lead to believe that while you CAN supply power to the pi via the GPIO +5V pin, it lacks some of the circuit overload protection that is present in the micro-USB port/TP1 portion of the circuit. I can't confirm this, I played it safe. For me, using TP1 was purely about not wanting to use a the micro USB port for power because it meant not having to splice a USB cord into the power supply. This is cleaner and, in my opinion, a little more robust than the flimsy wires in a USB cable.
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by phillip71newman » Sun Mar 17, 2013 11:54 am
You should be able to ground through the GPIO if you want. However, I'm lead to believe that while you CAN supply power to the pi via the GPIO +5V pin, it lacks some of the circuit overload protection that is present in the micro-USB port/TP1 portion of the circuit.


I believe that you have indeed bypassed the built in fuse in any case. If you look at the micro USB connector, pin 1 (5V) is directly connected to the one side of the fuse if you follow the tracks carefully. The measurement across the fuse is 0.2 Ohms. I also measured 0.2 Ohms between TP1 and pin 1(5V) of the micro USB port (and I did zero my multi meter to eliminate any zero-offset errors). This leads me to believe that you have bypassed the fuse and no longer have fused protection! Furthermore I get zero Ohms between TP2 and pin 5 (GND) of the micro USB port which seems ok. By the way thanks for your post. Very interesting and informative.
Posts: 2
Joined: Fri Mar 15, 2013 7:44 pm
by pjc123 » Sun Mar 17, 2013 2:21 pm
phillip71newman wrote:
You should be able to ground through the GPIO if you want. However, I'm lead to believe that while you CAN supply power to the pi via the GPIO +5V pin, it lacks some of the circuit overload protection that is present in the micro-USB port/TP1 portion of the circuit.


I believe that you have indeed bypassed the built in fuse in any case. If you look at the micro USB connector, pin 1 (5V) is directly connected to the one side of the fuse if you follow the tracks carefully. The measurement across the fuse is 0.2 Ohms. I also measured 0.2 Ohms between TP1 and pin 1(5V) of the micro USB port (and I did zero my multi meter to eliminate any zero-offset errors). This leads me to believe that you have bypassed the fuse and no longer have fused protection! Furthermore I get zero Ohms between TP2 and pin 5 (GND) of the micro USB port which seems ok. By the way thanks for your post. Very interesting and informative.


You are absolutely correct, and by the way, no need to measure. The schematic says it all. Here are some schematic snippets:

http://raspberrypi.stackexchange.com/qu ... h-the-gpio

That is why I would never power the pi through the GPIO header, or test points (TP1, TP2), or upper/lower USB ports as you are completely bypassing the main fuse using any of those methods. Of course you could supply your own fuse if you wanted to as an option, as long as you don't create a short between the fuse and the board.

I use the normal micro-usb power port to supply 5V power to the pi and use the GPIO header to supply both 5V and 3.3V power to my other circuits including the relay card. Since the max current available from the 3.3v line is 50ma (whose circuit is fed from the 5V line) I have a separate much smaller value fuse for that, as damage would occur to the 3.3V line way before the 5V fuse would ever trip. Actually I have three fast-blow pc mount fuses on my external circuit board to protect the 3.3v and 5v lines of the pi as well as my external 5v power supply, that will trip way before the pi or my external power supply would even detect a problem. That way I never have to worry about damaging anything.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by mchlwllmthms » Mon Mar 18, 2013 3:33 pm
pjc123 wrote:
phillip71newman wrote:
You should be able to ground through the GPIO if you want. However, I'm lead to believe that while you CAN supply power to the pi via the GPIO +5V pin, it lacks some of the circuit overload protection that is present in the micro-USB port/TP1 portion of the circuit.


I believe that you have indeed bypassed the built in fuse in any case. If you look at the micro USB connector, pin 1 (5V) is directly connected to the one side of the fuse if you follow the tracks carefully. The measurement across the fuse is 0.2 Ohms. I also measured 0.2 Ohms between TP1 and pin 1(5V) of the micro USB port (and I did zero my multi meter to eliminate any zero-offset errors). This leads me to believe that you have bypassed the fuse and no longer have fused protection! Furthermore I get zero Ohms between TP2 and pin 5 (GND) of the micro USB port which seems ok. By the way thanks for your post. Very interesting and informative.


You are absolutely correct, and by the way, no need to measure. The schematic says it all. Here are some schematic snippets [...]


Thanks for the clarification. I will need to add a fuse to my circuit. Do you know the exact value of the fuse?
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by pjc123 » Mon Mar 18, 2013 4:16 pm
mchlwllmthms wrote:Thanks for the clarification. I will need to add a fuse to my circuit. Do you know the exact value of the fuse?


According to the schematic, the main fuse F3 is a 6V 1.1 Amp polyfuse. If you want to also add a separate smaller fuse just on the line to the relay card, you would have to measure the current with all relays active and add a buffer amount for relay card variation and to prevent false trips.

It is up to you since it is your project, but since other people (many new to electronics) will be viewing this, I would just show the +5V and GND wiring being taken from the GPIO header pin to the relay card and transistor circuit instead of from the test points. The added complication of soldering wires to the test points just risks damaging the pi.

By the way, nice drawing. I have been wanting to do that for a while but couldn't get around to it.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by pjc123 » Tue Mar 19, 2013 11:57 am
As a side note, I also came across this on the wiki:

"Model B Hardware Revision 2.0 and Revision 1.0 with ECN0001 change This had the polyfuses removed, removing the 100 mA current limitation for each USB port (but leaving the main fuse F3 intact). Users should still ensure their power supply can power the Raspberry Pi and the USB peripherals. Revision 2.0 was released in August 2012. Warning: Because the polyfuses have been removed, back feeding of the PI, by applying power via its normal USB output, can damage D 17 if triggered by an over-voltage, and so lead to consequential over-heating. This can be discovered by melts, scorching, smoke or worse."

A look at the schematic shows that this applies to any method where you are backfeeding and bypassing the main fuse (TP1/TP2, two USB ports, or GPIO header).
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by klricks » Tue Mar 19, 2013 1:51 pm
pjc123 wrote:
mchlwllmthms wrote:Thanks for the clarification. I will need to add a fuse to my circuit. Do you know the exact value of the fuse?


According to the schematic, the main fuse F3 is a 6V 1.1 Amp polyfuse. If you want to also add a separate smaller fuse just on the line to the relay card, you would have to measure the current with all relays active and add a buffer amount for relay card variation and to prevent false trips.

It is up to you since it is your project, but since other people (many new to electronics) will be viewing this, I would just show the +5V and GND wiring being taken from the GPIO header pin to the relay card and transistor circuit instead of from the test points. The added complication of soldering wires to the test points just risks damaging the pi.

By the way, nice drawing. I have been wanting to do that for a while but couldn't get around to it.


The 1.1A is the trip current. The hold current is lower. I think I read that it is 700mA or so?
This means the fuse can handle currents up to the hold current. Currents between the hold and trip is undefined. Resistance begins to increase then it may or may not trip. Currents above the trip will instantly trip similar to a standard fuse.
My HDMI to VGA adapter & WIFI were drawing about 820mA and kept tripping F3 after a few minutes.
Go here for my RPi writeup. Basic config, Serial Port add-on etc:
http://blackeagle12.net/Comp/RPi/Rpi.html Click web icon on right side --->
Posts: 3473
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
by JohnDee » Tue Mar 19, 2013 2:02 pm
Instead of your interfacing board via transistors and resistors, I'm trying to control the relay board using an Ciseco's Slice of PI/O (see http://tinyurl.com/bjh3chu ) to run an I2C bus hoping that this may provide an extra level of protection for my beloved Rasp Pi. (I've got the I2C bus up and working, Ok. 'Just need to fathom how to use it).

I've connected a pin labelled 5V from the middle of the Slice of PI/O - see http://tinyurl.com/csa6tzx - in order to power the relay board (but I'm not sure if that's an input or output voltage pin on the Slice of PI/O :roll: ).

I also connected one of the Slice of PI/O's IO GND pins to the relay board's GND.

I'm currently powering the Ras Pi through the microUSB with a USB 2A USB power supply.

Does this sound OK? Am I missing any other issues?

And what about the floating state of the pins / relays on powerup if I'm not using transistors?

Apologies for any obviously stoopid questions - sorry, I'm a real noob.
TIA
Posts: 1
Joined: Thu Jan 31, 2013 11:07 pm
by pjc123 » Tue Mar 19, 2013 2:15 pm
klricks wrote:
The 1.1A is the trip current. The hold current is lower. I think I read that it is 700mA or so?
This means the fuse can handle currents up to the hold current. Currents between the hold and trip is undefined. Resistance begins to increase then it may or may not trip. Currents above the trip will instantly trip similar to a standard fuse.
My HDMI to VGA adapter & WIFI were drawing about 820mA and kept tripping F3 after a few minutes.


That's true. I was assuming that he would put the same exact polyfuse into his diagram before the pi and the relay. If he decides to use a regular fuse (glass type for instance), then the hold current would be the value to go by, which on the polyfuse is correctly 700ma, and then selecting a fuse based on its time/current curve properties.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm
by A1i2T3R » Sun Apr 14, 2013 9:59 am
Do you have to use the sain smart one cause it is a little expensive
:D
By the way THX you made life a lot easier
:mrgreen: :D :idea:
also is this the one u got from amazon
http://www.amazon.co.uk/SainSmart-8-Cha ... lay+Module
:mrgreen:
Enthusiastic pi user, with a hoby for modding everyday objects and using the pi as the brain!
User avatar
Posts: 99
Joined: Sat Apr 13, 2013 1:08 pm
Location: England - Kent
by mchlwllmthms » Mon Apr 15, 2013 4:27 pm
A1i2T3R wrote:Do you have to use the sain smart one cause it is a little expensive
:D
By the way THX you made life a lot easier
:mrgreen: :D :idea:
also is this the one u got from amazon
http://www.amazon.co.uk/SainSmart-8-Cha ... lay+Module
:mrgreen:


Yes, that's the one I got. You can use whatever you want. Personally I think the Sainsmart is pretty cheap. If you use something else, don't rely on this diagram.
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by Todd » Tue Apr 16, 2013 12:36 am
Hi guys,
I am attempting a sprinkler controller as well, using the Sainsmart SSR board which looks as though all the protection is included - I just connect my GPIO straight to the channel input (attachment) and a 5VDC supply to power the relay

Just wondering if anyone has written their program in Python and if it looks similar to this:

import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(11, GPIO.OUT, initial=GPIO.Low)
GPIO.setup(13, GPIO.OUT, initial=GPIO.Low)
GPIO.setup(15, GPIO.OUT, initial=GPIO.Low)
GPIO.setup(19, GPIO.OUT, initial=GPIO.Low)
GPIO.setup(21, GPIO.OUT, initial=GPIO.Low)
GPIO.setup(23, GPIO.OUT, initial=GPIO.Low)

While true:
GPIO.output(11, High)
GPIO.output(13, High)
sleep(10)
GPIO.output(15, High)
GPIO.output(13, Low)
sleep(10)
GPIO.output(19, High)
GPIO.output(15, Low)
sleep(10)
GPIO.output(21, High)
GPIO.output(19, Low)
sleep(10)
GPIO.output(23, High)
GPIO.output(21, Low)
sleep(10)
GPIO.output(23, Low)
GPIO.output(23, Low)
sleep(60)
Attachments
SSR Schematic.jpg
SSR Schematic.jpg (19.67 KiB) Viewed 117961 times
Posts: 7
Joined: Fri Dec 21, 2012 3:08 pm
by aweber1nj » Mon Jun 24, 2013 8:39 pm
Eventually I plan to run everything with the 24V supply (hopefully), but haven’t figured out a circuit to (efficiently/safely) reduce 24V to 5V to run the RPi and Relay Board. If anyone has any ideas, please let me know.

I realize the thread has far more valuable information on how to wire the Sainsmart relay board to the PI, but just wanted to make a note that most irrigation controllers and valves are driven from 24VAC. So just remember you'll probably need a transformer or other fancy circuit to convert to 5VDC to power the PI and relay board.

Great info in this thread. Thanks to all!

-AJ
Posts: 13
Joined: Fri May 24, 2013 8:11 pm
by scott_ehm » Sun Dec 01, 2013 5:42 am
Your post is informative and you are a good person. I have a similar 8 channel relay i would like to safely talk to the pi but i believe it to be active HIGH. What changes would i make to the transistor board?
Posts: 1
Joined: Sun Dec 01, 2013 5:34 am
by mchlwllmthms » Sun Dec 01, 2013 11:12 pm
I realize the thread has far more valuable information on how to wire the Sainsmart relay board to the PI, but just wanted to make a note that most irrigation controllers and valves are driven from 24VAC. So just remember you'll probably need a transformer or other fancy circuit to convert to 5VDC to power the PI and relay board.[/quote]

Yes, actually, I realized this after the fact. I'd still like to build a circuit to run everything off of one power supply, but for the time being, it's separate. I'll update the main post to reflect that, thanks for the heads up!
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm
by mchlwllmthms » Sun Dec 01, 2013 11:33 pm
scott_ehm wrote:Your post is informative and you are a good person. I have a similar 8 channel relay i would like to safely talk to the pi but i believe it to be active HIGH. What changes would i make to the transistor board?


Well, you could connect your GPIO pins directly to the sainsmart headers without any intermediary circuit, which should work. Others may argue, however, that you should still put a 10k pull-down resistor from each GPIO pin to ground between the GPIO and the relay board to prevent triggering the relays in unknown states. I.e., without a pulldown resistor, it may cause some of the relays to temporarily activate during booting of the RPi. Again, I'm not 100% on whether that's necessary or not, but that's my guess, and it wouldn't hurt to add.
Attachments
Pulldown01.jpg
Pull-down resistor for active-high relay boards.
Pulldown01.jpg (38.09 KiB) Viewed 107178 times
Posts: 26
Joined: Tue Mar 05, 2013 11:42 pm