Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Rpi and relay to switch on/off lights

Mon May 13, 2013 12:45 pm

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 ;)
Last edited by Angelus88 on Tue May 14, 2013 2:13 pm, edited 1 time in total.

rooster1
Posts: 17
Joined: Tue Feb 12, 2013 8:55 pm

Re: Rpi and reley to switch on/off lights

Tue May 14, 2013 11:35 am

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

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and reley to switch on/off lights

Tue May 14, 2013 2:13 pm

Well... so it doesn't matter if the relay is 5v and the gpio pin is 3,3v?

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: Rpi and relay to switch on/off lights

Tue May 14, 2013 2:27 pm

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
http://www.pieter-jan.com/

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Tue May 14, 2013 2:37 pm

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.

User avatar
penguintutor
Posts: 390
Joined: Tue May 08, 2012 9:11 am
Location: UK
Contact: Website

Re: Rpi and relay to switch on/off lights

Tue May 14, 2013 3:26 pm

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.

User avatar
Mortimer
Posts: 926
Joined: Sun Jun 10, 2012 3:57 pm

Re: Rpi and relay to switch on/off lights

Tue May 14, 2013 4:00 pm

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.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
Sarge
Posts: 34
Joined: Sun Jan 13, 2013 4:57 pm

Re: Rpi and relay to switch on/off lights

Tue May 14, 2013 5:10 pm

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

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Wed May 15, 2013 9:00 am

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

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: Rpi and relay to switch on/off lights

Wed May 15, 2013 9:04 am

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.
http://www.pieter-jan.com/

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Wed May 15, 2013 9:11 am

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

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Mon May 20, 2013 11:40 pm

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 ;)

dugongmoladive
Posts: 3
Joined: Tue Jun 11, 2013 7:47 am

Re: Rpi and relay to switch on/off lights

Tue Jun 11, 2013 8:08 am

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.
Attachments
fotek-ssr-25-da-solid-state-role.jpg
fotek-ssr-25-da-solid-state-role.jpg (40.26 KiB) Viewed 82393 times

ruffinmedia
Posts: 32
Joined: Sat May 11, 2013 11:43 am

Re: Rpi and relay to switch on/off lights

Wed Jul 24, 2013 11:31 pm

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.

talkeasy
Posts: 38
Joined: Sun Nov 04, 2012 10:57 pm

Re: Rpi and relay to switch on/off lights

Tue Aug 20, 2013 8:31 am

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.

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Tue Aug 20, 2013 9:01 pm

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 :)

peewee2
Posts: 82
Joined: Sun Apr 14, 2013 7:04 pm

Re: Rpi and relay to switch on/off lights

Tue Aug 20, 2013 9:41 pm

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

Angelus88
Posts: 442
Joined: Mon May 13, 2013 9:25 am
Location: Ivrea, TO (Italy)

Re: Rpi and relay to switch on/off lights

Tue Aug 20, 2013 9:55 pm

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

[avi]
Posts: 56
Joined: Mon Dec 10, 2012 3:00 pm

Re: Rpi and relay to switch on/off lights

Thu May 29, 2014 5:01 pm

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?

Mistertee
Posts: 24
Joined: Tue Aug 13, 2013 6:43 am

Re: Rpi and relay to switch on/off lights

Fri Oct 17, 2014 9:52 pm

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.

sharpy110
Posts: 1
Joined: Wed Oct 29, 2014 9:07 am

Re: Rpi and relay to switch on/off lights

Wed Oct 29, 2014 9:15 am

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!

marosi
Posts: 5
Joined: Mon Oct 27, 2014 2:35 pm

Re: Rpi and relay to switch on/off lights

Thu Nov 06, 2014 7:54 am

Here is a tutorial very interesting and not requires special technical knowledge

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

PratUshh
Posts: 9
Joined: Sun Apr 15, 2018 2:37 pm

Re: Rpi and relay to switch on/off lights

Mon Apr 16, 2018 4:11 am

I almost killed my pi. Due to some noobish wiring.Found this https://www.youtube.com/watch?v=iF-cOppShQE , hope it helps :)

User avatar
DougieLawson
Posts: 40251
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Rpi and relay to switch on/off lights

Mon Apr 16, 2018 10:57 pm

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.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

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

Re: Rpi and relay to switch on/off lights

Tue Apr 17, 2018 10:25 am

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)

Return to “Automation, sensing and robotics”