nattila
Posts: 1
Joined: Sun Nov 01, 2015 8:09 am

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

Sun Nov 01, 2015 8:30 am

Thank you for this great tutorial.
I have already implemented this wiring to connect my RPi B+ and a Sainsmart relay by using a BC 547 B transistor.
I have two issues with this implementation:
  • Without the 10K resistor it works great, but when I add the 10K resistor into the circuit the relay doesn't work anymore.
  • When the PI is off (sudo halt) or booting the relay turns on which can cause unintended consequences. But it also depends on which GPIO pin is using. While PI is turned off the relay turns on if connected to pin4, but doesn't turn on if connected to pin17.
Do you have any idea how to solve these issues?

Edson_Mavhondo
Posts: 1
Joined: Thu Feb 11, 2016 9:42 am

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

Thu Feb 11, 2016 9:48 am

Hie.

Recently bought a 4 Channel sainsmart relay. I have read before about using diodes and transistors as a means of protecting the RPi from potential damage.

In all the video tutorials i have watched on YouTube I noticed they were connecting the relay directly to the Pi and it worked just fine. My conclusion was that the sainsmart relay must be inbuilt with the transistors and diodes hence enabling you to connect directly

is this correct.

thanks

klricks
Posts: 5766
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

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

Thu Feb 11, 2016 1:32 pm

Edson_Mavhondo wrote:Hie.

Recently bought a 4 Channel sainsmart relay. I have read before about using diodes and transistors as a means of protecting the RPi from potential damage.

In all the video tutorials i have watched on YouTube I noticed they were connecting the relay directly to the Pi and it worked just fine. My conclusion was that the sainsmart relay must be inbuilt with the transistors and diodes hence enabling you to connect directly

is this correct.

thanks
Yes, All relay boards I have seen have the back EMF diodes and transistors included.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

mykeg
Posts: 1
Joined: Sat Apr 30, 2016 10:12 pm

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

Sat Apr 30, 2016 10:18 pm

I've got two 8 port Sainsmart Relay Boards, have read through all of the posts. Everything I read says that pulling the pin low (grounding) on the relay board should activate the relay. My doesn't!

I built this board; https://docs.google.com/file/d/0B5-HND9 ... VyODA/edit and it doesn't work. If I jump the i/o pin on the relay board to VCC it activates. Am I just stupid??? Someone put on the right track.

Thanks,
Mike

klricks
Posts: 5766
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

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

Sun May 01, 2016 12:29 am

mykeg wrote:I've got two 8 port Sainsmart Relay Boards, have read through all of the posts. Everything I read says that pulling the pin low (grounding) on the relay board should activate the relay. My doesn't!

I built this board; https://docs.google.com/file/d/0B5-HND9 ... VyODA/edit and it doesn't work. If I jump the i/o pin on the relay board to VCC it activates. Am I just stupid??? Someone put on the right track.

Thanks,
Mike
If you built the board with the transistors as shown in your linked diagram, then that will make the relays 'active high'.
The only purpose of the board is to convert the relays from 'active low' to 'active high' and IMO it's not needed.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

chelo_c
Posts: 4
Joined: Fri May 13, 2016 4:58 am

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

Fri May 27, 2016 11:47 pm

I have made the circuit you suggested. But there is something terrible wrong.

See when the relay gets activated (logic 1 on GPIO) it opens the NC circuit (of course).
However, it doesnt close the NA circuit. It gets stuck in an intermiadate state. (the NA never closes)

What can this be? is the voltage on the gpio not enough?

I am using the exact circuit you suggested, only 1 relay, Raspberry Pi 2 Model B.

Any suggestions? I have an exposition tomorrow and I am f***ed up.

Thanks!



---EDIT---

I fixed it! sorry, it was my mistake.
Yes it works great! thanks a lot for sharing knowledge!
do you have a bitcoin wallet for donations?
Last edited by chelo_c on Sat May 28, 2016 1:02 am, edited 1 time in total.

klricks
Posts: 5766
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

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

Sat May 28, 2016 12:55 am

chelo_c wrote:I have made the circuit you suggested. But there is something terrible wrong.

See when the relay gets activated (logic 1 on GPIO) it opens the NC circuit (of course).
However, it doesnt close the NA circuit. It gets stuck in an intermiadate state. (the NA never closes)

What can this be? is the voltage on the gpio not enough?

I am using the exact circuit you suggested, only 1 relay, Raspberry Pi 2 Model B.

Any suggestions? I have an exposition tomorrow and I am f***ed up.

Thanks!
You are using the circuit who suggested?
What is NA?
Most relays have NC, (C)ommon and NO. When the relay is not activated then C is connected to the NC terminal. When activated then C is then connected to NO.
See this for explanation of how relays work: http://pcbheaven.com/wikipages/How_Relays_Work/
Give a link to the relay board you are using and a photo and/or circuit diagram.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

chelo_c
Posts: 4
Joined: Fri May 13, 2016 4:58 am

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

Sat May 28, 2016 1:03 am

klricks wrote: You are using the circuit who suggested?
What is NA?
Most relays have NC, (C)ommon and NO. When the relay is not activated then C is connected to the NC terminal. When activated then C is then connected to NO.
See this for explanation of how relays work: http://pcbheaven.com/wikipages/How_Relays_Work/
Give a link to the relay board you are using and a photo and/or circuit diagram.


I fixed it! sorry, it was my mistake.
Yes it works great! thanks a lot for sharing knowledge!
do you have a bitcoin wallet for donations?

TRBTStevenson
Posts: 9
Joined: Sat May 28, 2016 2:16 am

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

Sat May 28, 2016 2:19 am

I am wiring a http://smile.amazon.com/GEREE-Channel-T ... ge_o01_s00 to my Raspberry Pi 3 would this be the same setup to make my relay activate but using a 12v power supply to power the board?

flegarrec
Posts: 1
Joined: Sat Sep 06, 2014 5:58 pm

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

Sun Jun 12, 2016 6:50 am

Thank you very much for this tutorial, especially for the diagram and its side info. All in one page, that's great. I think i know understand why i had issues with my relays. Applying your advices now. Thanks again.

Pointy
Posts: 10
Joined: Mon May 30, 2016 7:07 pm

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

Thu Jul 07, 2016 8:32 am

I know this thread was started a few years ago but I was curious if any of the original contributors are still around and can let me know how reliable this configuration has been.

I am looking to do something similar but I am going to be controlling aquatic systems, so reliability is key. I have also made a couple of changes, and I am no EE, so any feedback is greatly appreciated.

First off I am using a a RPI 3, which I believe will supply 2.5A on the 5V and I would like to drive the relay module coils from the GPIO 5V lines.

The relay board I have is unbranded but looks the same as the Sainsmart one. The relays are Songle SRD-05VDC-SL-C, which draw just over 70ma each. The inputs are opto isolated as per the following schematic...
relay module.png
relay module.png (20.31 KiB) Viewed 2917 times
The changes I have made are to add a manual/auto switch and change the components to SMD. See the following schematic...
relay_switch.png
relay_switch.png (21.63 KiB) Viewed 2917 times
When the switch is in the down position, it will ground the relay input pin, turning on the relay (manual on) In the up position it will connect the relay input to the GPIO pin and thus be controlled by the PI (auto mode). The switch will have a centre off to disable the output as well.

I am not sure but I don't think the transistors specs are critical so I just picked a GP SMD BC847B and I am using the same value resistors from the original post.

Can anyone see any problems with this configuration as I haven't tested it yet? Any other feedback is also appreciated.

Regards,

Les

arker
Posts: 1
Joined: Wed Dec 21, 2016 6:01 pm

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

Wed Dec 21, 2016 6:05 pm

I know this is a really old post, but I am confused.

Why is this considered Active-Low or Active-High when there are 3 terminals. Wouldn't connecting to A+B = Active-Low and B+C = Active-High?

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

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

Wed Dec 21, 2016 7:49 pm

arker wrote:I know this is a really old post, but I am confused.

Why is this considered Active-Low or Active-High when there are 3 terminals. Wouldn't connecting to A+B = Active-Low and B+C = Active-High?
It's to do with when the relay coil is energised not which set of contacts NO or NC are connected.
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.

dezmondpena
Posts: 1
Joined: Thu Jan 12, 2017 6:09 pm

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

Thu Jan 12, 2017 6:13 pm

Can you please send me more detailed information as to how to build this? Specifically instructions with the breadboard, I'm not sure where and how you placed the materials listed on it, thanks.

Email [email protected]

Phoenixxl
Posts: 1
Joined: Sun Jan 29, 2017 10:53 am

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

Sun Jan 29, 2017 11:09 am

To me, instead of messing around with a miniature breadboard or soldering resistors and diodes together as some suggest and risking damage to your lovely PI the answer for 2017 is ( just my humble opinion ):

Buy a cheap arduino clone ( the things are open source hardware so there's no shame in it) a model with a micro usb connector. The last one I bought was 2.99$ it took 3 weeks to get here but I really don't care tbh.
Buy a cheap usb-a to micro usb connector cable I've seen them around in discount shops for a euro and less.

The usb cable will power and control the arduino using serial over usb. You can now make a (9600 baud should be enough) serial connection between the PI and the arduino and set the states of your relay board using the arduino. Programming a simple multiplexer or something more elaborate if you wish. Setting your 8 relays to any state takes 1 byte. Package that byte any way you like. even if you add 3 bytes overhead for error correction etc , at 9600 baud you can change the state of all your relays every 3.3 milliseconds which should be plenty.

kdeuler
Posts: 5
Joined: Sun Mar 08, 2015 8:07 pm

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

Wed Mar 29, 2017 3:08 am

Hi Mike. I'm interested in doing exactly what you did with your instructions just below on this old post. Do you still recommend this configuration?

Also, I suppose you used the SIP software? (http://dan-in-ca.github.io/SIP/)

Mrt2081
Posts: 1
Joined: Tue Aug 08, 2017 1:35 pm

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

Tue Aug 08, 2017 1:38 pm

Thanks
You save my life👏😉

dacuda418
Posts: 1
Joined: Wed Sep 13, 2017 11:46 pm

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

Thu Sep 14, 2017 12:27 am

Chelo_C, thank you. I was reading this thread and going crazy so much time and effort was being wasted by many due to a faulty understanding of relays.

The relay can open and close a circuit on either of these pairs: B to A or B to C. The difference between the two is actually the answer to the original posters problem.

Wiring for sprinkler:

Cut one of the two wires going to sprinkler and now you have two wire ends. Put one in B. Put the other in A if you want the relay to keep the circuit closed by default (circuit complete....sprinkler on). This would require the pi to send a signal to the relay to open the circuit to turn off the sprinkler because by default the circuit stays closed(sprinkler on if you will).

Put the other wire end in C instead of A solves the problem. Now the circuit will remain open(sprinkler off) until the relay receives a signal to close the circuit thus turning on the sprinkler.

The relay talk about 5V means the relay itself takes 5V that it can get from the pi. Its not a limitation or indication what voltage the relay can control. Who cares the pi is 5V and the circuit you are controlling is 24V, it doesn't matter. What matters is if the relay can control 24V or not. That's the whole point of the relay. Using low voltage to power and control the relay in order to open and close higher voltage circuits.

Just wire the pi to the relay, cut into the circuit you want to control, in this case a sprinkler. Choose AC to hook your wires to (doesn't matter which end gets A or C) and the sprinkler will be off by default. Now you just have to program the pi to tell the relay when to close the circuit and turn the sprinkler on.

Done.

Learning101
Posts: 20
Joined: Sat Feb 10, 2018 10:54 am

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

Sat Feb 10, 2018 3:46 pm

Hi, what alternative transistor could be used for this setup? I can't source the 2n222 anywhere!

I've picked up a pick of mixed Kemo transistors from Madlins hoping one of them might do the job

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10845
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Sat Feb 10, 2018 9:24 pm

Learning101 wrote:
Sat Feb 10, 2018 3:46 pm
Hi, what alternative transistor could be used for this setup? I can't source the 2n222 anywhere!

I've picked up a pick of mixed Kemo transistors from Madlins hoping one of them might do the job
that should be a 2N2222, a 2N222 does not exist.
other transistors you could use are a 2N3904, or a BC547

Learning101
Posts: 20
Joined: Sat Feb 10, 2018 10:54 am

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

Sun Feb 11, 2018 9:19 am

Thanks for the help, would a BC529B or BC546B work?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10845
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

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

Mon Feb 12, 2018 12:03 pm

Don't know the BC529B, but yes a BC546 would work too, in fact almost all small NPN transistors will work.

Learning101
Posts: 20
Joined: Sat Feb 10, 2018 10:54 am

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

Mon Feb 12, 2018 1:30 pm

Thanks a lot for your help!

User avatar
Burngate
Posts: 5403
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

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

Mon Feb 12, 2018 6:18 pm

In this situation, BC529 won't work, it's pnp (apparently - no-one seems to have the pdf)

PhatFil
Posts: 389
Joined: Thu Apr 13, 2017 3:55 pm

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

Mon Feb 12, 2018 6:30 pm

would n alternative approach be to employ 3.3v-5v logic level shifters available as 2 4 and 8 channel pcb modules to protect the Pi from an accidental voltage spike, take 5v to feed both the hi voltage side of the LLS and the vcc pin on the relay module, Then connect the pi-gpio pins set for output to the relay via the low voltage side of the LL

the 2 way coms is redundant in this use but its a more lego approach that could appeal to some?

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

Who is online

Users browsing this forum: Bing [Bot] and 13 guests