111

I though about using the Raspberry Pi to switch on and off other electrical devices which unnecessary consume power in stand-by mode. In short, I'd like to control an AC socket or multiple sockets. How can one let the computer "push the button":

Image: CC-BY-SA 3.0 by Firstfreddy

The physical solution is a relay, but I don't want to build all on my own and play around with 220V and sparks when switching on and off ;-) By the way the Raspberry Pi requires 2 Watt in idle mode, so only using it as a switch to save energy might not make sense, so it should be usable for other purpose at the same time.

Jakob
  • 2,768
  • 5
  • 23
  • 22

14 Answers14

55

EDIT 2018

Years later and the hobbyist microelectronics community has exploded thanks to the like of cheap and power embedded computers, like Raspberry Pi. This caused mechanical relays that work direct of GPIO on 5/3.3V allot cheaper and easier to get.

You can get them as singles or premade (Bangood, Seeedstudio, Gearbest, eBay, etc) ranging from 4 to 48 "channels" I have even seen. These are much more compact size, very affordable, safe and easy to use.

enter image description here

# * * * WARNING * * * #

Switching mains involves interfacing with potentially lethal voltages. Due care and competence is required. Death is possible. YMMV. This paraphrases Russell McMahon's advice on Electrical Engineering


---Original Answer 2012---

Well you could use a Solid State Relay which is much smaller and easier to control than a mechanical relay (The big 12 volt ones used in automotive industry) , using an MCU or in this case Pi's GPIO pin.

enter image description here

You have to drive the input pin constantly to keep the relay on (just like a mechanical relay). So if something fails with that signal, then the power goes off. To avoid that you have to design another circuit that can sustain itself.

But you can get these pretty cheap on eBay and they are completely safe (isolated), so they won't blow up the Pi and do not require a lot of power to drive them, about 3~10mA. Just check the details before buying one. It is also worth noting they can heat up if you load them heavily (close to the maximum rating)

Piotr Kula
  • 17,336
  • 6
  • 66
  • 105
31

You could get one of these (RF) remote control power switches (Assuming you can find one suitable for your local power receptacles)

enter image description here

and hardwire the RPi to the remote. This has the advantage of being isolated and not requiring any mains wiring. You'd have to take into consideration the power consumption of the device if the goal is to save power.

John La Rooy
  • 12,005
  • 9
  • 48
  • 77
26

Both Adafruit and Spark fun sell an assembled device exactly for this purpose: The Power Switch Tail exists in several variants, fully assembled or as kit. The kit's assembly instruction (PDF) include schematics.

Jakob
  • 2,768
  • 5
  • 23
  • 22
EricH
  • 261
  • 3
  • 2
16

SainSmart sells Arduino relay modules (shields), they could also be used on Raspberries. There are different models (higher amperage, number of outputs, etc). For example SKU:20-018-100-FBA can be used for "equipment with a large current". And a useful article discussing Using the Raspberry Pi to Control AC Electric Power that mentions the SainSmart.

enter image description here

Sonia Hamilton
  • 261
  • 2
  • 4
10

You can get a certain power suply with a USB-Connection and control it with this http://sispmctl.sourceforge.net/ Debian/Raspian has the package sispmctl by default.

Stefan
  • 101
  • 2
6

Use a Telldus Tellstick!

It has many applications and supports sensors as well.

Code samples in many languages: https://github.com/telldus/telldus

A router which has an HTTP API to control the TellStick if you dont want to have it directly connected to the PI: http://www.dovado.com/index.php?option=com_content&view=article&id=13&Itemid=20

You can also buy a TellStick Net device and send API requests to Telldus Live from the PI (internet access needed).

5

you could also use an existing device. I have interfaced an Aviosys NetPower 8800 switch which connects via USB.

It didn't come with Windows drivers and they weren't willing to nrelease an interface spec so I could build a Linux driver.

But I've written a Python program to control it:

https://skydrive.live.com/#cid=500667A62B4F909A&id=500667A62B4F909A%21294

Lance
  • 59
  • 1
3

X-10 serial interfaces exist. That would have the advantage of controlling AC switches that aren't right there.

Jakob
  • 2,768
  • 5
  • 23
  • 22
Brian Carlton
  • 313
  • 1
  • 13
2

totally different approach:

as you like your server to be up, you probably like the idea of an UPS. You can use an APC and control is by the raspberry. This will let you powercycle the ups. The smallest UPS can be used, either new or secondhand. The secondhand option will set you back 50euro's/dollar or even less and has extra benefits (and extra joy in makeing a webinterface for even extra monitoring).

This way you can hook up more devices and let the raspberry send shutdown commands during powerfailure etc

My 5-cents.......

user13550
  • 21
  • 1
1

Here is a SAFE way!

I used an off the shelf wireless transmitter, a wireless powerswitch (both 220 or 110volt will work) and a 5v relay.

This high power switching was done using an arduino but raspberry would work just as well (no code required for the transmitter).

http://youtu.be/trZ3y4xCGhA

lenik
  • 11,533
  • 2
  • 32
  • 37
Tony
  • 11
  • 1
1

A more complex but rewarding solution, would be to interface with RF devices directly. Check this out: http://rayshobby.net/?p=3381

gc_i
  • 71
  • 2
1

you just need 2 things:

  1. a transmitter directly interfacing via RXD, TXD of the serial connector of your raspi:

http://www.elv.de/elv-fs20-uart-sender-fs20-us-komplettbausatz.html

  1. a receiver with a relais (toggle switch). This retains its state even during a power outage:

http://www.elv.de/unterputz-funk-wechselschalter-fs20-ws1-komplettbausatz.html

some further info is found here:

Cheapest way to controlling multiple power sockets (lights) through Wi-Fi

sparkie
  • 435
  • 3
  • 9
1

For things that switch relatively occasionally mechanical relays are hard to beat. "solid state relays" have better cycle life but much higher cost and much higher operating losses.

The problem is that a lot of relay boards on the market are badly designed, all too often when I look at such boards I see inadequate creepage and clearance distances. I would not buy such a board for controlling mains without being able to see the layout of the power traces.

It's not helped by the design of the relays themselves, a common design of relay has one of the contact pins in-between the two coil pins. This makes it much harder to maintain creepage/clearance with these relays than it would be with a relay that has the coil pins at one end and the contacts at the other.

https://www.sainsmart.com/collections/internet-of-things/products/4-channel-5v-relay-module appears to be a sensible design. If you look at the picture of the bottom you can see they have slotted the PCB around the common terminal of the relay to control creepage distances.

You should obviously also make sure you mount the board securely in an enclosure that either well insulated or earthed and make sure all wiring is adequately restrained.

Peter Green
  • 6,595
  • 1
  • 21
  • 26
0

Belkin's WeMo Switch + the Ouimeaux Python library = arbitrary control over an outlet without any soldering or mains power exposure/risk.

Downsides: costs $50 US per outlet at list price, only works when your wifi network is up, and may or may not be compatible with the plugs in your part of the world.

Tim
  • 101
  • 1