Page 1 of 2

Rpi and relay to switch on/off lights

Posted: Mon May 13, 2013 12:45 pm
by Angelus88
Hello everybody. I'm looking for a way to connect the raspberry pi to some sort of relay to switch off/on my home lights. I know there are plenty of tutorials out there but my problem is I know about nothing of electronic, my bad.

I wanted to buy a relay like this:

Image

I wanted to ask you two things:

1) How can I phisically connect the raspberry to the relay? And I mean, which kind of cables should I use? Is there a noob-proof tutorial somewhere?

2) What kind of devices can I connect to the relay? I mean... is there some kind of power-consumption limit?

Thanks a lot guys ;)

Re: Rpi and reley to switch on/off lights

Posted: Tue May 14, 2013 11:35 am
by rooster1
Angelus88 wrote:Hello everybody. I'm looking for a way to connect the raspberry pi to some sort of relay to switch off/on my home lights. I know there are plenty of tutorials out there but my problem is I know about nothing of electronic, my bad.

I wanted to buy a relay like this:

Image

I wanted to ask you two things:

1) How can I phisically connect the raspberry to the relay? And I mean, which kind of cables should I use? Is there a noob-proof tutorial somewhere?

2) What kind of devices can I connect to the relay? I mean... is there some kind of power-consumption limit?

Thanks a lot guys ;)
Hi

You can use 3 wires from the GPIO to the relay (female to male jumper leads). 3.3V, signal and ground. This will operate the relay using simple command line scripts

http://elinux.org/RPi_Low-level_periphe ... ing_system

The relays you show are 10 Amps as I remember. Plenty for lights.

R

Re: Rpi and reley to switch on/off lights

Posted: Tue May 14, 2013 2:13 pm
by Angelus88
Well... so it doesn't matter if the relay is 5v and the gpio pin is 3,3v?

Re: Rpi and relay to switch on/off lights

Posted: Tue May 14, 2013 2:27 pm
by Pieter-Jan5000
The gpio pins of the raspberry pi are probably too limited in current to drive a relay directly. Use a line driver like the uln2003a to overcome this problem. Then you can also fix the problem of the voltage by feeding the line driver with 5V

Re: Rpi and relay to switch on/off lights

Posted: Tue May 14, 2013 2:37 pm
by Angelus88
Pieter-Jan5000 wrote:The gpio pins of the raspberry pi are probably too limited in current to drive a relay directly. Use a line driver like the uln2003a to overcome this problem. Then you can also fix the problem of the voltage by feeding the line driver with 5V
Yeah, this is what I was wondering but I found some videos, like this one, where the raspberry is directly connected to the relay.

Re: Rpi and relay to switch on/off lights

Posted: Tue May 14, 2013 3:26 pm
by penguintutor
so it doesn't matter if the relay is 5v and the gpio pin is 3,3v?
Probably not - you would need to check the specs of the relay interface board, but whilst the relays need a 5v supply, the accompanying circuitry built into the relay board will most likely work with a 3.3v input signal.

The gpio pins of the raspberry pi are probably too limited in current to drive a relay directly.
That is correct if you are trying to switch a relay directly from the GPIO, but if using a relay interface board as shown in the photos then there is already circuitry to switch the relays on/off using a logic level signal.

Re: Rpi and relay to switch on/off lights

Posted: Tue May 14, 2013 4:00 pm
by Mortimer
Angelus88 wrote:
Pieter-Jan5000 wrote:Yeah, this is what I was wondering but I found some videos, like this one, where the raspberry is directly connected to the relay.
I don't believe it is. The 8-channel relay board shown has opto-isolators driving the relay coils, so the GPIO pin is only having to sink current through a pair of LEDs.
Image

However from Sainsmarts own website there is a link on how to interface the Raspberry Pi to their 8-channel relay board:
http://www.sainsmart.com/arduino-compat ... logic.html

Here is the link itself:
https://github.com/fixedd/RPi_SainSmart ... ace#readme

However that video , along with many others, seems to suggest that the Raspberry Pi can work directly connected to the relay board.

Re: Rpi and relay to switch on/off lights

Posted: Tue May 14, 2013 5:10 pm
by Sarge
You could use a Power Tail Switch.

http://www.powerswitchtail.com/Pages/default.aspx

Maybe pricier than the relays but works fine with the Pi's GPIO.

Sarge

Re: Rpi and relay to switch on/off lights

Posted: Wed May 15, 2013 9:00 am
by Angelus88
Mortimer wrote:
I don't believe it is. The 8-channel relay board shown has opto-isolators driving the relay coils, so the GPIO pin is only having to sink current through a pair of LEDs.
Image

However from Sainsmarts own website there is a link on how to interface the Raspberry Pi to their 8-channel relay board:
http://www.sainsmart.com/arduino-compat ... logic.html

Here is the link itself:
https://github.com/fixedd/RPi_SainSmart ... ace#readme

However that video , along with many others, seems to suggest that the Raspberry Pi can work directly connected to the relay board.
Thanks for the informations. I found that link from Sainsmart too but as you can see the raspberry is connected to that sort of pcb and then the pcb is connected to the relay while in the video, as you say, is directly connected. Anyway, I've already ordered the relay board so I'll let you know if it works directly connected ;) Thanks a lot guys!
Sarge wrote:You could use a Power Tail Switch.

http://www.powerswitchtail.com/Pages/default.aspx

Maybe pricier than the relays but works fine with the Pi's GPIO.

Sarge
Yes, I found this device too but I'm from Italy so I don't think it's gonna work :D

Re: Rpi and relay to switch on/off lights

Posted: Wed May 15, 2013 9:04 am
by Pieter-Jan5000
Ok sorry. I didn't take a good look at the board. With a board that has opto couplers on it, the need for a line driver is obsolete. It also offers better protection for the indutive load of the relay. Good luck.

Re: Rpi and relay to switch on/off lights

Posted: Wed May 15, 2013 9:11 am
by Angelus88
Pieter-Jan5000 wrote:Ok sorry. I didn't take a good look at the board. With a board that has opto couplers on it, the need for a line driver is obsolete. It also offers better protection for the indutive load of the relay. Good luck.
Great, thanks a lot again ;) I knew I could count on you guys

Re: Rpi and relay to switch on/off lights

Posted: Mon May 20, 2013 11:40 pm
by Angelus88
Good news guys, it worked! In the end I choosed this one.

Image

It's almost the same of the other one and it did his job.
I just used three wires and using this scheme I did as follows:

Image

First wire from the 3v3 power to the VCC of the relay.
Second wire from the Ground to the Ground of the relay.
Third wire from the GPIO 17 to the IN1 of the relay.

I guess I can use the other GPIO 22, 23 and 24 for the IN2, IN3 and IN4
as my relay has 4 switches.

Then from the shell I just needed to do as follows (with root permissions):

echo "0" > /sys/class/gpio/gpio17/value :------> the switch is off
echo "1" > /sys/class/gpio/gpio17/value :------> the switch is on

It changes immediately and it's working well even from a webpage with php.
Thanks a lot guys for the support ;)

Re: Rpi and relay to switch on/off lights

Posted: Tue Jun 11, 2013 8:08 am
by dugongmoladive
Hello,

I'm using Fotek SSR to do the trick. They come in several different flavor. Do check your power requirement before getting one.

Although the datasheet says it accepts 3-32VDC on the input pins, my rev 2 board doesn't have enough juice to power it directly from the GPIO (maybe not enough power on the PSU). So I end up creating an open collector circuit with NPN transistor with 5v from the power rail on the collector side. You can also use MOSFET to do this, but NPN BC547 is what I have lying around. With 5v on the SSR's input side, it works like a charm.
This SSR is pretty cheap, around 10 bucks each. So google around if you decide to buy one.

Just make sure you double/triple check all the connections before you test it with life AC current.

Re: Rpi and relay to switch on/off lights

Posted: Wed Jul 24, 2013 11:31 pm
by ruffinmedia
I'm looking to do a similar thing however I need to be able to cut the connection on and off for 240 voltage cable.

Re: Rpi and relay to switch on/off lights

Posted: Tue Aug 20, 2013 8:31 am
by talkeasy
Hi Angelus88

Can you explain why you connected the relay to the 3.5v pin not the 5v one? The relay spec says 5v.

Like to try this myself!

Thanks.

Re: Rpi and relay to switch on/off lights

Posted: Tue Aug 20, 2013 9:01 pm
by Angelus88
ruffinmedia wrote:I'm looking to do a similar thing however I need to be able to cut the connection on and off for 240 voltage cable.
Well, this relay board should work! If you read the description, it is written that the board can manage 10A (max 250V AC or max 30V DC) for each relay. Anyway, what do you want to do?
talkeasy wrote:Hi Angelus88

Can you explain why you connected the relay to the 3.5v pin not the 5v one? The relay spec says 5v.

Like to try this myself!

Thanks.
That's a good question. Don't know why. I remember I was following a tutorial over the Internet and that tutorial said to use the 3v3 pin. I wondered the same thing as you did but as you can see in the description of this board, it says that the voltage to control the board is between 3 and 15v so I thought it would have worked and so it did :)

Re: Rpi and relay to switch on/off lights

Posted: Tue Aug 20, 2013 9:41 pm
by peewee2
a wee safety observation.

Electric shock kill, many years ago when I was an apprentice my boss caught me doing something potentially dangerous, a year later he died from an electric shock whilst working in his loft.

The questioner asked can he/she use this relay gizmo & a pi to control the lights (plural). The first question to ask is - do you mean fixed, mains powered house lights?

Exactly how do you use a single relay board to control house lights?

The practical answer is you can't, not unless you are going to run 1.5mm twin and earth cable all around the house, using a relay board to switch mains is potentially dangerous, the relay board needs to be in a suitable box securely fixed in a safe location, the cabling needs to be safely routed....

The only safe way to control lights is to use approved kit - such as the wireless light switches sold under the Home Easy brand.

Pete

Re: Rpi and relay to switch on/off lights

Posted: Tue Aug 20, 2013 9:55 pm
by Angelus88
peewee2 wrote:a wee safety observation.

Electric shock kill, many years ago when I was an apprentice my boss caught me doing something potentially dangerous, a year later he died from an electric shock whilst working in his loft.

The questioner asked can he/she use this relay gizmo & a pi to control the lights (plural). The first question to ask is - do you mean fixed, mains powered house lights?

Exactly how do you use a single relay board to control house lights?

The practical answer is you can't, not unless you are going to run 1.5mm twin and earth cable all around the house, using a relay board to switch mains is potentially dangerous, the relay board needs to be in a suitable box securely fixed in a safe location, the cabling needs to be safely routed....

The only safe way to control lights is to use approved kit - such as the wireless light switches sold under the Home Easy brand.

Pete
Pete I really appreciate your security advices and warnings.
Till now, I'm just using this relay to switch off/on my flatbed scanner and just once I tried to switch off/on a little lamp like this one and it worked:

Image

Re: Rpi and relay to switch on/off lights

Posted: Thu May 29, 2014 5:01 pm
by [avi]
dugongmoladive wrote:Hello,

I'm using Fotek SSR to do the trick. They come in several different flavor. Do check your power requirement before getting one.

Although the datasheet says it accepts 3-32VDC on the input pins, my rev 2 board doesn't have enough juice to power it directly from the GPIO (maybe not enough power on the PSU). So I end up creating an open collector circuit with NPN transistor with 5v from the power rail on the collector side. You can also use MOSFET to do this, but NPN BC547 is what I have lying around. With 5v on the SSR's input side, it works like a charm.
This SSR is pretty cheap, around 10 bucks each. So google around if you decide to buy one.

Just make sure you double/triple check all the connections before you test it with life AC current.
Can you explain bit more why did you use transistor?

Re: Rpi and relay to switch on/off lights

Posted: Fri Oct 17, 2014 9:52 pm
by Mistertee
Be very careful when dealing with mains voltages. Use a Power Tail Switch (from USA) or Mains Switch Widget (from UK). These take care of all the safety issues. The UK product has a fuse as well to prevent fires.

Re: Rpi and relay to switch on/off lights

Posted: Wed Oct 29, 2014 9:15 am
by sharpy110
www.denkovi.com have relay boards to suit Rpi, just search the website for Raspberry to find them. They are in Bulgeria, but I have bought a couple of Windows/Linux boards which are easy to use & work fine. My Rpi compatible board is in transit. Can`t wait!

Re: Rpi and relay to switch on/off lights

Posted: Thu Nov 06, 2014 7:54 am
by marosi
Here is a tutorial very interesting and not requires special technical knowledge

http://www.instructables.com/id/Home-Au ... -Phidgets/

Re: Rpi and relay to switch on/off lights

Posted: Mon Apr 16, 2018 4:11 am
by PratUshh
I almost killed my pi. Due to some noobish wiring.Found this https://www.youtube.com/watch?v=iF-cOppShQE , hope it helps :)

Re: Rpi and relay to switch on/off lights

Posted: Mon Apr 16, 2018 10:57 pm
by DougieLawson
PratUshh wrote:
Mon Apr 16, 2018 4:11 am
Due to some noobish wiring
You can say that again. Why would anyone use RED for GND and BLACK for Vcc unless they're planning to break things? Didn't watch beyond the first minute because of that.

Re: Rpi and relay to switch on/off lights

Posted: Tue Apr 17, 2018 10:25 am
by Burngate
Apart from agreeing with Dougie, in the US, apparently, Live is Black with Neutral White. So he almost got half of it right.
https://www.allaboutcircuits.com/textbo ... fographic/

It's worth noting that Red for Live & Green Earth isn't such a good idea since those two are the most easily confused by the colour-blind.
(In Britain at least) males are more likely to be colour-blind, and more likely to be electricians. The solution is to train more female electricians (or shoot the male ones)