In this personal project, I developed a couple of prototypes and designed a simple circuit board that supported Raspberry Pi to control different brands of wireless outlets. These are the ordinary wireless outlets that can be bought from online stores or local markets. The developed applications have these features:
This is a brief video presentation to show the result of the project.
The motivation of the project is to use Raspberry Pi to control outlets. There are already some similar projects using the Raspberry Pi for remote control. However, those are using existing switches of the wireless controllers. It means that you need to know some basic functions on the circuit board. Then you hack some circuits to use Raspberry Pi replacing the manual pressing on the buttons of these switches. Doing things of these like reverse engineering of circuits, that is not an easy way. Specifically, if you want to control outlets from different manufactures designed different structures of remote switches, you need to hack all of them. That is not practical, error-prone, and time consuming.
In this project, I used a more convincing way in building a Raspberry Pi to simulate signals of remote controllers. The idea was to use a software defined radio device, such as USRP, to capture genuine signals from switches. Then we use Raspberry Pi to simulate these signals. This method is easier than previous methods, and it is more general. You can use it to simulate all kinds of outlet remote switches.
Use one outlet as an example, we get its signal of open command as a wave file. Use an audio editor to open the wave file. We can decompose the signal into some simple binary codes. The narrow square wave is coded as 0, the wide square wave is coded as 1. You are free to use other coding methods to make it easier to be interpreted. In this case, we can use the code as shown in the following figure to denote the message signal of open command.
int g_signal_switch[]= {1,0,1,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,1,0,0,1,0,0,0}; int g_signal_1_open[]= {0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0}; int g_signal_1_close[]= {0,1,1,0,1,0,0,0,0,1,0,0,0,0,0,0}; int g_signal_2_open[]= {0,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0}; int g_signal_2_close[]= {0,1,1,0,1,0,0,0,0,0,0,1,0,0,0,0}; int g_signal_3_open[]= {0,1,1,0,1,0,0,1,0,0,0,0,0,0,0,0}; int g_signal_3_close[]= {0,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0};We define the time interval for setting high/low voltage on the pin of GPIO as:
#define SEND_LOW_SWITCH digitalWrite(PIN,1);delayMicroseconds(600); \ digitalWrite(PIN,0);delayMicroseconds(1200); #define SEND_HIGH_SWITCH digitalWrite(PIN,1);delayMicroseconds(1200); \ digitalWrite(PIN,0);delayMicroseconds(600); #define SEND_LOW_SIGNAL digitalWrite(PIN,1);delayMicroseconds(600); \ digitalWrite(PIN,0);delayMicroseconds(1800); #define SEND_HIGH_SIGNAL digitalWrite(PIN,1);delayMicroseconds(1800); \ digitalWrite(PIN,0);delayMicroseconds(600);
Using the above information, we complete an executable file that can attach parameters to specify which outlet will be turned on/off. Then we establish a web application on Raspberry Pi. The client with a browser can visit the web application to control outlets. To make things fancier, we introduced voice recognition feature, that can control an outlet by voice command. Besides, the web application supports to set timers to trigger some controls, this is a particular feature that is hard to be implemented on the original wireless switch. On Raspberry Pi, we can take advantage of Linux system to program these functions.