cdduvall
Posts: 9
Joined: Sun Jun 02, 2013 12:44 am

HELP! Please help me turn on/off a light with RPI

Fri Jan 24, 2014 3:54 am

What I am trying to do is integrate a Raspberry PI into a lamp in my living room. If someone would be so kind as to tell me how to just turn a light on or off using the gpio pins I would be very greatful. My goal is to have a raspberry pi plugged in next to a lamp, so that I can just remote into my Raspberry Pi and issue a command to turn the lamp on or off. Keep in mind I just want to keep this simple, no relays, nothing complicated. I don't have alot of money, I just want to be able to start with a command, and later I will write an android app to remote into my android pi to turn the lamp on or off. I'll give you a scenario of why this would be useful: You just got home from work, and it is already dark, and the only lighting in your living room, is around a couch or coffee table and you don't want to trip over your furniture, so you arrive at your house. Pull out your smartphone, connect to your wifi, and execute your smartphone app that remotes into your raspberry pi, and turns on your lamp in the living room. TADA! Now you can see without falling and breaking your leg. I would just like some advice on how to turn on a lamp using the GPIO pins in the simplest way possible. Any other home automation, I can figure out after I learn how to turn one lamp on with the GPIO pins. Thank you.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: HELP! Please help me turn on/off a light with RPI

Fri Jan 24, 2014 5:38 am

Assuming you are in the US (so you have US-style electrical outlets) I found this:
http://www.adafruit.com/products/268

I have never used one, and unfortunately it's out of stock, but it illustrates what you need to do what you want. You can make one yourself from parts, but if you are new to the game you might want something like this which is mostly complete.

As you can see, the power cord has a plug at one end and a socket at the other. You would disconnect your lamp from the wall outlet and plug this thing in instead, then plug the lamp into the other end. The plastic blob in the middle contains a solid-state relay, which breaks the supply wire from one end to the other. On the edge of the relay are some screw terminals. You need to connect one terminal to GND on the Pi, and another to a GPIO line on the Pi (so you need some wires that you can plug on to the GPIO header). Then you can use software on the Pi to turn the GPIO on and off, which will turn the relay on and off, which will turn the light on and off.

Since it's out of stock you can make one yourself by buying a solid state relay and cutting a power extension cord in half and rewiring it, but you must have confidence to do this, and you must have experience in making safe connections to mains-operated equipment. Maybe you could email adafruit and ask when it will be restocked, or try and find another supplier.

Good luck.

txt3rob
Posts: 365
Joined: Sat Aug 11, 2012 3:45 pm
Contact: Website

Re: HELP! Please help me turn on/off a light with RPI

Fri Jan 24, 2014 3:33 pm

check out http://www.github.com/txt3rob/RPI-Control/ if you are uk based.
The Raspberry Pi Hell Guy - Random Ramblings to assist me and others.
http://raspberrypihell.blogspot.com
My Github - http:/www.github.com/random-robbie/
http://www.smspi.co.uk - send free uk sms via your raspberry pi from here

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

Re: HELP! Please help me turn on/off a light with RPI

Fri Jan 24, 2014 5:12 pm

I use solid state relays for controlling 120-240 volt lights, etc.

The SSR input (3-30 volts) can be connected directly the the GPIO pins without any interfacing hardware.
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
mahjongg
Forum Moderator
Forum Moderator
Posts: 13366
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: HELP! Please help me turn on/off a light with RPI

Fri Jan 24, 2014 6:28 pm

Photo-TRIAC (opto-isolator) controlling a power TRIAC, using the correct configuration (as found in dimmers etc), like this:
Image

But be very careful, mains electricity is not to toy with.

josar
Posts: 44
Joined: Sun Jan 19, 2014 1:29 am

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 12:56 am

I'm always using relay boards from ebay, e.g. http://www.ebay.com/itm/1pcs-5V-2-Chann ... 417978de87

It works directly with RPi, you just need 4 jumper cables and you can switch the relay on and off. If you can wire up your lamp to the relay, you can control it with your RPi.

cdduvall
Posts: 9
Joined: Sun Jun 02, 2013 12:44 am

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 1:00 am

Thank you josar you provided me with the exact answer I was looking for.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 1:51 am

Ok, but you did specify "no relays" originally.

It looks like this is the same device:
http://dx.com/p/2-channel-5v-relay-modu ... arm-265936

And this one:
http://www.sainsmart.com/arduino-compat ... -mini.html

The sainsmart link is handy as it includes this schematic:
http://www.sainsmart.com/media/catalog/ ... nnel__.jpg

You can see that in order to turn the relay 'on' you need to set GPIO to 0 (which is the opposite to what you might expect).

The 8-channel version of this board is also discussed here:
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=19222

But the information applies just as well to the 2-channel board.

You will have to cut open a mains extension cord and cut the 'hot' line, strip some insulation from the cut ends and insert them into the screw terminals on the relay board. Then you really *must* install the relay board into a plastic enclosure. Mains power is dangerous, and you should ensure that no-one can touch the exposed mains connections (the screw terminals and solder pads on the relay board) when it is in use.

cdduvall
Posts: 9
Joined: Sun Jun 02, 2013 12:44 am

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:12 am

Actually I did request a "no relay" way to do this...yet like setting the GPIO to 0 I got everything but what I expected. :D No big deal. I now have several ways to do what I originally set out to do. Brainstorming is limitless once you introduce foreign influences. Thank you to all who have and will continue to make contributions to this idea.

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

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 3:01 am

mahjongg wrote:Photo-TRIAC (opto-isolator) controlling a power TRIAC, using the correct configuration (as found in dimmers etc), like this:
Image

But be very careful, mains electricity is not to toy with.

What you have basically done is make your own SSR but without the zero crossing switching.
Image
Zero Crossing Solid State Relay
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

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 3:06 am

Richard-TX wrote:
mahjongg wrote:Photo-TRIAC (opto-isolator) controlling a power TRIAC, using the correct configuration (as found in dimmers etc), like this:
Image

But be very careful, mains electricity is not to toy with.

What you have basically done is make your own SSR but without the zero crossing switching.
Image
Zero Crossing Solid State Relay
U1 includes a zero-crossing detector.

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

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 1:51 pm

ame wrote:Ok, but you did specify "no relays" originally.

It looks like this is the same device:
http://dx.com/p/2-channel-5v-relay-modu ... arm-265936

And this one:
http://www.sainsmart.com/arduino-compat ... -mini.html

The sainsmart link is handy as it includes this schematic:
http://www.sainsmart.com/media/catalog/ ... nnel__.jpg

You can see that in order to turn the relay 'on' you need to set GPIO to 0 (which is the opposite to what you might expect).

The 8-channel version of this board is also discussed here:
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=19222

But the information applies just as well to the 2-channel board.

You will have to cut open a mains extension cord and cut the 'hot' line, strip some insulation from the cut ends and insert them into the screw terminals on the relay board. Then you really *must* install the relay board into a plastic enclosure. Mains power is dangerous, and you should ensure that no-one can touch the exposed mains connections (the screw terminals and solder pads on the relay board) when it is in use.
be very cautious with these modules, as unfortunately they are ALL seem to be designed to be driven by a 5V signal, as from an Arduino. The schematic of the Sainsmart device is handy to see why that is, as you can see it has TWO LED's in series in the input circuit, and as a typical (red) LED needs 2.0V to turn on this means that the input needs at least 4V! at least, that is the theory.

unfortunately the schematic of my SSR also incorporates an indicator LED, but you can bypass or leave it out. If you need an indicator LED, simply put a suitable resistor in series, and connect it in parallel with the SSR input, instead of in series.

You could also bypass the LED in the Sainsmart modules, but most often the LED is in Surface Mount Technology (SMT) , what probably makes it more difficult to do, and you need to know how to solder, which is what many people try to avoid, its the reason why they want to buy those ready made modules in the first place!

And yes, "my" circuit is exactly what you would find in many ready made SSR's except it is probably cheaper.

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

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:00 pm

ame wrote:
U1 includes a zero-crossing detector.
Wow. Learn something new every day.

Thanks for the heads up.

Richard
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
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:05 pm

mahjongg wrote:
And yes, "my" circuit is exactly what you would find in many ready made SSR's except it is probably cheaper.
That is likely true. Someone has to pay for packaging, UL/CE certifications, potting compound, etc.

In addition you know what you are getting. There has been a fair amount of people that have found the chinese made SSRs to be sub-standard.


What exactly is U1? I did not see the part number on the schematic.
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
mahjongg
Forum Moderator
Forum Moderator
Posts: 13366
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:17 pm

there are many, but one of the most affordable ones is the IS6010XSM, however that one needs 50mA LED current, and more importantly it doesn't do zero crossing. One of the cheapest suitable ones for this purpose (at about one euro) is the Sharp PC3SD21NTZBF.

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

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:33 pm

I found the PC3SD21NTZBF at Digikey. $0.96 in single lot quantities. 10 of them will cost $8.00

The BTA08-400 costs $1.32 single lots. 25 pcs are $26
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
mahjongg
Forum Moderator
Forum Moderator
Posts: 13366
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: HELP! Please help me turn on/off a light with RPI

Sun Jan 26, 2014 2:48 pm

The BTA08-400 is only an example, another suitable 8A triac would be the BT137-600 and it's only 70 cent or so.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: HELP! Please help me turn on/off a light with RPI

Mon Jan 27, 2014 12:39 am

Well, although it's out of stock at Adafruit, the PowerSwitch Tail II is available from the PowerSwitchTail.com company:
http://www.powerswitchtail.com/

Only $29.95, it's a safely enclosed solid-state relay that needs only 3V at 3mA to actuate. It doesn't have a zero-crossing detector, but that's not necessary for turning a light on and off.

Return to “Automation, sensing and robotics”