Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Warning: Interfacing with mains electricity involves working with potentially lethal voltages. Due care and competence is required. – Mark Booth Aug 20 '12 at 11:13
This blog post is about a project to remotely switch mains ON and OFF using a long range (>100m) radio modules. It does need some skills to put together. – seggy Jan 21 at 8:49

13 Answers 13

up vote 37 down vote accepted

Well you could use a Solid State Relay which is much smaller and easier to control than a mechanical relay, 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 going to have to design another circuit that can self sustain itself.

But you can get these pretty cheap on eBay and they are completely safe (isolated) so they wont blow up the Pi and do not require allot 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)

* * * 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
share|improve this answer
You don't always have to keep driving the pin for the relay to stay open. There's a special type of relay called bistable relay. It has two stable modes (on and off), you can switch between them and they stay like this until they are switched again. They are not so common as normal relays however. – Krzysztof Adamski Aug 17 '12 at 17:10
Thanks! This looks not more difficult or dangerous than a simple screw terminal. The RaspPi could also switch of its own power supply ;-) – Jakob Aug 17 '12 at 18:44
These relay don't come cheap. A 25A one like this from farnel would set you back most of the price of a Raspberry Pi. If you don't need 25A, lower current versions can me cheaper. – Mark Booth Aug 20 '12 at 11:06
From Ebay much cheaper, delivered :) Honk Kong UK – ppumkin Aug 20 '12 at 13:07
I have seen catastrophic SSR failures (like, failing ON) from those cheap eBay ones. Run away from them. – Joel Wigton May 10 at 4:24

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.

share|improve this answer
+1. thats a really good idea, and a lot safer than interacting with the mains as a beginner – AnthonyBlake Aug 21 '12 at 8:28

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.

share|improve this answer
The poster does not mention where he lives (I suspect he is not in N. America - based on the need for 220V). The device you mention is designed for the US (plug type) and does not handle 220V. – Steve Robillard Nov 4 '12 at 14:37
there is kit available for 220V, see here – dm76 Jan 4 '13 at 20:38
out of stock on both sites. any alternatives? – avi Apr 3 '15 at 14:57

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.

share|improve this answer
Cool - I am going to buy one and take it apart to see how it works :-) muhahahah – ppumkin Aug 19 '12 at 11:21
That's the evil cackle I love – Pitto Feb 12 '13 at 12:54

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

share|improve this answer

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).

share|improve this answer
I LOVE it LOVE it LOVE it and then LOVE it agan. Simply can't wait for mono to work to use my lovely switchking server. – Pitto Feb 12 '13 at 12:59

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:


share|improve this answer
Yes, I also though about using an existing electricity usage monitor and switch, but it's difficult to find a device that can easy be controlled without having to install proprietary drivers. – Jakob Aug 23 '12 at 7:08

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

share|improve this answer

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.......

share|improve this answer

you just need 2 things:

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


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


some further info is found here:

Cheapest way to controlling multiple lights through Wi-Fi

share|improve this answer

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

share|improve this answer

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).


share|improve this answer

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.

share|improve this answer

protected by Community Jan 21 at 11:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.