Switching an appliance on and off
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.
Re: Switching an appliance on and off
+1
It'd be really great to see some instructions (circuit diagrams) on driving relays with the pi
It'd be really great to see some instructions (circuit diagrams) on driving relays with the pi
Dear forum: Play nice 

Re: Switching an appliance on and off
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.
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.
Re: Switching an appliance on and off
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.
That takes care of the hardware. Plug and play.

Check out our raspberry pi addons: https://www.bitwizard.nl/shop/
Re: Switching an appliance on and off
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.
I adapted the instructable to use a netduino and it should be possible to easily do the same from a pi.
- mahjongg
- Forum Moderator
- Posts: 14573
- Joined: Sun Mar 11, 2012 12:19 am
- Location: South Holland, The Netherlands
Re: Switching an appliance on and off
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.
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.

Re: Switching an appliance on and off
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)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.
Dear forum: Play nice 

Re: Switching an appliance on and off
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
Lesson:
http://venus.ece.ndsu.nodak.edu/~glower ... Switch.pdf
Example on page 2:
http://venus.ece.ndsu.nodak.edu/~glower ... olve04.pdf
- gordon@drogon.net
- Posts: 2024
- Joined: Tue Feb 07, 2012 2:14 pm
- Location: Devon, UK
Re: Switching an appliance on and off
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!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.
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/
Gordons projects: https://projects.drogon.net/
Re: Switching an appliance on and off
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!abishur wrote: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)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.

Dear forum: Play nice 

Re: Switching an appliance on and off
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.
You do have to be careful to find one which has Linux drivers available.
Re: Switching an appliance on and off
It's amazing how safest can rhyme with "most boring", "most expensive", and "least satisfactory" all at the same timebredman 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.

Dear forum: Play nice 

Re: Switching an appliance on and off
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.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 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
Re: Switching an appliance on and off
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
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
Re: Switching an appliance on and off
Just for the record, that's the conclusion I had come to as wellElApe 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

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 

-
- Posts: 59
- Joined: Wed May 16, 2012 2:00 pm
Re: Switching an appliance on and off
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 ?
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 ?
Re: Switching an appliance on and off
I am nowwallacebiy wrote: Jake , are you here ?

_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).
-
- Posts: 59
- Joined: Wed May 16, 2012 2:00 pm
Re: Switching an appliance on and off
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 ....
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 ....
-
- Posts: 48
- Joined: Tue Jan 17, 2012 1:42 pm
Re: Switching an appliance on and off
I posted to a similar query about controlling a/c stuff here: http://www.raspberrypi.org/phpBB3/viewt ... 31#p100031.
Re: Switching an appliance on and off
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.
Re: Switching an appliance on and off
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.
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.
Re: Switching an appliance on and off
2000W? Yikes!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.

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 

Re: Switching an appliance on and off
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.
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.
Re: Switching an appliance on and off
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.
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.
Re: Switching an appliance on and off
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
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