jonno
Posts: 1
Joined: Mon May 28, 2012 9:28 am

Switching an appliance on and off

Fri Jun 08, 2012 2:38 pm

Is there a simple way I could use the Pi as a switch to on/off an standard 240volt appliance? I'm pretty sure I could write the script and control it with an installed webserver but the electronics part would be far beyond me. It wouldn't need to be wired directly to the appliance, just switching on and off at the wall socket (or equivalent) would be plenty.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Fri Jun 08, 2012 3:02 pm

+1

It'd be really great to see some instructions (circuit diagrams) on driving relays with the pi
Dear forum: Play nice ;-)

domesday
Posts: 258
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK

Re: Switching an appliance on and off

Fri Jun 08, 2012 4:03 pm

It would be a very simple thing to do, essentially you need to ensure that the Raspberry Pi is isolated from the electrical device. If you want to have it switched on/off for long periods the best thing would be to use a latching relay. If you want to be able to turn it on and off a lot like flash some disco lights you would generally use an opto-isolator and triac.

Thinking about it, you could probably do it wirelessly, by using one of those wireless mains switches. This sort of thing http://www.toolstation.com/shop/p97425 Could pull apart the remote and use one of the GPIO ports on the Pi to simulate pressing the button.

User avatar
rew
Posts: 423
Joined: Fri Aug 26, 2011 3:25 pm

Re: Switching an appliance on and off

Sat Jun 09, 2012 8:50 pm

You could get our spi_relay board and connect it to the rpi_serial board.

That takes care of the hardware. Plug and play. :-) You can of course do either or both of these boards yourself.
Check out our raspberry pi addons: https://www.bitwizard.nl/shop/

emg
Posts: 88
Joined: Wed Jan 11, 2012 11:01 pm

Re: Switching an appliance on and off

Sun Jun 10, 2012 12:36 am

I've taken a different tack using a netduino and HomeEasy automation 433Mhz wireless. See: http://www.instructables.com/id/Arduino ... utomation/

I adapted the instructable to use a netduino and it should be possible to easily do the same from a pi.

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

Re: Switching an appliance on and off

Mon Jun 11, 2012 12:16 am

Seems like a job for a photo-triac, like this one from farnell:
http://nl.farnell.com/isocom/is6015x/op ... dp/1683237

Just be extremely careful to separate the low voltage (LED side) from the high voltage (mains, triac) side, but this way you can directly control low wattage mains powered equipment, directly from a GPIO pin.

Read the datasheet of the device, and at least the wikipedia article, before proceeding:
http://en.wikipedia.org/wiki/Opto-isola ... -isolators

But if you are uncertain about anything, read this too:
http://www.vishay.com/docs/84780/phototri.pdf


Needless to say, always be extremely careful with mains voltages. :ugeek:

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Mon Jun 11, 2012 3:56 am

mahjongg wrote:Seems like a job for a photo-triac, like this one from farnell:
http://nl.farnell.com/isocom/is6015x/op ... dp/1683237

Just be extremely careful to separate the low voltage (LED side) from the high voltage (mains, triac) side, but this way you can directly control low wattage mains powered equipment, directly from a GPIO pin.

Read the datasheet of the device, and at least the wikipedia article, before proceeding:
http://en.wikipedia.org/wiki/Opto-isola ... -isolators

But if you are uncertain about anything, read this too:
http://www.vishay.com/docs/84780/phototri.pdf


Needless to say, always be extremely careful with mains voltages. :ugeek:
I just want to make sure I'm reading this right, but basically this device performs the same function as an optic relay, but it can be driven from 10mA (which I *think* I saw a document Gert put out said the gpio pins can be told to put out 10 mA). In which case I can put my mains power on the high voltage side of this chip and the gpio on the other and everything is happy without anything else? (Well I say that, but I'd probably still want to put a diode on the GPIO pin going to the chip, and a resistor on the pin coming back from the chip)
Dear forum: Play nice ;-)

phrasz
Posts: 46
Joined: Fri Jun 01, 2012 4:13 am

Re: Switching an appliance on and off

Mon Jun 11, 2012 4:52 am

I was educated on, and forever will use, Transistor switches:
Lesson:
http://venus.ece.ndsu.nodak.edu/~glower ... Switch.pdf
Example on page 2:
http://venus.ece.ndsu.nodak.edu/~glower ... olve04.pdf

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Switching an appliance on and off

Mon Jun 11, 2012 12:46 pm

jonno wrote:Is there a simple way I could use the Pi as a switch to on/off an standard 240volt appliance? I'm pretty sure I could write the script and control it with an installed webserver but the electronics part would be far beyond me. It wouldn't need to be wired directly to the appliance, just switching on and off at the wall socket (or equivalent) would be plenty.
There are several simple ways - however you must not forget that you're dealing with mains voltages and currents here - and these can be lethal not just to the Pi, but to yourself!

So 2 direct approaches that I'd use (and have used, but not yet on a Pi) are relays. Firstly good old fashioned mechanical relay devices - the down-side is that the Pi will not drive these directly, you'll need some sort of driver chip - e.g. something like the ULN2003 series, the other (direct) way is to use the modern equivalent; solid-state relays and these work via an internal opto-isolator. These are my prefered way to drive mains power, but again, be very careful as you'll have mains voltages on the same board as the signal voltages. You can do it on stripboard, but do lift the tracks in-between the mains side and the low-voltage side.

The solid state ones I use are: http://uk.rs-online.com/web/p/solid-sta ... s/2912371/ these can be driven directly from the 3.3v output of the Pi. The advantage of these is that they have built-in zero-cross detectors, so shouldn't produce any switching glitches/spikes/noise.

Good luck and do take care - check and double-check everything before initial turn-on!

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Mon Jun 11, 2012 2:23 pm

abishur wrote:
mahjongg wrote:Seems like a job for a photo-triac, like this one from farnell:
http://nl.farnell.com/isocom/is6015x/op ... dp/1683237

Just be extremely careful to separate the low voltage (LED side) from the high voltage (mains, triac) side, but this way you can directly control low wattage mains powered equipment, directly from a GPIO pin.

Read the datasheet of the device, and at least the wikipedia article, before proceeding:
http://en.wikipedia.org/wiki/Opto-isola ... -isolators

But if you are uncertain about anything, read this too:
http://www.vishay.com/docs/84780/phototri.pdf


Needless to say, always be extremely careful with mains voltages. :ugeek:
I just want to make sure I'm reading this right, but basically this device performs the same function as an optic relay, but it can be driven from 10mA (which I *think* I saw a document Gert put out said the gpio pins can be told to put out 10 mA). In which case I can put my mains power on the high voltage side of this chip and the gpio on the other and everything is happy without anything else? (Well I say that, but I'd probably still want to put a diode on the GPIO pin going to the chip, and a resistor on the pin coming back from the chip)
To answer my own question, it looks like the answer is no. From what I've been reading, on the high voltage side, the opto-isolator would connect to a triac which would close the circuit for running mains voltage. An SSR is something I'm far more comfortable with, but it's also a lot more expensive, I'd rather figure out how to use the opto-isolator! :-P
Dear forum: Play nice ;-)

bredman
Posts: 1415
Joined: Tue Jan 17, 2012 2:38 pm

Re: Switching an appliance on and off

Mon Jun 11, 2012 3:11 pm

The safest way is to buy a USB-connected relay board. Search the internet for "USB relay 220v", here is just one example http://www.electronic-software-shop.com ... are/relay/

You do have to be careful to find one which has Linux drivers available.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Mon Jun 11, 2012 3:29 pm

bredman wrote:The safest way is to buy a USB-connected relay board. Search the internet for "USB relay 220v", here is just one example http://www.electronic-software-shop.com ... are/relay/

You do have to be careful to find one which has Linux drivers available.
It's amazing how safest can rhyme with "most boring", "most expensive", and "least satisfactory" all at the same time :-P
Dear forum: Play nice ;-)

SteveOll
Posts: 9
Joined: Tue Jun 05, 2012 6:48 pm

Re: Switching an appliance on and off

Mon Jun 11, 2012 9:15 pm

bredman wrote:The safest way is to buy a USB-connected relay board. Search the internet for "USB relay 220v", here is just one example http://www.electronic-software-shop.com ... are/relay/

You do have to be careful to find one which has Linux drivers available.
I use a LabJack U3-HV DAQ to interface with my Raspberry Pi to control electronics and I also use an opto-isolated 8 relay board, Contact ratings 10A/240VAC/8A 30VDC (GEN8PRMx-LJ: http://www.easydaq.biz) which is powered via the LabJack's DB15 connector and straight from a non-powered USB hub draws a max of 350mA when all eight relays are active.

I control the relay board via the LabJack using Python 2.x

The same board can also be used with an Arduino!

Or you could use a MOSFET, e.g. a BUZ11 or similar and as long as the Raspberry Pi can output the required Gate Threshold voltage, that can switch large voltage/currents although you may need a large heatsink or cooling fan combination with it.

-Steve

ElApe
Posts: 2
Joined: Tue Jan 10, 2012 5:48 pm

Re: Switching an appliance on and off

Tue Jun 12, 2012 12:00 am

Depends what you want to switch on and off really, if you are looking at switching higher current loads I would use an opt-isolated triac to drive the gate on a 2nd higher current Triac which actually controls your load.

In the past I have used the Texas MOC-3020 optos to drive another Triac switching a 20A load.

http://www.micropik.com/PDF/moc3020.pdf

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Tue Jun 12, 2012 3:20 am

ElApe wrote:Depends what you want to switch on and off really, if you are looking at switching higher current loads I would use an opt-isolated triac to drive the gate on a 2nd higher current Triac which actually controls your load.

In the past I have used the Texas MOC-3020 optos to drive another Triac switching a 20A load.

http://www.micropik.com/PDF/moc3020.pdf
Just for the record, that's the conclusion I had come to as well :-)

I plan on using the moc3010m with the STMicroelectronics BTA12-600BRG. I'm going to get 6 of them to drive my 24V AC sprinkler solenoids and 1 as a switch to open my garage door (120V AC)

The deciding factor for me was the realization that using an opto-coupler with a triac is pretty much what an SSR is (well one type of SSR at any rate), so all I'm doing is making my own SSR in essence... for a pittance of the price!
Dear forum: Play nice ;-)

wallacebiy
Posts: 59
Joined: Wed May 16, 2012 2:00 pm

Re: Switching an appliance on and off

Tue Jun 12, 2012 2:12 pm

this Piqued my interest , so I did a little digging

found this , which may or may not be helpful

http://www.jakebyrne.com/adding-web-con ... -hardware/





Hahaha
And if you go to the part 2 of that It's a Rasperry Pi He's using to run a web server to control it from !!

Jake , are you here ?

jakebyrne
Posts: 2
Joined: Tue Jun 12, 2012 3:12 pm

Re: Switching an appliance on and off

Tue Jun 12, 2012 3:30 pm

wallacebiy wrote: Jake , are you here ?
I am now :)

_my method isn't exactly trivial_, but if you're not afraid to do a little soldering and processor programming it should be manageable. I suppose the benefit of the approach I took is that you can control a number of devices and they don't need to be co-located with the Raspberry Pi, and it's all done safely (as wallace highlighted).

You could extend my approach so that you remove the Atmega8 and the USB cable by using the GPIO pins on the Pi instead, the reason I went with the Atmega8 and USB is that it's now compatible with a range of servers and not just the Raspberry Pi.

I'd be interested in seeing a version of this that was built exclusively for the Raspberry Pi, I'd be willing to help out where I can, but I've limited time over the next few months (trying to finish up my PhD).

wallacebiy
Posts: 59
Joined: Wed May 16, 2012 2:00 pm

Re: Switching an appliance on and off

Tue Jun 12, 2012 9:02 pm

Jake ,
I think this could develop into a really handy way of controlling on off in a lot of setups .

I reckon it'll be handy in a brewery ....

http://www.raspberrypi.org/phpBB3/viewt ... 1&start=25

Switching on and off kettle elements and refrigerators ....

Michael Meissner
Posts: 48
Joined: Tue Jan 17, 2012 1:42 pm
Contact: Website

Re: Switching an appliance on and off

Thu Jun 14, 2012 12:28 pm

I posted to a similar query about controlling a/c stuff here: http://www.raspberrypi.org/phpBB3/viewt ... 31#p100031.

User avatar
RichardUK
Posts: 235
Joined: Fri Jun 01, 2012 5:12 pm

Re: Switching an appliance on and off

Thu Jun 14, 2012 1:33 pm

Search for X10 in Google. Old tech but lots of hardware. USB and serial protocol to a box that then sends control signals over the power line.

Zorkman
Posts: 1
Joined: Mon Dec 19, 2011 3:51 pm

Re: Switching an appliance on and off

Thu Jun 14, 2012 4:24 pm

This might be a trivial question, but would http://www.dealextreme.com/p/arduino-5v ... 54?item=20 be a SAFE and reliable method to switch an appliance ON/OFF (appliance will be 2000W)?

I'm hoping to just have to use the GPIO as digital 1/0 and maybe a 5V line from the usb?
I will also be connection a wireless USB key.

Thanks in advance.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Switching an appliance on and off

Thu Jun 14, 2012 5:21 pm

Zorkman wrote:This might be a trivial question, but would http://www.dealextreme.com/p/arduino-5v ... 54?item=20 be a SAFE and reliable method to switch an appliance ON/OFF (appliance will be 2000W)?

I'm hoping to just have to use the GPIO as digital 1/0 and maybe a 5V line from the usb?
I will also be connection a wireless USB key.

Thanks in advance.
2000W? Yikes! :shock: It depends on what the voltage is. If you're running off 120V @ 2000W that would be almost 17 Amps, the relay is only rated up to 10 A so it wouldn't work, but if it's 240, that would only 8 and a third Amps and it should be able to handle it

As for using the 5V to trigger your relay, how would you control it? I mean the 5V pin is an always on (so to speak). You'd have to do another relay or gate that would only let the 5 volts through whenever your gpio pin went high.
Dear forum: Play nice ;-)

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Switching an appliance on and off

Thu Jun 14, 2012 5:28 pm

I doubt that board is designed to switch those sorts of loads. If the load is inductive then you will get large back-emf when switching on and off. The relays may handle the current, but the back-emf may burn them out.

Also those relays are designed to be controlled by an arduino which outputs 5V at a significant current, while the RaspPi will only output 3.3V at a current so small that you would be hard-pressed to find a relay sensitive enough.

domesday
Posts: 258
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK

Re: Switching an appliance on and off

Thu Jun 14, 2012 8:37 pm

I think probably the best thing to say is this ...

The GPIO pins on the Raspberry Pi are only suitable for switching a transistor or at a push lighting a low powered LED. So if you want to connect anything more powerful such as a buzzer, relay or super bright LED you will need some sort of intermediate amplifier circuit.

This could be a simple transistor in the case of a relatively low power device such as a bright LED.
An inductive load like a relay would be better off with a darlington driver that are conveniently available in an IC such as the ULN2803.
To control a low voltage motor a Full Bridge Driver would be the best option as it can switch the high current.
When controlling mains voltages you will require either a relay or Triac connected via an optical isolator, connected via a darlington driver.

thexman
Posts: 259
Joined: Sat Apr 07, 2012 2:18 pm

Re: Switching an appliance on and off

Sun Jun 17, 2012 5:56 pm

once the foundation fix the USB data packets issue these Control cards / relay setups that currently work on windoz7 and Linux boxes and Mac Pc's even a Ipad if you want it. see blog posts Http://www.yoctopuce.com

i had the idea for an 8 way board because my customers all had multiple outputs needing switching so 8 was a logical solution the Maxi-relay device
one armed controls engineer, my grammar is bad but lets face it most keyboards don't suit a one armed man

Return to “Automation, sensing and robotics”