Instead of rewiring the remote control, you can replicate the remote's RF signals using a transmitter that uses the same frequency as your sockets (these particular units use 433.94 MHz). This will depend on the particular sockets and sometimes your location – some countries prohibit the use of certain frequencies – as you may require certification before making your own transmissions:
The signals sent by the RF remote control can be recreated using 433Utils created by
http://ninjablocks.com. The 433Utils uses WiringPi and is written in C++, allowing high speed capture and replication of the RF signals.
Obtain the code using the following command:
cd ~ wget https://github.com/ninjablocks/433Utils/archive/master.zip unzip master.zip
Next, we need to wire up our RF transmitter (so we can control the switches) and RF receiver (so we can determine the control codes) to the Raspberry Pi.
The transmitter (the smaller square module) has three pins, which are power (VCC), ground (GND), and data out (DATA). The voltage supplied on the power pin will govern the transmission range (we will use a 5V supply from Raspberry Pi, but you could replace this with 12V, as long as you ensure you connect the ground pin to both your 12V supply and Raspberry Pi).
Although the receiver has four pins, there is a power pin (VCC), ground pin (GND), and two data out pins (DATA), which are wired together, so we only need to connect three wires to Raspberry Pi:
RF Tx |
RPi GPIO pin |
RF Rx |
RPi GPIO pin |
VCC (5V) |
2 |
VCC (3V3) |
1 |
Data out |
11 |
Data in |
13 |
GND |
6 |
GND |
9 |
Before we use the programs within the RPi_Utils, we will make a few adjustments to ensure our RX and TX pins are set correctly.
Locate codesend.cpp in 433Utils-master/RPi_utils/ to make the required changes:
cd ~/433Utils-master/RPi_utils nano codesend.cpp -c
Change int PIN = 0; (located at around line 24) to int PIN = 11; (RPi physical
pin number).
Change wiringPi to use physical pin numbering (located around line 27) by replacing wiringPiSetup() with wiringPiSetupPhy(). Otherwise, the default is wiringPi GPIO numbers; for more details, see http://wiringpi.com/reference/setup/. Find the following line:
if (wiringPiSetup () == -1) return 1;
Change it to this:
if (wiringPiSetupPhys () == -1) return 1;
Save and exit nano using Ctrl + X, Y.
Make similar adjustments to RFSniffer.cpp:
nano RFSniffer.cpp -c
Find the following line (located at around line 25):
int PIN = 2;
Change it to this:
int PIN = 13; //RPi physical pin number
Find the following line (located at around line 27):
if(wiringPiSetup() == -1) {
Change it to this:
if(wiringPiSetupPhys() == -1) {
Save and exit nano using Ctrl + X, Y.
Build the code using the following command:
make all
This should build without errors, as shown here:
g++ -c -o codesend.o codesend.cpp g++ RCSwitch.o codesend.o -o codesend -lwiringPi g++ -c -o RFSniffer.o RFSniffer.cpp g++ RCSwitch.o RFSniffer.o -o RFSniffer -lwiringPi
Now that we have our RF modules connected to Raspberry Pi and our code ready, we can capture the control signals from our remote. Run the following command and take note of the reported output:
sudo ./RFSniffer
Get the output by switching button 1 OFF with the remote set to channel A (note that we may pick up some random noise):
Received 1381716 Received 1381716 Received 1381716 Received 1381717 Received 1398103
We can now send out the signals using the sendcode command to switch the sockets OFF (1381716) and ON (1381719):
sendcode 1381716 sendcode 1381719
You could even set up Raspberry Pi to use the receiver module to detect signals from the remote (on an unused channel) and to act upon them to start processes, control other hardware, or perhaps trigger a software shutdown/reboot.