What I would like to see is the cheapest way possible to control my lights using my Raspberry Pi.

What I imagine to control it

I build an interface on my smartphone by which I can send commands to my Raspberry Pi. The Raspberry Pi would then send a package (or something else) to a thing I can put inside my power socket (so I don't see it). Note that this thing should be connected through Wi-Fi (how else is it going to receive the message from my Raspberry Pi?).

What is this thing and what is the cheapest possible way possible, as I am planning to connect a dozen or so lights?

  • There is a wifi controlled outlet someone made for around $20 in parts (not including the raspberry pi) ProvoTronics.com
    – Ty Jones
    Commented Nov 4, 2016 at 22:48

7 Answers 7


I'm using these items:

  • Receivers ON-OFF to control my lights (you typically put a device in the walloutlet or instead of the walloutlet). They work in the 433 MHz band (ISM).

Out of the box you have a remote control which sends a signal to the receiving device and switch it on or off.

In my case, I created this situation:

  • Created an HTML site on my Raspberry Pi (/switch.html)
  • I call that page on my smartphone
  • On the page are four buttons (I control four devices / lights)
  • When I click a button, it asynchronously fires a call to /switch.php (the .php is on the Raspberry Pi)
  • The switch.php calls a switch.py program which controls the 433 MHz sender (see below)
  • The 433 MHz sender does the same thing as the out of the box remote control.

This is the sender, that is, the replacement for the standard remote control: 433 MHz Wireless Transmitter Module Superregeneration for Arduino

I also created a scenario for out-of-house use.

I didn't want to connect my Raspberry Pi via my homerouter directly to the Internet, so I built myself another webpage (at my own domain) which does not control the Raspberry Pi directly, but it sends an email to a (known only to me) email (Gmail) address.

The Raspberry Pi checks that email account every 10 minutes to see if there is any email. In that email I for instance say A on or B off.

So when we get home late and the lights are already off, we navigate to the site on my mobile (plans are to make it an Android app), click the button, the page gets posted and at the server an email gets sent, and in the next 0-10 minutes the Raspberry Pi checks the email, sees four new emails (A on, B on, C on and D on) and switches the lights on.

How to get started

So, to get started, these are the things I've done to get it all working. In my case, I programmed the control of the 433 MHz sender in Python (which is an easy language if you already know how to program).

First you install the rpi.gpio libary.

This library is used to control the little pins on your Raspberry Pi from your Python script. See Install RPi.GPIO Python Library.

Then you can optionally read the article Tutorial: How to use your Raspberry Pi like an Arduino, it's about what you can do with the rpi.gpio library, for instance blinking LEDs.

It's not mandatory for the Elro light switching however.

Then you get the awesome code for the Elro commanding by HeikoHeiko, at http://pastebin.com/aRipYrZ6. You paste that code in a file named 'switchelro.py'.

You then change the string on line 94 to your own jumper settings (as you have set in your remote control and the walloutlet device. Check wether the combination remote-walloutlet device works before trying it with the Raspberry Pi. If it doesn't work with the standard components, it will probably fail with the Raspberry Pi too).

You then change the number of the pin your sender is attached to on line 97.

The pin number can be gotten from RPi Low-level peripherals and in File:RPi P1 header.png.

You have to use the 1..26 count (the black image), not the GPIO34, GPIO24, etc. (green image).

Then you type this on the command prompt:

sudo python switchelro.py 2 1

which means 'turn on B' (following this schema: A = 1, B = 2, C = 4, D = 8, E = 16 for the first number, and 1=on, 0=off for the second).

I changed the repeat = 10 on line 30 to repeat = 20 in the beginning (I don't remember why) and that works. I never retried it with the setting '10'.

  • 1
    oh, and the price.. here in the Netherlands a set of 3 walloutlet receivers (which you click in the walloutlet, and the light goes into the receiver) with remote control costs 15 euro. The 433 Mhz sender costs about $5
    – Michel
    Commented May 22, 2013 at 8:07
  • That sounds exactly what I'm searching for! Could you please send me the project files? (The switch.html, switch.php and, the switch.py) My email is in an above answer. Also, where can I buy the on-off2 receiver in the Netherlands? The website you provided does not provide any prices. Commented May 22, 2013 at 8:22
  • Excellent post- Can you add where you found the source for the commands you send via serial ? Are you usign a library? How do you target the devices? +1
    – Piotr Kula
    Commented May 22, 2013 at 8:48
  • 1
    @Nitin In my system you can set the dipswitch on the receiver (the 5 on/off switchers) and 5 letters (A .. E). So with the code default_key = [1,0,0,0,1] from the pastebin.com/aRipYrZ6 code you control the dipswitches and with the pin property in the def __init__(self, device, key=[1,1,1,1,1], pin=4): code you control the A .. E (a=1 .. e=16)
    – Michel
    Commented Mar 17, 2015 at 13:32
  • 1
    @Nitin Don't know how to control it with C#. Looking forward to that too, because the latest PI will run Win10 and hopefully it will run C# as well. That said, whilst I am a C# programmer, Python is an easy learn
    – Michel
    Commented Mar 17, 2015 at 13:33

The thing is called X10, it's an industry standard for most home automation tasks, including controlling lights. The control signal is sent over the same power line your appliances are connected to.

To be able to control everything from the computer, you might want to read about X10 Computer Interfaces from OpenRemote web site. The model you're most probably are after is CM15A with USB interface, that has Linux support.

Also, it might be a good idea to check ebay for X10 enabled wall sockets and screw in lamp modules, these can be bought quite cheaply, in the $10-20 range.


What you're looking for is a Solid State Relay or mechanical Relay. The idea is that a small amount of current at a low voltage (such as from your RPi) can be used to trigger the flow of a larger amount of current at a higher voltage (such as a lamp).

I would recommend $12 SainSmart 8 Channel DC 5V Relay Module for Arduino Raspberry Pi, as it's already been manufactured into a board with ready to use screw terminals. It has build in FETs to source the extra current required for mechanical relays to be triggered. There are different boards from the same company, in a wide variety of layout/number of relays. The one I sent is 8 channels, so it might not be sufficient for your needs, although there are 16 channel versions available. They're generally cheaper than buying multiple relay's separately, and making hooking up to them easy.

There are 4 connections required:

  • A common ground (that's shared to all relays) that connects to the RPi
  • Separate inputs powered by individual RPi GPIO lines (to trigger relays)
  • A high voltage input
  • A high voltage output

The high voltage inputs/outputs are the connections that are made or broken by the relays in accordance to their input lines.

I already have an AWESOME C program for remotely switching GPIO pins over SSH. If you'd like I can give you the source code, or even explain how it works.

  • How can I say no to an AWESOME program. Although C is not in my repertoire of languages, I can at least look at the code over time. Commented May 21, 2013 at 8:59
  • If your question has been answered, please click the checkmark below the voting arrows.
    – Alexander
    Commented May 22, 2013 at 6:09
  • @XAleXOwnZX can I see this Awesome code too? Perhaps you should open a "Does anyone have an AWESOME C program for remotely switching GPIO pins over SSH" question then answer it.
    – puk
    Commented Sep 30, 2013 at 6:21
  • I'll need your e-mail address, I'll send it and post the question+answer tomorrow
    – Alexander
    Commented Oct 1, 2013 at 4:28
  • can I connect the rPi to this relay board directly? Or do I need add a resistor/transistor in between? And also is it fully isolated? so that in case something happens, my pi or electric appliance is still safe?
    – avi
    Commented May 27, 2014 at 18:09

my system is cheap: EUR 43.- (receiver + transmitter) see below.

for home automation I simply attach an 3.3V compatible 868,35MHz FS20 transmitter to the RPI:


this transmitter interfaces directly (by 4 wires only) to RPI's GPIO ports (3.3V, GND, TXD, RXD) and is simply controlled via the serial line interface.

you now can control the huge range of FS20 devices like switches, toggle switches, dimmers, timers, radios. multi-channel-receivers etc. by transmitting some bytes over RPI's UART serial console interface.

FS20 system overview:


(unfortunately the website is available in German only)

I personally prefer plain CLI for controlling my home devices. Should you prefer some GUI you may have a look here:


fortunately in English :-)

Though very flexible the FS20 system is very cheap. Sample costs for a simple on/off switch:

switch itself: http://www.elv.de/elv-funk-schaltsteckdose-fs20-st.html EUR 22,95

UART transmitter: http://www.elv.de/elv-fs20-uart-sender-fs20-us-komplettbausatz.html EUR 19,95

I recommend to control the RPI itself by a wireless keyboard. For this you optionally may buy this ingenious little thing:

RT-MWK03[Wireless 2.4 Ghz] (http://www.riitek.com/en/product-detail-428.html)


I wrote a detailed blog post on how to control outlets wirelessly using a raspberry pi. Check it out: http://timleland.com/wireless-power-outlets/


While not exactly cheap, here's my solution:


Basically, you use the Philips Hue (wifi-controllable, programmable multicolor LED lights) together with a RPi and a touchpad. The USB touchpad surface acts on the color and brightness dimensions, while the mouse buttons toggle the lights on and off. Cost is RPi + Wifi dongle ($11) + cheap USB touchpad ($15) + Philips Hue set ($200 for bridge and 3 lights, then $60/light).


I have a differente approach: I am using Busware's CUL USB dongle (supports FS20 + HMS + FHT + other protocols and devices), and implemented my own Java API to abstract the devices and allow easy automation via a Java application.

In case anybody gets interested on my little project: http://www.paulo-lima.org/hans

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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