Saturday, December 7, 2013

Turning dumb wireless wall plugs into the smart ones (Part 1)

I just bought Stanley wireless wall plug system from Amazon. It has three wall plugs which can be remotely turned off or on by a small transmitter. I want to control these wall plugs via internet from anywhere in the world. There are such products on the market, such as Belkin WeMo, but they are much more expensive (~$50 per one plug). This set cost me $21 for three plugs (http://www.amazon.com/gp/product/B00A3XTCOE/ref=ox_ya_os_product).

The nice aspects of this product are:
1. The remote has separate on and off buttons which will be useful if controlling plugs remotely, without seeing the effect.
2. The plug has on/off button in case I want to override the setting without a remote or access to internet
3. The system works with fixed digital codes transmitted via RF at standard 433MHz. Generic 433MHz transmitters and receiver modules that connect to microcontrollers such as Arduino can be readily bought.
4. The system has a good range, covering pretty much my whole house (signal can go through multiple walls)


So, the plan is as follows:
1. Create a sniffing circuit to determine what codes are transmitted by each button on the transmitter. For this I will use a simple 433 MHz receiver I bought from Amazon for $6 (including a matching transceiver)
2. Program a microcontroller (in my case TI's MSP430, similar to Arduino) to programmably play back the codes via the above mentioned simple 433MHz transmitter. (Later, I will connect this TX to a small webserver I'm building, based on BeagleBone Black, instead of MSP430).
3. Test the whole thing
4. Port this to BeagleBone Black webserver which will act as the home automation hub.

1. The sniffing circuit

I found this idea from several sources on the web, but this is ingenious. I used this tiny RX module I bought from Amazon (http://www.amazon.com/gp/product/B008A4UWK6/ref=oh_details_o03_s01_i00?ie=UTF8&psc=1)
(TX is on the left and RX is on the right)

Then, I made a simple circuit with a resistor divider and customized cables (USB power and audio jack) that I will attach to my computer which will be used as an oscilloscope.

Here is what it looks like:



I plugged both cables (USB and audio) into USB and Line-in sockets in the PC, respectively. It's important to use Line-in, not microphone, socket as it can handle larger voltage swings, without damaging a sound card.
Next, I downloaded an open source software - Audacity (http://audacity.sourceforge.net/download/) which I used to capture the input from the Line-in input on the sound card while I pressed each button on the remote control. I used sampling at 44.1 kHz which is fast enough to capture decoded signal from the RX module:



As you can see the code repeats as long as you press the button. I labeled different waveform, so I can later read the code for each button. The codes have some minor differences among them for a few bits:


Now, I needed to find out the timing of the pulses, so I zoomed in till I saw individual sample points and measured how many of them are in high and low pulses as well as in the period:




2. A microcontroller program 

I will use this information above to program the MSP430 microcontroller LaunchPad with TX module to play back the codes at will (the LaunchPad can be replaced by anything else, such as Arduino Uno). I connected VDD of the TX module to 5V (instead of 3.3V) to get a better range. The TX Data pin is connected to P1.1 of the LaunchPad. The Launchpad is programmed and power is supplied via USB cable connected to my PC.



Here is the Energia software code for the LaunchPad: http://tinkeringandsuch.blogspot.com/2013/12/example-energia-code-for-controlling.html


3. Testing

I finally got the whole setup to work. You can see the power-on indicator lamp flashing on the power plug:



4. Porting to BeagleBone Black webserver 

Now, to make this thing more useful, I will port the software into my BeagleBone Black board which runs a webserver under Ubuntu Linux. This way a can control devices attached to these wall plugs over the internet and include them into my home automation project I am building. I will describe this step in a second part of the blog entry.

No comments:

Post a Comment