Home Automation: AC Wall Plugs, RF modules, and an Arduino


Here’s a fairly simple way of remotely controlling your electronics using a cheaper solution then the hundreds or thousands of dollars that professional home automation systems cost. It does however require programming knowledge and at least some circuitry knowledge.

1. Automation Things

Buy some things that are controller by RF signals and have a remote. Say, some radio controlled wall outlets, or radio controlled light bulbs:



2. Building an RF Sniffer

Buy an Arduino, an RF receiver, and a microphone cord and build an awesome radio frequency sniffer device:


Now we need to combine everything together into a RF sniffing machine by wiring everything together as detailed in martin_bg’s post on the Arduino forum. If you don’t yet understand circuit diagrams and how the Arduino works a good place to start would be the Arduino tutorials page. In the case of my build in the image below I only connected one of the 5V pins and one of the ground pins instead of all of them, and my microphone cord only had one wire instead of 3 so I wired that to the pin 2 & 39K resistor, and wired the ground & 10K resistor directly to the bundle of loose copper wire surrounding the wire.

Now we have an RF Receiver that converts radio frequency signals into audio signals!

3. Recording the RF Signal


Next up is recording the button presses on your RF remote by using audio recording software on your computer. Connect your microphone cord to the line-in port on your computer (not the microphone port), and then download Audacity (popular audio recording software), run it, and in Audacity set your Project Rate to 48000Hz and your recording type to Mono. You should now be ready to record.

Press the record button and then press a button on your RF remote and hopefully you’ll see the sound wave in the recording change. If so you can press the stop button and go on to decoding the signal. If not then go back and check your set-up of everything. It’s also possible the remote is transmitting in a different frequency (315Mhz/434Mhz) than what you wired up on the breadboard.

4. Decoding the RF Signal

Now we know we have the RF signal recorded but not quite what it is or where it starts and stops. If you start zooming in on the recording you should start to see discrete groups of sound waves. When you press the button on the remote it sends the same signal multiple times to guarantee the signal got through, and as you can see below it does look like we got a bunch of static and then the same signal 5 times in a row.


So let’s zoom in very closely on one of those 5 signal grouping and we can finally see the actual transmission data. You’ll notice that the signal follows the pattern of long on, short off or short on, long off where on means below 0, and off mean above 0 (your’s might be mirrored…or to be more picky, my readings are mirrored).


Now looking at the bottom lines of the sound wave anytime we see a long bar we’ll mark it down as a 1, and any time the bar is short we’ll mark it down as a 0. Thus the pattern for the above wave, and the RF signal of the first button on the remote is:

We’re not quite done yet as the length of times these signal’s are on or off for are also important. So let’s zoom in even closer on the first 1 signal until there are dots visible. Each dot represents one of the times that the sound from the microphone was measured. Since we set Audacity to sample at 48000Hz there are 48000 sample points/dots every second.


There are very roughly 21 dots during a short signal and 63 dots during a long signal (does not need to be very accurate). Since we know there are 48000 dots in a second we can divide 21/48000 and 63/48000 to come up signal lengths of time of 410µs and 1230µs respectively.

5. Building an RF Transmitter


Wire up the RF transmitter and connect it to a pin on the Arduino (hey we’re actually finally using the Arduino for something more than supplying power!). The black wires are just sticking up in the air as antennas so that the signal is amplified enough to make it through the whole house.


For the code I made some small modifications to similar peoples projects, primarily rayshobby.net where he did the identical project, and a helpful post on sending serial data to the Arduino and sending website form submissions to the serial port (and thus control the Arduino from a website).

Primarily the code contains the sequence found for each keypress:

struct Controller NexxTech1 = {NexxTech, 0b100010000000010000000101000, 0b010010000000010000000101000, 27};

And sends the sequence by reading each bit, if it’s a 1 sending a long on, short off, and if it’s a 0 sending a short on, long off:

for(k=0;k<LENGTH;k++) {
    d = ((command>>(LENGTH-1-k)) & 1 ? LONG_DELAY : SHORT_DELAY);
    digitalWrite(RF_DATA_PIN, HIGH);
    digitalWrite(RF_DATA_PIN, LOW);    
    delayMicroseconds(TOTAL_DELAY - d);

The code also listens on the serial port for a letter representing the thing to control and a 1 or 0 to turn it on or off. Thus you can open the Serial Monitor and send a command like ‘a1’ and the Arduino will turn on object a.

Arduino sketch

And while that was a lot…that’s it! About $50 for the setup and $20 per 3 sockets you want to control. I haven’t had a problem with the Arduino in the basement sending the RF signal to the second floor and if you programming knowledge you can write some PHP/Phython/Java/etc code to send serial commands to the Arduino and thus have a website or program to control the home automation system. Again, the Stack Overflow example will give you an example of writing such a website.

{ 3 comments… read them below or add one }

redcell December 1, 2013 at 3:19 PM

The link to the sketch file is not working…


Zander Kidd December 2, 2013 at 8:01 AM

Should be fixed now.


redcell December 2, 2013 at 1:44 PM

thank you


Leave a Comment

Previous post:

Next post: