Thursday, January 16, 2014

Raspberry Pi - Controlling 433 MHz remote outlets

In my previous post here, I tried to use a cheap 433 MHz transmitter to replicate the 433 MHz remote functionality but landed up hacking the remote to send the codes instead. The main issue I was facing there was that the code was not being recognized by the RF outlets.

I was finally able to resolve that issue so I just need one GPIO pin to control all my RF remote outlets now!

Troubleshooting my original issue:

I am using this receiver and transmitter - 433MHz Tx-Rx pair (set of 2)








I was using the RCSwitch library ported over to the Raspberry Pi from here
http://ninjablocks.com/blogs/how-to/7506204-adding-433-to-your-raspberry-pi

As mentioned in my previous post, I first tried using the Audacity route but I could not decode the data correctly.

Since I had an Arduino lying around as well, I downloaded the RCSwitch library for the Arduino and tried the advanced receiver demo.

The output for one switch of my remote looked like this:
Protocol: 1
Decimal: 1398209
binary: 000101010101010111000001
PulseLength: 207

I noticed that the pulse length was 207 which is different from the default length in the code. I quickly changed the pulse length in the send demo sketch on the Arduino and was able to get the RF outlet to switch on!

So I went back to my Raspberry Pi and modified the send.cpp code to look like this:
int main(int argc, char *argv[]) {
    /*
     output PIN is hardcoded for testing purposes
     see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
     for pin mapping of the raspberry pi GPIO connector
     */
    int PIN = 0;
    unsigned long code = atoi(argv[1]);

    if (wiringPiSetup () == -1) return 1;
        printf("sending code[%d]\n", code);
        RCSwitch mySwitch = RCSwitch();
        mySwitch.enableTransmit(PIN);
        mySwitch.setPulseLength(207);
        mySwitch.send(code,24);
        return 0;
}

Note: I have removed the header files for a cleaner code look below. Please include them in your actual code if you want to use the code below.



I have the transmitter data pin connected to the Pi pin 11 (GPIO 17). I re-ran make in the dir and sent the previously decoded code:
sudo ./send 1398209

And it works! Good riddance to the multiple GPIO pins to replicate the remote functionality +  the remote is free for use independently now.


11 comments:

  1. Hi Trushant, Can you please post an step by step guide if possible.

    ReplyDelete
    Replies
    1. What exactly are you looking for? The ninjablocks link pretty much walks you through how to use these modules. If you download their code, you just need to modify send.cpp with what I have stated above.

      Delete
    2. I have followed your instructions, but I am not able to turn on the rf switch. Is there any thing I am missing. I have connected the data pin to pin 11, vcc to 5v and to the ground. I have installed the utilities from ninjabloks.

      Delete
    3. Couple of things that could be the problem:
      1) How far away is your RF switch from your transmitter? Do you have an antenna on the transmitter ?
      2) Are you using the same RF modules (transmitter, remote+RF switches) that I am? - If you are not, then the protocols could be different and the example is not going to work without understanding what protocol your RF remote is sending out.

      Delete
    4. I am using the RF switch similar to this one
      http://rayshobby.net/blog/wp-content/uploads/2011/10/remote_control_socket.jpg

      I think, I will have to find the codes being transmitted by the RF transmitter, I assumed it is similar to the codes on this page
      http://rayshobby.net/?p=2427

      I have tried them but it seem's to be not working. I will update my setup with a picture.

      Thanks

      Delete
  2. Here is the link for the setup

    https://app.box.com/s/ylq34ollx57c1omav6cj

    ReplyDelete
    Replies
    1. It is a little hard to see the pinout details but I think you have your receiver and transmitter data connections to the Pi wrong. Can you list out the GPIO pin numbers you are using for the different functions?

      Delete
    2. Finally got it working. One of the transmitter I received from ebay was not working. Thanks for the help.

      Delete
    3. Sure. Glad to hear that it is working for you now.

      Delete
  3. It seems to me, that there is a new Version
    The Line "mySwitch.setPulseLength(207);" should be in "codesend.cpp"

    ReplyDelete
  4. I wrote a post describing in detail how I created this: http://timleland.com/wireless-power-outlets/

    ReplyDelete