User avatar
RaspberryPiBeginners
Posts: 218
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
Contact: Website

How can you use a pi to controlled a mains switch

Fri Sep 07, 2012 7:40 pm

I was wondering if it's possible to use a pi to controlled a mains powered device. For example a lamp or fan? if so does anyone know of any good online guides :D
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD

User avatar
jecxjo
Posts: 158
Joined: Sat May 19, 2012 5:22 pm
Location: Minneapolis, MN (USA)

Re: How can you use a picture to controlled a mains switch

Fri Sep 07, 2012 8:43 pm

You're looking for a Relay Switch to break the mains power and keep yourself isolated. Here is a consumer product that skips all the wiring and just gives you Mains in/out and some pins to switch it.

http://www.powerswitchtail.com/Pages/default.aspx
xmpp: [email protected]
Blog: http://jecxjo.motd.org/code

User avatar
RaspberryPiBeginners
Posts: 218
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
Contact: Website

Re: How can you use a picture to controlled a mains switch

Sat Sep 08, 2012 7:31 pm

Anything UK based?
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD

sipos
Posts: 9
Joined: Thu Sep 06, 2012 9:27 pm

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 4:29 am

I'm looking for something similar but, the link posted isn't suitable for what I need as I need it to control a 240V (UK mains plug) device. If anyone knows of anything suitable, I'd be very grateful for a link.

User avatar
RaspberryPiBeginners
Posts: 218
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
Contact: Website

Re: How can you use a pi to controlled a mains switch

Sun Sep 09, 2012 9:09 am

Just realized what I called this post. I dang auto correct
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD

User avatar
Bencom
Posts: 56
Joined: Wed Mar 07, 2012 10:40 pm
Location: New Zealand
Contact: Website

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 10:28 am

I use relays like this on the RPI...
http://arduino-direct.com/sunshop/index ... tail&p=181

I am using a 4 relay unit for development at the moment.
Search out the gpio package on the wiki, build and install.
All is needed is to set the port pin to output to turn on relays and set back to input to turn off.
Pull 5v from the gpio connector. The relays switch fine. I think when switched to output, pull up on the pins is enabled hence one only needs to toggle between input and output to switch.

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 5:19 pm

Its simple take a maplins remote control plug,
http://www.maplin.co.uk/remote-controll ... ack-348217
plus a 433mhz trannsmiter
http://www.maplin.co.uk/rf-transmitter- ... les-267236

And check the forum for code, lot of people have done it.
Example:
https://github.com/dmcg/raspberry-strogonanoff
Batteries not included, Some assembly required.

ambi dextrous
Posts: 10
Joined: Sat Aug 18, 2012 1:48 pm

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 5:44 pm

Make sure the picture has a good solid heavy frame throw picture at switch. (Job Done) :lol:

sipos
Posts: 9
Joined: Thu Sep 06, 2012 9:27 pm

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 8:23 pm

Thanks for the replies.

I'm not sure I like the idea of using the relay. I was hoping for something where I wouldn't have to have anything to do with the mains power part myself other than plugging unmodified devices in. I'm just not that comfortable modifying something using mains power directly, even only connecting a relay like this (even though, conceptually, it isn't really that different to wiring a plug, something I am happy to do - it doesn't necessarily make sense that I'm not comfortable doing it myself).

Using the remote control switch and the RF transmitter to control it is fine. I'll probably do that. It does feel a bit hacky though.

I guess what I was hoping for is a ready made enclosed unit that plugs in, and has a socket to plug something else into, with ground, +5V and control pins to connect the low voltage circuit to, to switch on and off the socket. Basically, that someone would have made something that I could buy that already has a plug connected to a socket via something like the relay above all enclosed in a nice box so I don't have to play with anything wired directly to mains power myself.

User avatar
Bencom
Posts: 56
Joined: Wed Mar 07, 2012 10:40 pm
Location: New Zealand
Contact: Website

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 8:48 pm

Much nicer to say, "I made this".
Take the precautions. Do not power it up without putting it in a box.
Of course your countries laws may come into play.
Here we can for personal use in our own home I am pretty sure.

User avatar
Jim JKla
Posts: 2218
Joined: Sun Jan 29, 2012 11:15 pm
Location: Newcastle upon Tyne UK

Re: How can you use a picture to controlled a mains switch

Sun Sep 09, 2012 8:53 pm

Get one of those plugs that can be controlled by an ir remote then control the remote with the RPi that way your RPi has isolation via a ir link ;) the Maplin one is Rf just as viable.
Noob is not derogatory the noob is just the lower end of the noob--geek spectrum being a noob is just your first step towards being an uber-geek ;)

If you find a solution please post it in the wiki the forum dies too quick

User avatar
RaspberryPiBeginners
Posts: 218
Joined: Fri May 11, 2012 6:54 am
Location: Soham, Cambridgeshire
Contact: Website

Re: How can you use a pi to controlled a mains switch

Mon Sep 10, 2012 1:36 pm

Bencom your link http://arduino-direct.com/sunshop/index ... tail&p=181 is the closest to what I was after. Not sure if it's UK comparable. I very intresting
Click here for my unofficial YouTube Channel > http://goo.gl/oFYBD

0rphu
Posts: 38
Joined: Sun Oct 23, 2011 1:45 pm

Re: How can you use a pi to controlled a mains switch

Mon Sep 10, 2012 3:59 pm

I've been thinking about something similar, so far I'd like to build it with 433MHz transmitter and receiver, with HT12E and HT12D encoder and decoder. For the actual mains switching I'd like to use a triac circuit like this http://hmmtheresanidea.blogspot.sk/2008 ... ching.html. My problem is I need the "switch" to latch, because I don't want the transmitter on the Pi side to continuously transmit, just to keep the switch on, so I'll need some bistable circuit, maybe with NE555, or perhaps a simple bistable multivibrator.

That's my idea, anyway. If you have comments or improvements, let me know!

User avatar
Bencom
Posts: 56
Joined: Wed Mar 07, 2012 10:40 pm
Location: New Zealand
Contact: Website

Re: How can you use a pi to controlled a mains switch

Mon Sep 10, 2012 7:12 pm

RaspberryPiBeginners wrote:Bencom your link http://arduino-direct.com/sunshop/index ... tail&p=181 is the closest to what I was after. Not sure if it's UK comparable. I very intresting
Check out the ali express web site. You may be able to get one of quantities. Shipping may be your biggest obstacle. Some suppliers build in shipping (Free shipping to NZ, but as we know nothing is free).

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: How can you use a pi to controlled a mains switch

Thu Oct 04, 2012 11:58 am

I have a set of Morrisons (a UK supermarket) Status remote control mains sockets. Cost me a fiver with some petrol. I hooked a 433MHz transmitter to my PI, and can control all three sockets anywhere in the house. I'm half way through writing up a little web page on the project and will post a link on the forum when it's done.

No need to worry about working with the mains either, just a small transmitter and the sockets never need to be tampered with.

Dogga
Posts: 8
Joined: Mon Sep 17, 2012 3:50 pm

Re: How can you use a pi to controlled a mains switch

Fri Oct 05, 2012 3:33 pm

Hi.

Im currently in project in which I need to control three different lights and have them turn on and off in a sequence. I followed this topic and have everything I need to make it, but am just struggling with silly things like how to even connect the transmitter to Raspberry. Im a noob and would really appreciate some direction.

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: How can you use a pi to controlled a mains switch

Sun Oct 07, 2012 10:00 am

Here's how I did it.

http://www.hoagieshouse.com/RaspberryPi ... CPlug.html

I have 2 bedside lamps controlled by cron jobs now to come on just before Me and the Mrs need to wake up in the mornings.

Hoagie
Posts: 119
Joined: Sun Sep 23, 2012 7:19 pm

Re: How can you use a picture to controlled a mains switch

Wed Oct 10, 2012 2:51 pm

DexOS wrote:Its simple take a maplins remote control plug,
http://www.maplin.co.uk/remote-controll ... ack-348217
plus a 433mhz trannsmiter
http://www.maplin.co.uk/rf-transmitter- ... les-267236

And check the forum for code, lot of people have done it.
Example:
https://github.com/dmcg/raspberry-strogonanoff

Are you sure about that transmitter? It appears to be an FM type, while all of the sockets I've ever seen use very simple AM communications protocols.

yeahbox
Posts: 36
Joined: Sun May 27, 2012 10:35 pm
Location: Manchester, UK

Re: How can you use a pi to controlled a mains switch

Sat Oct 13, 2012 11:19 pm

No one in this thread has mentioned Telldus yet (http://telldus.se/) which is working really nice, I have a Tellstick duo connected to my raspi and I can turn on and off switches and also read temperatures from different temperature transmitters. So this would leave the hardware bit solved for you and you are left with the programming of your applications. There are many topics already about tellsticks, here is one: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=19681

User avatar
tand
Posts: 20
Joined: Sat Jul 14, 2012 7:56 am

Re: How can you use a pi to controlled a mains switch

Sun Oct 14, 2012 12:33 am

I have been running RF Bitbanger http://www.raspberrypi.org/phpBB3/viewt ... 37&t=11159 for several weeks now together with a python script that switches my exterior lighting on and off based on time and sunrise/sunset.
Soldering and kernel driver compilation could be a little bit tricky if you haven't done it before, otherwise its not very hard to do, and the component cost is reasonable.
Be nice to your fellow threads!

AshP
Posts: 10
Joined: Mon Oct 22, 2012 10:38 pm

Re: How can you use a pi to controlled a mains switch

Tue Oct 23, 2012 9:13 pm

Tand, where do you download sunrise/sunset times from?

fatcinco
Posts: 26
Joined: Tue May 15, 2012 4:50 am
Contact: Website

Re: How can you use a pi to controlled a mains switch

Wed Oct 24, 2012 3:23 am

Lots of programming languages have built in functions to get the sunset/sunrise. Php for example is date_sunset.

Example: http://thomasloughlin.com/z-wave-open-zwave-update/

Michael-H
Posts: 2
Joined: Thu Oct 25, 2012 8:44 pm

Re: How can you use a picture to controlled a mains switch

Thu Oct 25, 2012 9:00 pm

I'm probably doing something really stupid, but when I follow these instructions...
DexOS wrote: And check the forum for code, lot of people have done it.
Example:
https://github.com/dmcg/raspberry-strogonanoff
...it all seems to be going OK until...

Code: Select all

sudo python raspwitch.py --channel 1 --button 3 --gpio 8 on
...which causes this error:
Traceback (most recent call last):
File "raspwitch.py", line 71, in <module>
from WiringPin import WiringPin
ImportError: No module named WiringPin
Can anyone suggest where I'm going wrong? Thanks

sipos
Posts: 9
Joined: Thu Sep 06, 2012 9:27 pm

Re: How can you use a picture to controlled a mains switch

Fri Oct 26, 2012 4:02 am

Michael-H wrote: ...it all seems to be going OK until...

Code: Select all

sudo python raspwitch.py --channel 1 --button 3 --gpio 8 on
...which causes this error:
Traceback (most recent call last):
File "raspwitch.py", line 71, in <module>
from WiringPin import WiringPin
ImportError: No module named WiringPin
Can anyone suggest where I'm going wrong? Thanks
The error means that the module called WiringPin(.py) is not installed or, not in one of the directories listed in your PYTHONPATH environment variable. Unless you've heard of this module before, I'd guess you don't have it installed so, you need to download it and install it (into a location that is in your PYTHONPATH when you run the script). I googled it quickly and couldn't find a module called WiringPin but, found lots of references to WiringPi so, perhaps it's a typo in the script or, perhaps WiringPin.py is a file included with the script that needs to be downloaded and installed or perhaps it was renamed or something. I'd checkout the documentation for the script and see if it mentions any dependancies or contact the author and ask if you can't track down the module.

LesTroyer
Posts: 14
Joined: Wed Aug 29, 2012 2:38 pm

Re: How can you use a pi to controlled a mains switch

Fri Oct 26, 2012 2:42 pm

there are a lot of X10 or zigbee products out there that you can interface to with RS232. That keeps you out of the high voltage stuff that can be fatal.

Les

Return to “Automation, sensing and robotics”