Caladain
Posts: 5
Joined: Fri May 17, 2013 6:52 pm

Help with Sainsmart relay

Fri May 17, 2013 7:01 pm

Greetings!

I'm a software engineer getting into a basic GPIO project with my Raspberry Pi, and I wanted to run my proposed circuit by some more knowledgeable eyes before I make a butchery job of the soldering (hopefully kidding :? )

I have a SainSmart 4 Relay 5V board, a ULN2083A and perfboard, and a Raspberry Pi. I've combed the forums here, and elsewhere, and came up with the following connections in order to operate the relay *and*, hopefully, protect my Pi from any badness coming back through the relay. I can't find *any* worthwhile documentation on this 4 Relay board, so i'm hoping i did everything correctly. Should this work?
http://oi40.tinypic.com/28cgdqw.jpg
Image

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Help with Sainsmart relay

Fri May 17, 2013 10:14 pm

The two GND wires on your diagram should be connected together but the rest looks fine. The current needed by the relay inputs is actually quite low and could be done by direct connection to the GPIO but an advantage of using the 2803 as you have done is that it means you set the GPIO high to activate the relay.

Caladain
Posts: 5
Joined: Fri May 17, 2013 6:52 pm

Re: Help with Sainsmart relay

Sat May 18, 2013 3:21 am

So, something more like this, or should i have the ground from the external power supply join with the ground from the RPi, and then feed into the ULN2083?

http://oi42.tinypic.com/2qknic3.jpg
Image

As a secondary question..why would it make a difference? To my uneducated and unenlightened mind to the world of the electrical engineer, ground is ground, yeah?

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Help with Sainsmart relay

Sat May 18, 2013 12:03 pm

You want to stick with the original diagram you showed but link the 2 purple wires together. The GND from the Pi, the ULN2803 and the input of the Relay board should all be joined together.

GNDs from these bits of equipment do not normally go back to the GND of the AC supply and so won't be connected together via that route. They are just the reference point for each bit of equipment and the reference points need to be joined together so they all agree on what GND is.

You are not breaking any isolation you get from using relays as the output switching contacts are not connected to anything on the input or Raspberry Pi side of things.

Caladain
Posts: 5
Joined: Fri May 17, 2013 6:52 pm

Re: Help with Sainsmart relay

Sat May 18, 2013 1:50 pm

Third time is hopefully a charm :-)

Sorry for all the trouble and thanks for your help thus far btidey. I know enough to know when i don't know enough and need a second set of eyes :lol: It's quite a fun project thus far, even if I haven't started final assembly.

The only remaining question I have, if this looks aOk, is what improvements, if any, anyone would recommend to help shield the RPi or relay board, and if the ground coming from the 5V power supply should be included in this loop as pictured, or if i should remove that link (leaving the rest)?

http://oi44.tinypic.com/6ga5c2.jpg
Image

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Help with Sainsmart relay

Sat May 18, 2013 5:15 pm

That looks fine to me now.

The GND of the 5V supply feeding the Pi, which I assume you are connecting through the microUSB Pi connector, is now effectively joined to the GND of your relay 5V power supply which is as it should be.

The alternative to using two separate supplies is to use one that is sufficient for both the Pi and the relay board and split its output so that GND and 5V go the Pi and also to the rest of your circuit. A 4 channel relay board like this probably needs about 0.3A when all 4 relays are on so a good 1A supply would be sufficient.

The one thing you don't really want to do is to power the Pi through the microUSB and then take significant amounts of current (say more than 0.2A) from the +5V connector on the GPIO to power external circuitry. That could put some strain on the polyfuse inside the Raspberry. It wouldn't do permanent damage but you can have to wait a while for the polyfuse to recover if it got overloaded.

Caladain
Posts: 5
Joined: Fri May 17, 2013 6:52 pm

Re: Help with Sainsmart relay

Thu Jul 11, 2013 4:33 pm

Sorry to resurrect this thread, but i have an update that I'd like someone to look at and say is "okay" given the above.

http://oi40.tinypic.com/vov2wm.jpg
Image

The only difference is that there is no linkage between the Raspberry Pi's Ground, the ULN2083's ground, and the Sainsmart's power supply's ground. I finally got to implement this project, and when i wired it up with the ULN2083's ground in that connection, the Sainsmart relay's LED's "Glowed" a soft red and wouldn't activate or deactivate. When i left the ULN2083 out of the ground loop, as pictured above, the Sainsmart relay appeared to function correct. Is this a safe thing to do?

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Help with Sainsmart relay

Thu Jul 11, 2013 8:04 pm

The ULN2803 GND should be connected to the common ground.

I suspect it is working somehow because at least 1 of the GPIO outputs is at a logic 0 and so the drive current from a GPIO high to the ULN2803 is finding its way back that way. More importantly the output current that the ULN2803 is sinking when the input side of the relay is turned on has to go somewhere and that should be through the pin 9 of the ULN2803 back to GND. Again I suspect that this sink current is flowing back into a GPIO low and that defeats the whole purpose of using the ULN2803.

I definitely would not leave it like this although there is little chance of doing damage as the relay input currents are quite small.

I think you need to reconnect the GND and then work out why it is not working. Set just one of the GPIO pins high. Then if you have a meter the corresponding input pin on the ULN2803 should be close to 3.3V with respect to pin 9. The corresponding output pin of the ULN2803 should be quite low ( < 1V) and the relay should turn on. Similarly the GPIO pins that are 0 should measure close to 0V with respect to pin 9 and the ULN2803 outputs should be close to 5V. If you don't have a meter then I'd suggest just connecting up 1 output and double checking all the connections.

Caladain
Posts: 5
Joined: Fri May 17, 2013 6:52 pm

Re: Help with Sainsmart relay

Thu Jul 11, 2013 8:36 pm

I wasn't precise earlier. When the 2083 is connected to the ground, the whole bank of relays glow (but not the bright red of when they are activated). I checked the output on the "other" side of the 2083 (the pins going to the relay) with and without the 2083's GND in the loop. They appear the same. I only have one set of wires connected (for relay 1) for simplicity.

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Help with Sainsmart relay

Thu Jul 11, 2013 10:17 pm

The LEDs on these relay circuits are pretty sensitive and will glow with quite small currents much lower than required to activate the relay. However, the leakage current through the ULN2803A when it is 'off' should be pretty low and I would not have expected this to have lit up the LED significantly.

Maybe one way to check things out is to disconnect all the 2803 inputs but leave the outputs connected to the relays, and with the 2803 properly grounded on pin 9. Under this condition the 2803 outputs are definitely off and if the Leds glow significantly then there is some other leakage path somewhere. Connecting one of the inputs of the 2803 to the 3.3V connector on the GPIO (pin 1) should then turn the corresponding LED on and activate the relay OK. If that is working OK then you need to check how you are setting the outputs on the GPIO. Have you programmed them to be proper outputs?

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Fri Sep 05, 2014 2:05 pm

@Caladain: I would love to see how it ended.

I have one (clone, I suppose, as it misses just the "sainsmart" mark) of this relay boards and I noticed that relay 1 doesn't switch, although the led indicating its activity follows the switching logic; furthermore, the relay 4, after switching initially, after a few seconds loose power and switch autonomously.
I tested the board with all possible settings (5V JD-VCC/3V VCC/JD-VCC+VCC not jumpered; or 5V JD-VCC/5V VCC/JD-VCC+VCC not jumpered; and lastly 5V JD-VCC/5V VCC jumpered) but the problem remains: only channels 3 and 4 seems to work properly. The power supply I used for the JD-VCC is 5V and 1500mA. It's also possible that in my case the issue is related to the fact my board should be a chinese clone (respect: nothing personal).
In regards to the VCC/JD-VCC jumper, no one talked about it. I suppose you considered it always shorted.
I've never tried to use a Darlinghton array with it, I have a ULN2003A and I'll check now how it goes.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Help with Sainsmart relay

Fri Sep 05, 2014 2:31 pm

dentex wrote:@Caladain: I would love to see how it ended.

I have one (clone, I suppose, as it misses just the "sainsmart" mark) of this relay boards and I noticed that relay 1 doesn't switch, although the led indicating its activity follows the switching logic; furthermore, the relay 4, after switching initially, after a few seconds loose power and switch autonomously.
I tested the board with all possible settings (5V JD-VCC/3V VCC/JD-VCC+VCC not jumpered; or 5V JD-VCC/5V VCC/JD-VCC+VCC not jumpered; and lastly 5V JD-VCC/5V VCC jumpered) but the problem remains: only channels 3 and 4 seems to work properly. The power supply I used for the JD-VCC is 5V and 1500mA. It's also possible that in my case the issue is related to the fact my board should be a chinese clone (respect: nothing personal).
In regards to the VCC/JD-VCC jumper, no one talked about it. I suppose you considered it always shorted.
I've never tried to use a Darlinghton array with it, I have a ULN2003A and I'll check now how it goes.
as you say, its likely the clone quality at fault, cheap can have problems.
Have you checked voltage at the relay coil while it is energised?
Doug.
Building Management Systems Engineer.

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Fri Sep 05, 2014 3:09 pm

BMS Doug wrote: as you say, its likely the clone quality at fault, cheap can have problems.
Have you checked voltage at the relay coil while it is energised?
Voltage at the relay coils is around 4,8V for the 3 working ones. The unswitching one can be triggered applying manually 5V to its coils. With everything engaged (all 4 LEDs on), every octocoupler has ~1V on the source side and all have ~3.2V on the sensor side but the channel it's not switching.
Happens that I have a spare EL817 so I can try to replace it.
Never attempted at doing anything similar, I'm quite new to this stuff, but would be terrific if I could fix it like this. :o
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Help with Sainsmart relay

Fri Sep 05, 2014 3:28 pm

A fairly simple board like this is perfect for first time repair efforts, I hope you have a good soldering iron (temperature controlled one) as it will make the job much easier.

Good luck with the repair.
Doug.
Building Management Systems Engineer.

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Fri Sep 05, 2014 4:01 pm

BMS Doug wrote:A fairly simple board like this is perfect for first time repair efforts, I hope you have a good soldering iron (temperature controlled one) as it will make the job much easier.

Good luck with the repair.
Thanks.
The repair went OK, but the relay doesn't switch anyway. Same voltages read on the new octocoupler. :(

Considering the scheme should be this one:
sainrelay.png
sainrelay.png (12.69 KiB) Viewed 17693 times
I wonder what could be.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Fri Sep 05, 2014 4:19 pm

I found that shorting contacts 3 and 4 of the above scheme triggers all the relays except the one it's not working. What does it mean? Should be a problem with the Q3 transistor?
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Help with Sainsmart relay

Fri Sep 05, 2014 10:11 pm

Diode D3 could be shorted out, that or it must be the resistor R6 or the transistor Q3 as they are the only remaining potential faults.

not the diode or you wouldn't be able to energise the relay by putting a voltage across it.

I would suggest checking the resistance between leg 3 of the opto-isolator and the base of the transistor Q3, if that is the same across all of the relays then the problem has to be Q3 (in my opinion).
Doug.
Building Management Systems Engineer.

ianahner
Posts: 2
Joined: Tue Sep 16, 2014 7:08 pm

Re: Help with Sainsmart relay

Tue Sep 16, 2014 7:13 pm

I question the need for the ULN2083 at all.

A quick look at the schematic for the Sainsmart board shows me that the first signal wire pin is sent through a transistor and then a ULN2083 INSIDE the Sainsmart relay board. I believe you may be introducing unnecessary redundancy. The signal current that the Sainsmart board will require should be very low, and you shouldn't get any risk of damaging the raspi due to the on-board uln2083 and transistor/diode setup.

I would recommend checking out the schematics for the Sainsmart board. They are very crappy schematics, but they DO show what is going on if you take a minute to try to follow all the remote net labels.

ianahner
Posts: 2
Joined: Tue Sep 16, 2014 7:08 pm

Re: Help with Sainsmart relay

Tue Sep 16, 2014 7:21 pm

Correction:

Ignore me, I am totally incorrect. I was looking at a schematic for the 16channel version and made the false assumption that it used the same components.

Therefore, there is NOT actually a uln2083 on board.

HOWEVER:

It does use a double transistor switching method and one of those transistors has a diode on the input pin side. When you consider that the uln2083 is simply a transistor array, the end result is more or less the same, and you would likely be fine directly driving it from the raspi.

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Sat Jul 02, 2016 10:52 am

BMS Doug wrote:Diode D3 could be shorted out, that or it must be the resistor R6 or the transistor Q3 as they are the only remaining potential faults.

not the diode or you wouldn't be able to energise the relay by putting a voltage across it.

I would suggest checking the resistance between leg 3 of the opto-isolator and the base of the transistor Q3, if that is the same across all of the relays then the problem has to be Q3 (in my opinion).
I've always been amazed by how I cannot maintain track of replies on this board (or the mail system sucks, or all goes into the spam folder on my side)... But... REALLY thanks for the reply anyway, although I'm saying this with absolutely improper delay.

The story here ended in the way that I ditched the crappy board and made a DIY board with the ULN2003's logic on it and then piloted 4 single relays (Groove by Seedstudio) that didn't have optocouplers on board. Up and running since then. :lol:

Thanks mate, I always appreciate any help on good forums, as this one is, but your reply simply slipped through my fingers. :)
Last edited by dentex on Sat Jul 02, 2016 10:58 am, edited 1 time in total.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Help with Sainsmart relay

Sat Jul 02, 2016 10:54 am

ianahner wrote:Correction:
... the end result is more or less the same, and you would likely be fine directly driving it from the raspi.
Hi,
yes you're right, but probably the logic in doing this for many owners of this relay boards, is simply to invert the board's behavior from active low to active high, which make a lot more sense IMHO. ;)
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac

Return to “Automation, sensing and robotics”