rasusr
Posts: 22
Joined: Thu Jul 04, 2013 3:46 am

GPIO to SainSmart 4-channel relay board, transistors needed?

Tue Nov 19, 2013 10:47 pm

Hi,
There are a lot of posts out there about how the Sainsmart 4 or 8 channel 5V relay should not be used directly from the Raspberry Pi. Many people use NPN transistors in between the relay module and the RPi. And there are also people who wire the RPi directly to the Sainsmart relay and saids it works fine, but I haven't seen any schematic of that setup, so I'm trying to make one.

According to the schematic, the relay coil is powered via an optocoupler. The VCC terminal is the logic high voltage, and the JD-VCC terminal is the relay coil voltage. As long as you don't jumper the VCC to the JD-VCC, you can have 3V on VCC for logic level and 5V on JD-VCC for relay coil power.

I attached an image of how I think it could be directly wired up. What I don't understand is that the Sainsmart board seems to need a way to sink the input current (from VCC to ground) to engage the relay coil. If you connect the GPIO output to one of the relay board input pins...I'm not sure how that works. People who are wiring the Rpi directly to the Sainsmart boards, is this how they're doing it?

My direct wire schematic:
http://img33.imageshack.us/img33/1010/uk1a.jpg

Here's someone who used a buffer IC in between the RPi and the relay board. Is this the more appropriate way to drive the relay? I can see how the 7407 is sinking the RPi's VCC logic to the RPi's ground.

http://www.raspberrypi.org/phpBB3/downl ... hp?id=4658

Thanks for any input.

rasusr
Posts: 22
Joined: Thu Jul 04, 2013 3:46 am

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Tue Nov 19, 2013 10:58 pm

Followup -
The circuit above that uses a buffer IC of NPN transistors, do you need to add some resistors to the input and ground, more like this link?

https://docs.google.com/file/d/0B5-HND9 ... edit?pli=1

User avatar
DougieLawson
Posts: 32702
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Tue Nov 19, 2013 11:22 pm

It looks OK. There appears to be opto-isolators on the SainSmart board, those will protect the RPi GPIO pins. Don't jumper JD-Vcc to Vcc.

The relays need 5V to close / open. You could use the 5V pin on the RPi but it may be safer to use an external 5V supply.
The relays can switch 250VAC 10A or 30VDC 10A. BEWARE of mains voltages.

Pin 1 to Vcc
Pin 9 to GND
Pins 11, 12, 13, 15 to IN1, IN2, IN3 & IN4

Pin 2 to JD-Vcc (or external supply to JD-Vcc and GND)

Set pins 11, 12, 13 or 15 high and the relay should activate.

As far as I can see you don't need to add additional transistors/resistors for the opto isolators. But, I can't find a datasheet that tells what voltage / current is needed for to activate the opto-isolators.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

ryguystye
Posts: 4
Joined: Tue Nov 19, 2013 7:58 am

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Sun Nov 24, 2013 9:55 am

DougieLawson wrote:It looks OK. There appears to be opto-isolators on the SainSmart board, those will protect the RPi GPIO pins. Don't jumper JD-Vcc to Vcc.

Set pins 11, 12, 13 or 15 high and the relay should activate.

As far as I can see you don't need to add additional transistors/resistors for the opto isolators. But, I can't find a datasheet that tells what voltage / current is needed for to activate the opto-isolators.
Hi. I'm looking to use the same relay with my Pi and I'm a noob. Isn't it an active low relay? Is there a way use the same setup with the 3.3V to Vcc and 5V to JD-Vcc, but so that the Pi's signal to the relay is so that high is active and low is off? Is that what other people use the transistors/resistors for?

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Sun Nov 24, 2013 11:06 am

The whole transistor issue is one that is based in ignorance. Because the Sainsmart relay boards are opto isolated, there is no need to add any additional transistors. What I have found is that the design of the sainsmart boards is lacking. Sainsmart has a chip LED in series with the opto-isolator. This is clearly wrong at 3 or 5 volt levels. Some of the chip LEDS on the SS boards are crap. They will change their current carrying ability over time. To resolve all those issues, I have jumpered out the LEDs on the board.

I drive multiple SS relay boards directly from MCP23017 chips on a single Rpi. No additional transistors needed or wanted.

Now if you want to change the relay board input from sink to source switching, then there are a few options, a transistor being one of them. On the two relay SS board, the board can be modified to permit source switching of the relays.

I have found that in the case of a RPI, driving a relay board with the output of a port expander like the MCP23017 is the best solution for me. Controlling the MCP23017 is very easy. It can be dome from a shell script, python, or any other programmiong language you desire. The plus side of the I2C bus is that it only uses 2 GPIO pins.

If you want to drive the relay board directly from the GPIO pins, I cannot help you as I have not done it.

If you want to switch 115 volts AC, a solid state relay is what I would use. I use a Raspberry Pi and SS relays to control the compressor drains in my shop. The same Rpi is also a music server. SS relays come in a variety of sizes. I use a pair of SS relays to control the amplifiers for my stereo. I have two 1kw amplifiers.

The cost of a MCP23017 is between $1 and $2 depending on quantitiy. I paid $25 for 25 of them 10 months ago.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
Douglas6
Posts: 4346
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Sun Nov 24, 2013 5:48 pm

Richard-TX wrote:The whole transistor issue is one that is based in ignorance.
I'm not disputing that at all, but in my (ignorant) experience I had to use an MPC23017 AND transistors to get reliable switching, I believe because of the indicator LEDs on the Sainsmart, which I did not try to bypass.

dkossman
Posts: 26
Joined: Tue Dec 25, 2012 12:35 am
Location: Los Angeles, California

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Mon Apr 28, 2014 1:37 am

just found this on ebay. looks like you can jumper it to trigger either high or low. I've asked the seller for a schematic - need to confirm that if i hook it up to 5V that it won't feed back to the Pi's 3.3v GPIO pins.

http://cgi.ebay.com/ws/eBayISAPI.dll?Vi ... 1486573020

anyone familiar with it, by any chance?

thanks

cycleops
Posts: 2
Joined: Fri Jun 19, 2015 3:48 pm

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Fri Jun 19, 2015 4:01 pm

I have a similar SainSmart board (but 8 channel) -- everything works just fine except at boot when some of the relays switch on and off rapidly -- does anyone know if there's a way to prevent this without disconnecting the board?

cycleops
Posts: 2
Joined: Fri Jun 19, 2015 3:48 pm

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Mon Jun 22, 2015 9:23 pm

cycleops wrote:I have a similar SainSmart board (but 8 channel) -- everything works just fine except at boot when some of the relays switch on and off rapidly -- does anyone know if there's a way to prevent this without disconnecting the board?
Answering my own question: While many of my GPIO pins are indeterminate during boot, only pin 8 was swings with enough voltage to activate a relay, so I just removed that pin from my set and all is good. And I set the pins high at the end of boot. I guess I could use pull-up resistors on all the pins, but it doesn't seem necessary.

dbarry722
Posts: 15
Joined: Thu Jan 02, 2014 1:16 am

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Sun Sep 04, 2016 3:48 pm

Hi guys..

Bought this to learn about interfacing the Raspberry Pi but am a bit unsure about the connections as no datasheet came with it..

Has anyone used one of these? I'd rather use a separate battery for the relays with the raspberry Pi just supplying the switching signal. Seems a little similar to the SainSmart board

Many thanks

Declan

http://www.ebay.co.uk/itm/5V-1-2-4-8-Ch ... 1765757093

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Sun Sep 04, 2016 5:33 pm

Douglas6 wrote:
Richard-TX wrote:The whole transistor issue is one that is based in ignorance.
I'm not disputing that at all, but in my (ignorant) experience I had to use an MPC23017 AND transistors to get reliable switching, I believe because of the indicator LEDs on the Sainsmart, which I did not try to bypass.
It says here, https://www.amazon.com/SainSmart-101-70 ... B0057OC5O8 , that it takes 15 to 20 mA per relay. This says, http://raspi.tv/2013/rpi-gpio-basics-5- ... h-rpi-gpio, "The maximum recommended current draw from that supply is 51 mA. This is the total for all the 3V3 GPIO pins. ... The maximum current draw from any one pin should not exceed 16 mA." Now if you have one of those 8 channel relay modules running all eight relays, that's clearly going to be over the limit in total current and it is very possible that each relay is over the limit, if only a little bit. Your experience, instability and whatnot, seems to suggest, I think, that you are right to be wary. And the other poster who seems to be hinting that there's no problem actually removed the LEDs from the circuit, apparently. So it seems like at some level everyone is sort of in agreement that there are issues.

dkossman
Posts: 26
Joined: Tue Dec 25, 2012 12:35 am
Location: Los Angeles, California

Re: GPIO to SainSmart 4-channel relay board, transistors nee

Mon Sep 05, 2016 9:29 pm

15ma is what is required to drive each of the relay coils. However the actual input current to each of the board's IN1... IN8 inputs is about 0.45ma when pulling them low.

I just measured it on a typical 8 relay board off eBay similar to the one being discussed.

Thus its perfectly safe to drive directly from the Pi's GPIO outputs.

If anyone has seen differently let us know.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 9 guests