IMG_0629 Test Setup Arduino & Transmitter-001

Decoding and sending 433MHz RF codes with Arduino and rc-switch

In this tutorial I’ll show you how to use an Arduino to decode signals from RF remotes, and re-send them to remotely control some mains switches and a garage door.

RF transmitter and receiver modules connected to the Arduino using a solderless breadboard and jumpers

RF transmitter and receiver modules connected to the Arduino using a solderless breadboard and jumpers

Stuff you need

  1. Arduino – I’m using an Arduino Uno Rev3.
  2. 433.92Mhz RF Transmitter and Receiver Pair – I got mine from eBay for the ridiculously cheap price of $1.45:
    Transmitter Model No: MX-FS-03V (marked XD-FST)
    Receiver Model No: MX-05V (marked XD-RF-5V)
    They work just fine – the main problem is that there is no datasheet or documentation available. Some basic specs are available on hobbycomponents.com but that’s about it. Similar modules should also be available at your local electronics shop e.g. Jaycar.
  3. Breadboard and jumpers – also available from eBay or Jaycar.
  4. rc-switch
  5. A remote-controlled garage door, and/or:
  6. Some remote controlled mains switches. Mine are “PowerTran” model A0342.
  7. A basic knowledge of Arduino and C++

Connect transmitter and receiver to Arduino

The rc-switch wiki has connection diagrams for both the transmitter and receiver.

Identify your remote controls

Most RF controlled devices should work with rc-switch, but if you want you can open up the remote and check that the encoder chipset is on the list of compatible chipsets.

I’ve got two remote controls – one for my garage door (EV1527 chipset), and one for my RC mains switches (LX2262A-R4 chipset).

Decode signals from your remote controls

rc-switch has built-in functions that sends codewords for certain natively supported devices – so If you have one of these devices (I don’t) you may be able to skip this step.

Open the rc-switch “ReceiveDemo_Advanced” example sketch. Upload it and open the serial monitor.

Hold your remote near your receiver module and press a button. The Arduino should decode the signal and print the results in the serial monitor. This is what I got for my remote-controlled mains switch when I press the button to turn channel 5 on:

Decimal: 3932352 (24Bit)
Binary: 001111000000000011000000
Tri-State: 011000001000
PulseLength: 232 microseconds
Protocol: 1
Raw data: 7244,232,692,124,792,592,328,596,324,596,328,596,324,140,784,144,788,120,792,136,780,136,788,140,788,128,784,144,796,124,780,140,784,596,336,588,968,96,36,104,908,132,1412,68,248,64,28,484,56,

The LX2262A-R4 uses a 12 tri-state bit codeword comprising 8 address bits followed by 4 data bits. For the tri-state codeword above – 011000001000 – the address is 01100000 (channel 5) and the data/command is 1000 (turn on).

My mains switches can have up to 8 addresses with a separate on and off command for each. By pressing every button and decoding the signals I worked out the codes for all the addresses and commands:

Address Bits: 8
Channel 1 = 01110000
Channel 2 = 00110000
Channel 3 = 01010000
Channel 4 = 00010000
Channel 5 = 01100000
Channel 6 = 00100000
Channel 7 = 01000000
Channel 8 = 00000000

Data Bits: 4
Turn On  = 1000
Turn Off = 0000

I suspect the address codewords will be the same for all devices of the same make & model – if anyone can confirm this please let me know.

The EV1527 chipset in my garage door remote uses a 24-bit codeword comprising 20 address bits followed by 4 data bits. The codes I got from my garage door remote are:

Button 1:
Decimal: 8571080 (24Bit)
Binary: 100000101100100011001000
Tri-State: not applicable
PulseLength: 321 microseconds
Protocol: 1
Raw data: 9964,956,332,312,976,312,976,308,980,304,980,308,980,952,340,304,980,956,336,188,908,276,728,264,124,168,308,60,24,60,236,88,88,204,88,76,80,56,1020,284,440,56,24,40,100,84,12,36,56,

Button    Address              Data
Button 1: 10000010110010001100 1000
Button 2: 10000010110010001100 0100
Button 3: 10000010110010001100 0010
Button 4: 10000010110010001100 0001

Write code for your device

rc-switch has built-in functions that sends codewords for certain natively supported devices – so If you have one of these devices (I don’t) you should be able to use the RCSwitch::switchOn() and RCSwitch::switchOff() methods in the TypeX example sketches.

If not, you’ll need to manually set the PulseLength and Protocol and send raw codes using the RCSwitch::send() or RCSwitch::sendTriState() methods, as shown below.

The following code – based on the “SendDemo” sketch – switches one of my remote controlled mains switches on and off every 1 second. Note the pulse length has to be manually set because it differs from the default pulse length for Protocol 1. I’ve created a function – command() – which accepts channel number and on/off as integer arguments and looks up the corresponding address and data commands specific to my device. For your device you could create a similar function, or just send the raw codes.

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {

 Serial.begin(9600);

 // Transmitter is connected to Arduino Pin #10 
 mySwitch.enableTransmit(10); 

 // Set Protocol (default is 1, will work for most outlets)
 mySwitch.setProtocol(1); 

 // Set pulse length 
 // NB Pulse length must be set AFTER Protocol, 
 // because setProtocol(1) also sets pulse length = 350
 mySwitch.setPulseLength(232);

 // Optional set number of transmission repetitions.
 // Mine seem to work with 2, yours may need more
 mySwitch.setRepeatTransmit(2);
}

// Switch channel 8 on and off every 1 second
void loop() {
 command(8, 1);
 delay(1000);
 command(8, 0);
 delay(1000);
}

void command(int nAddress, int nData) {

 // List of device addresses - may be different for your devices
 char* addressCodes[8] = { "01110000", "00110000", "01010000", "00010000", "01100000", "00100000", "01000000", "00000000" };

 // List of commands - may be different for your devices
 char* dataCodes[2] = { "0000", "1000" };

 // Concatenate the Address and Data codes into a single codeword
 char sendCode[13] = "";
 strcat(sendCode, addressCodes[nAddress-1]);
 strcat(sendCode, dataCodes[nData]);

 // Send the code
 mySwitch.sendTriState(sendCode);
}

Here is the code which opens and closes my garage door (simulates button 1) every 10 seconds. It also flashes the on-board LED to indicate a command has been sent.

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {

 Serial.begin(9600);

 // Transmitter is connected to Arduino Pin #10 
 mySwitch.enableTransmit(10);

 // Optional set pulse length.
 mySwitch.setPulseLength(321);

 // set protocol (default is 1, will work for most outlets)
 // mySwitch.setProtocol(2);

 // Optional set number of transmission repetitions.
 // mySwitch.setRepeatTransmit(15);

 pinMode(13,OUTPUT);

}

void loop() {
 mySwitch.send("100000101100100011001000");
 digitalWrite(13,HIGH);
 delay(500);
 digitalWrite(13,LOW);
 delay(10000); 
}

Photos and Video

Here are some photos of the equipment I used and my test setup. The RC switch has a lamp plugged into it.

Here is a video of the Arduino remotely switching my lamp on and off every 1 second:

Notes

The transmitter module seems to have a range of several metres without an antenna. If you require more range, you can add an external antenna by soldering a length of insulated wire to the “ANT” via on the transmitter. Recommended length is 1/4 wavelength, which is approx 17cm @ 433MHz.

Future work and applications

Things I plan to do in future include:

  1. Include control of IR devices e.g. TV and air-conditioning remotes.
  2. Switch appliances, lights etc on/off via a webpage or phone app.
  3. Switch lights, TV, radio etc on and off on a schedule whilst I’m holidays so it looks like I’m still at home. To improve the illusion, the schedule could be varied randomly.
  4. Automatically turn off appliances & lights if unintentionally left on.
  5. Play pranks on people by randomly opening and closing their garage doors. You shouldn’t do this, it’s naughty.
  6. Port to Raspberry Pi (rc-switch has a rpi port).

References

  1. https://code.google.com/p/rc-switch/
  2. Similar blog posts which taught me what I needed to know:
    1. http://tinkerman.eldiariblau.net/decoding-433mhz-rf-data-from-wireless-switches/
    2. http://tinkerman.eldiariblau.net/decoding-433mhz-rf-data-from-wireless-switches-the-data/
    3. http://blog.sui.li/2011/04/12/163/
  3. Datasheets
    1. http://forum.hobbycomponents.com/viewtopic.php?f=39&t=1324
    2. http://en.chiptrue.com/images/LX2262_en.pdf
    3. http://aitendo3.sakura.ne.jp/aitendo_data/product_img/wireless/315MHz-2012/RX315-HT48R/EV1527.pdf

 Questions and Comments

If you have any questions or suggestions on how I can improve this post, please leave a comment 🙂

31 thoughts on “Decoding and sending 433MHz RF codes with Arduino and rc-switch

  1. hasan kes

    Hi, i’m upload “ReceiveDemo_Advanced” sketch and open serial monitor but screen is empty. i’m push my controller any buttons but screen empty.

    Reply
  2. Jorge Anis

    Good evening, I make a query, the receiving electronic garage motors have a button that “learns” the code of the remote control, Would you know how you can do that with arduino? From already thank you very much. Best regards.

    Reply
  3. chris

    Hi,

    great tutorial !

    Seems like I am using the same receiver / transmitter.
    Sending works perfectly in the entire house but I have a problem with the reception of RF signals. Although I tried 2 versions of external antennas I only get ~ 1m range.
    I tried a 17.3 cm long wire and a shielded RG 58 coax-wire of which I removed the shield of 17.3 cm and left the rest es a ´ground plate´ replacement.

    Any ideas on how to improve the range while receiving?

    Additionally the reception is unreliable and yields inconsistent results. Pressing the same button several times on my remote leads to the following output:

    Decimal: 5201 (24 Bit) Binary: 000000000001010001010001 Tri-State: 00000FF0FF0F PulseLength: 325 micros. Protocol: 1
    Raw data: 10116,268,1031,264,1007,291,1006,313,1020,257,1012,282,993,315,1004,277,997,300,1039,258,993,359,964,924,359,289,1000,952,360,283,1000,296,1043,257,996,992,314,295,996,955,350,287,999,300,1017,281,1001,985,321,
    Received 5201

    Decimal: 5215 (24 Bit) Binary: 000000000001010001011111 Tri-State: 00000FF0FF11 PulseLength: 326 micros. Protocol: 1
    Raw data: 10154,234,1007,285,1005,301,1027,266,1092,267,940,296,1038,263,990,320,1009,266,1001,295,1010,282,1001,958,345,294,998,989,321,310,976,299,1010,284,1000,953,350,296,994,983,348,926,377,930,339,936,365,943,350,
    Received 5215

    Decimal: 5471 (24 Bit) Binary: 000000000001010101011111 Tri-State: 00000FFFFF11 PulseLength: 325 micros. Protocol: 1
    Raw data: 10055,289,1019,278,1011,282,1053,257,1001,282,1020,279,1038,279,1025,248,1015,289,1008,304,941,331,969,957,345,289,1006,939,349,299,1017,926,351,324,984,977,331,278,1001,950,360,931,362,946,350,937,390,955,319,
    Received 5471

    I am using the very cheab ELRO kit for less than 10€ and as mentioned before switching the sockets on/off works perfectly with perfect range.

    THX, Chris

    Reply
    1. 3cHeLoN

      My findings are the same as yours. I have also inconsistent readings from an ALDI remote. Maybe the pulselength is measured incorrectly?

      Reply
      1. Pusaken

        Same here with ALDI remote. Readings are unstable. Most of the time, however, the correct value is received. Did you make any progress on this 3cHeLoN?
        Maybe I have the time to check if the pulselength can be forced and adjusted manually.

        Reply
  4. brian

    very well done!! i am going to use with this home automation to turn on and off lights
    Thank you

    Reply
  5. Razvan

    Hy,
    I am trying to do the same with my arduino, i have a 315 receiver and a rf relay on the same frequency, the receiver sniffs this signal, but when using the 433 receiver i get nothing. On the back of the remote says 433.92mhz, i tried with a remote from a rf controlled car and it receives that signal, how can i sniff my garage remote? Can you please help?

    Reply
  6. Wudwork

    Thank you for the work you did and presenting it in easy to implement way. I am intrigued about the garage door opener; mine is a Sears and I thought the code changed for security reasons. I don’t know the frequency so the el-cheapo receivers I got on ebay might not work for it.

    Reply
  7. Martin

    Thank you for the great tutorial. I am having problems with getting the code to work. I’ve purchased the same RF receiver and transmitter as you specify. When I use my garage door remote to try and sniff the code, nothing ever appears in the console output. I found that the code rcSwitch.available() always returns false, so no decoding happens.
    Did you ever have this problem? Or do you know how to fix this? I purchased 3 identical receivers, and all of them have the same problem, so I don’t think it is a hardware fault.
    Thanks so much for your help.

    Reply
    1. Jakub

      I have problem with range of transmitter. I made a lot of tests (changing input voltage of transmitter from 4 to 9 V etc.), but range is about 10m in open area. How long distance did you reach in your environments? I use two external antennas wired to the receiver and transmitter.

      Reply
  8. Pingback: 433 MHz RF and Raspberry Pi (cheap IP power switch) » we got style

  9. Camillo

    Hi! Nice tutorial; I have bought these modules from Ebay, they seems really identical (MX-FS-03V) except there is written FS1000A instead of XD-FST (???) and I am getting a really short range (2-3 centimetres without antenna, 2-3 meters with antenna); I am really disappointed; do You have any idea or maybe I have the wrong modules?
    Thank you!
    Camillo

    Reply
    1. Wes Post author

      You should get much longer range than that – either the receiver or transmitter may be faulty, or they may not be tuned correctly.

      Reply
      1. Camillo

        I bought the XD-FST/FS1000A as well, but without antenna the range is similar (just a few centimetres…).

        Reply
  10. icebear

    hi,

    I have a weird problem with some new remotes I bought.
    I already can control my RC-710 outlets using the code I found here (and also via RC switch):
    http://www.dserv01.de/howtos/funksteckdose-fernsteuern-mit-arduino/

    from the same page I used the instructions to decode the signals from my new ‘Flamingo’ outlets remote control
    (the Flamingo outlets more or less seem to be the same a the ELRO 440, but dont have DIP switches).

    I had no problem to decode the signal (mis-)using an audio editor and my soundcard as ‘poor mans osciloscope’.

    this is the remotes signal for ‘ch a off’ as captured with audacity:
    http://s1.directupload.net/images/140306/8tbgkgxu.jpg

    I also could rebuild the signal manually as described here
    http://www.dserv01.de/howtos/funksteckdose-fernsteuern-mit-arduino/
    (basically only had to tweak the ‘wait’ function to wait 324 microseconds instead of 350).

    And I also could send an identical signal via RC switch, it detected a PulseLength of 331 microseconds.
    However, in order to have identical signals in my poor-osci I had to use 324 microseconds also for RC switch.

    but now both signals match (top is original remote, on bottom the arduino generated signal):
    http://s1.directupload.net/images/140306/qk6k8s4a.jpg

    what RC switch captures from the orig remote:

    Decimal: 5243156 (24Bit) Binary: 010100000000000100010100 Tri-State: FF00000F0FF0 PulseLength: 331 microseconds Protocol: 1
    Raw data: 10280,352,964,956,372,352,956,944,388,340,976,344,976,352,956,352,972,356,956,360,968,360,964,320,992,348,968,332,996,332,976,964,352,360,968,344,976,348,964,956,376,344,972,952,368,348,972,340,980,

    watchin this in Sui’s oszi:
    http://test.sui.li/oszi/img/33b65d676399c872c3de38360e7c761a.png

    so it all seems to match, but the damn outlets only switch with the remote, but not from the arduino.

    its not a problem in my transmitter setup, I can still switch the RC-710 outlets, and can capture the sent signals as well.

    Any ideas why the problem could be?

    Reply
  11. nicedrop

    Hi. I have a remote made with the HR433A component and references says it is a “One Port SAW Resonator”. (The board is stamped with 0401-3) I’ve tried to clone the remote with a remote cloner device but it does not receive the signal.

    Is your project compatible with this device and/or how would I find out before making the investment in my first Arduino project.?

    Many thanks.

    Reply
  12. Sergio

    Hello! I’m super interested in your project, I too want to implement remote control of home appliances, specially lights and security devices, problem is that my knowledge in electronics is very limited yet I want to build it all my self. The good thing is that I’m a programmer, web apps is my specialty and I can create any app I’d need. So wondering if you were able to advanced with your project and if you were able to create the web/mobile app you wanted?
    If not then maybe we can exchange knowledge, you could share your customized circuits so I can build them myself and I could write code for the apps so we can control these things. If you are interested please let me know….

    Reply
  13. Lasith Jayawardana

    Dear Wes,

    Thanks a million for your tutorial. If configured well, it works like magic!

    I have been having some challenges with trying to marry two different RF remote control systems together, one is 315mhz while the other is on 433mhz.
    With your tutorial it is possible to do that simply by having a 315mhz receiver and a 433mhz transmitter.
    Of course a bit of re-coding the sketches had to be done to have both receive and transmit sketches into one sketch. I can email it to you if you like.
    Thanks once again for a wonderful tutorial.

    Regards

    Lasith

    PS: regarding some posts with range problems, it is my experience that this is due to frequency mismatch.

    Reply
  14. Jeff

    For those having problems with the range of the receiver, I have found a solution that works for me. I am using the MX-05V (315mhz version) to receive signals from my wireless alarm sensors such as motion detectors and door/window sensors.

    Like you, I was having major range issues with the receiver. Even with a 24cm antenna, I couldn’t receive anything from a 315mhz motion detector that was only 6 feet away. It would work from only about two feet away. After pulling my hair out with different antennas, I tried powering my Arduino Uno with a 9 volt battery instead of just using the usb cable (5v). My range went from 2 feet to over 50 feet.

    In case it was a fluke, I went back to the usb cable only and the range dropped again. Plugged the 9v back in, and the range was back to at least 50 feet and has been working ever since. TIFWIW.

    Reply
  15. eugen

    hi I want to clone existing remote control. Example http://www.ebay.co.uk/itm/Electric-Cloning-Universal-Gate-Garage-Door-Remote-Control-Fob-433mhz-Key-Fob-BT-/111510813886?pt=LH_DefaultDomain_3&hash=item19f68ffcbe

    I used RCSwitch and https://bitbucket.org/fuzzillogic/433mhzforarduino/wiki/Home applications.

    I received codes in arduino. RCSwitch is showing …

    Decimal: 5592323 (24Bit) Binary: 010101010101010100000011 Tri-State: FFFFFFFF0001 PulseLength?: 472 microseconds Protocol: 1 Raw data: 14652,448,1448,1420,500,452,1448,1420,512,440,1456,1420,508,448,1456,1420,512,448,1452,1420,508,452,1452,1424,508,448,1456,1424,508,448,1456,1424,512,448,1460,444,1452,432,352,132,1456,448,1452,448,1456,1420,508,1424,508,

    fuzzillogic is showing Code: 531361, period duration: 471us.

    Codes are different 5592323 vs 531361?

    Reply
  16. craigskipsey

    Great post, very helpful. I’m trying to hack my garage door remote, which is a very common one – 315mhz TM-305C So I’m using a 315mhz XD-RF-5V

    But I’m not getting any response in the serial window. Chipset on the remote is HCS200 which has rolling code for security. But surely I should at least be able to receive a signal…? What am i missing?

    Reply
    1. Greg

      I also want to read hcs200, on my remote the is an oscillator ASR433.92, so maybe you to have this freqency.

      Reply
  17. Pingback: RF Resources (433 MHz) - Tamer Çelik

  18. ABC

    sir;
    how u decode the Address bit & Data bit of receiver side.
    Please explain the protocol for decode the code of EV1527 IC
    Thanku

    Reply
  19. ABC

    Sir ,
    I got below HEX code(in real term at 9600 baud rate) when i press the remote key;
    But I didnt understand the which one is data bit & address bit.
    Please explain if u have any idea about this decoding

    I used IC EV1527 for remote purpose & guide me which micro-controller IC used for decoding the code.

    & briefly explain about RAW DATA ,Pulse Length & Button address & data

    FF FF FF FC EB FB FF AF F7 BF FF FF FE FF
    FF DF 7F F5 FF F7 BD FF 5B BF FF 7F BF F3
    FF FF F7 6F 7F DD 5F FF FF FF EF FF AF DF
    FF FD 7F F7 E7 F7 FC FB EF FF 57 FF 6F FF
    FF F7 57 FF EB F7 FF FF FB FD EF 77 77 FF
    D7 DF BF D7 FF F7 F7 AF DF FD FF F7 FF FB
    FF DB FF F6 FF EF B7 7F FF 7D FA FB FF FF
    DF FF FF FF FB FF EF FF BF DF EF FD 7F F7
    F7 FE FF FF EF F5 7F FF FB FF B7 FF 7E FF
    EF FF FF BF F7 DD BB FF FF FF 6F EA FF FF
    7F FD EF EF AD FF EF DF FF FF FF FF FF FB
    FF BF EF FF FF DB BB DD DD BF FF 6D FF FF
    FF FF FF FF FF FF FF FF FF FF FF FF FF FF
    FF FF FF FF FF FF FF FF FF FF FF FF FF FF
    FF FF FF FF FF FF BF FF FF 6F 9B F7 FF FF
    FF F7 FF FD FF FE FF FC FF DF FF FF FF FF
    7F FF BF FF FF FF FF 7F EF FF FF FF FF FB

    Thanks.

    Reply
  20. Amrit

    Hi I want to turn programming on of my multiple arduino boards (10 nos), at the same time with a wireless remote. [i.e. one remote for all 10 arduino uno to perform the same function of resetting/initiating the saved programming at the same time].
    Please help me.
    Email: nikhilbhardwaj32@gmail.com
    THANK YOU!

    Reply

Leave a Reply