30 July 2014

433 MHz RF module with Arduino Tutorial 4:

WARNING: Please check whether you can legally use RF transmitters and receivers at your location before attempting this project (or buying the components). This project is aimed at those who are looking to automate their home.
There are 4 parts to this tutorial:
To get the most out of this tutorial - it is best to start at tutorial Part 1, and then progress to Part 2 then Part 3 and then do Part 4 last. Doing the RF tutorials in this order will help you to understand the process better.

Project 4 : 433 Mhz RF remote replacement tutorial

Carrying on from my previous "433MHz transmitter and receiver" tutorials (1,2 & 3): I have thrown away the need to process the signal with a computer. This means that we can now get the Arduino to record the signal from an RF remote (in close proximity), and play it back in no time at all.
The Arduino will forget the signal when powered down or when the board is reset. The Arduino does not have an extensive memory - there is a limit to how many signals can be stored on the board at any one time. Some people have opted to create a "code" in their projects to help maximise the number of signals stored on the board. In the name of simplicity, I will not encode the signal like I did in my previous tutorials.
I will get the Arduino to record the signal and play it back - with the help of a button. The button will help manage the overall process, and control the flow of code.
Apart from uploading the sketch to the Arduino, this project will not require the use of a computer. Nor will it need a sound card, or any special libraries. Here are the parts required:


Parts Required:

Fritzing Sketch



Arduino Sketch


Now let's see this project in action !
Have a look at the video below to see the Arduino turning a light and fan on/off shortly after receiving the RF signal from the RF remote. The video will also show you how to put this whole project together - step by step.

The Video


This concludes my 433MHz transmitter and receiver tutorials (for now). I hope you enjoyed them.
Please let me know whether this worked for you or not.
I have not tested this project with other remotes or other frequencies - so would be interested to find out whether this technique can be used for ALL RF projects ??


If you like this page, please do me a favour and show your appreciation :

  Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
Have a look at my videos on my YouTube channel.



However, if you do not have a google profile...
Feel free to share this page with your friends in any way you see fit.


  1. Hello, Nice explanation. This helps to understand the basic principle for receiver and transmitter using arduino. Just another query it is possible to take a note of the sniffed data from existing remote and play the same data via another transmitter using arduino. Basically I want o first read the data from each button of the existing RF remote and use the data in my transmitter to play it.

    1. At the end of the Arduino code - you will see a section which allows you to transmit the signal to the serial monitor. You could send the signal to an SD card, or just store them on your computer using the Processing IDE . I assume you have already looked at tutorials 1 - 3.
      Once you have the stored signal, you can just send it back to another Arduino, and transmit the signal as required.

  2. Hei, thanks for your interesting tutorial. I'm a newbie to Arduino and I wonder how come the LED on pin 13 and ground wouldn't burn without any resistor. Thank you :)

    1. That is a good question. Some people say that there is an onboard resistor attached to pin13, while others say that newer boards don't have this resistor.
      While I have used this technique numerous times without any problems, I would recommend that you either stick with the onboard LED, or attach a resistor in series (just in case).
      Excellent question !!

    2. Here is an article that supports the use of a resistor in series.
      But in the comments of that article, there are people that say that some Arduino boards have an onboard resistor in series with pin13.

      Use this technique at your own risk. But thank you for this question. Because I think I will recommend a resistor in future tutorials.

  3. Hello,

    Thanks for your tutorials, however on tutorial #4 your push button is floating so it will turn on at random, it's much better to make use of the internal pull-up resistor by adding the following to void setup() :-

    digitalWrite(button, HIGH);

    Then change the coding so buttonVal==HIGH becomes buttonVal==LOW and wire the button so when pressed it goes to GND.

    In this state the button is always pulled up HIGH and GND pulls it LOW when the button is pressed, otherwise the button will float and trigger randomly.


    1. Ha Ha, I always forget about this floating problem... Well picked up. Thank you.

    2. 'Anonymous' or Scott can please you provide a few more details on the code and circuit changes to remove the floating button issue. Also for the serial print to be effective as it is hit and miss at the moment with the floating button.

      As an interim I worked out that the best way to get a reliable recording is to have the button switched on when the Arduino is reset. This is giving excellent results and I'm truly amazed at how effective this is.

      It is managing to record and playback all ID's for 'type 2' devices that were failing as highlighted in my post on the tutorial 2 page. It is also working for some RF activated relays that I will call type 3 devices. Strangely it is still not working for type 1 devices. Type 1 are Status remote sockets as shown at http://www.amazon.co.uk/Status-SREMSOC3PK3-Remote-Control-Socket/dp/B003XOXAVG

      The protocol for the Status remote sockets is covered in Geoff Johnson's article at http://www.hoagieshouse.com/RaspberryPi/RCSockets/RCPlug.html

      Scott is there any reason why your sketch isn't able to record and playback this protocol?

      For reference I have included below an on and an off signal for the Status remote sockets as recorder by rtl_433.exe (rtl recording software for windows).

    3. This comment has been removed by the author.

    4. Sorry Scott, forget to paste in the on off signals. See below.

      signal_len = 85221, pulses = 174
      Iteration 1. t: 156 min: 79 (76) max: 234 (98) delta 125
      Iteration 2. t: 156 min: 79 (76) max: 234 (98) delta 0
      Pulse coding: Short pulse length 79 - Long pulse length 234

      Short distance: 65, long distance: 221, packet distance: 2378

      p_limit: 156

      [00] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [01] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [02] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [03] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [04] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [05] {25} 04 db fb 00 : 00000100 11011011 11111011 00000000
      [06] {24} 04 db fb 00 : 00000100 11011011 11111011 00000000

      *** signal_start = 312812343, signal_end = 312878215
      signal_len = 65872, pulses = 124
      Iteration 1. t: 156 min: 79 (59) max: 234 (65) delta 212
      Iteration 2. t: 156 min: 79 (59) max: 234 (65) delta 0
      Pulse coding: Short pulse length 79 - Long pulse length 234

      Short distance: 66, long distance: 222, packet distance: 2379

      p_limit: 156

      [00] {25} 04 db f3 00 : 00000100 11011011 11110011 00000000
      [01] {25} 04 db f3 00 : 00000100 11011011 11110011 00000000
      [02] {25} 04 db f3 00 : 00000100 11011011 11110011 00000000
      [03] {25} 04 db f3 00 : 00000100 11011011 11110011 00000000
      [04] {24} 04 db f3 00 : 00000100 11011011 11110011 00000000

    5. Hi Paul,
      Wow - you seem to be knee deep in RF signals :)
      I was just about to respond to you, to ask if you had a chance of looking at Tutorial 4, when I came across this message... so looks like you have managed to work your way through most of your problems....
      I would like to say that I did have to go through a bit of trial and error, and sometimes got a bit confused by the RF results that I was getting. There are few sites that explain that there is a delay when you write to the pin, and then go on explain the frequency calculations.

      To solve the Floating push button - read this tutorial.

      I am not seeing your on/off signals recorded by rtl_433.exe
      You may want to expand the dataSize variable to a higher value, and once you know the length of the signal, bring it down to what-ever number you discover. I think the maximum number you can use for this variable is 1700 (on an Arduino UNO) - due to memory restrictions. But see how you go.
      And you may need to play around with the timeDelay variable as I did in Tutorial 3. You might want to incorporate the calibration process into this tutorial??

      And finally, I think Geoff Johnson noted that HIGHs and LOWs were reversed in his sketch. I think I had a similar issue, so you may want to try reversing them to see if that helps.

    6. Sorry Paul,

      I re-posted my message because I needed to change something and add something. And now I see you have posted your signals... but I don't know if it actually helps me to figure out what is happening on your side...

    7. Hi Paul,

      Geoff Johnson uses a timeDelay of around 222 Microseconds ??

    8. Hi Scott,

      Spent a few hours yesterday trying to 'crack' the Status sockets but no joy. Strange thing is the relays I use have a RF signal 'learn' facility and when I use the Status remote to 'teach' them the RF they are controlled by your sketch. The same applies when I use another well done RF library.

      Cloned another RF device earlier today. It is a 'security' device which I will call type 4. So types 2, 3 and 4 working well but not type 1, yet.

    9. Paul - Glad to hear that this is working for so many of your devices - but there is obviously something different about your "type 1" device. Check to make sure that it is not using a rolling code (after some time)??
      I will also advise you to post your question to the Arduino Forums... tell them what you are trying to do, what you have done, and see if the "experts" can get you on the right track.
      Show the code you are using - as this may help narrow down the issue.

      I would be interested in the outcome - so please post a link to your forum post.


    10. Hi Scott,
      The Status sockets (type 1 device) do not use rolling codes of any type. Looking at the devices that your sketch controls compared with the one type that is doesn't (excluding rolling codes of course) the common factor appears to be signal length. Your sketch works where the long pulse is double the short pulse but Status sockets have long pulses three times the length of the short pulses. This is the only factor I can see different, plus maybe the reversing of the signal (low becomes high and high becomes low).

      For reference Pilight has no trouble controlling the Status sockets.

      Can you please contact me via Facebook.

  4. Hi there,
    best wishes from Germany. I started the other way round. Found these cheap modules on Ebay where they are available for less than 1 Euro, if you take five of them. That's only about half the amount you have to pay for a beer in a pub here. Looking for information after the purchase I found your tutorials. It was a really good idea to keep them simple. I am still a beginner with the Arduino and those explanations on the internet where the authors try to impress the reader with their knowledge are not helpful. So yours on the contrary is very helpful.
    Thanks says Georg

    1. Possibly because I don't have much knowledge :)

      Thanks for the feedback Georg

    2. You have plenty of knowledge Scott. Thanks for a great set of tutorials on RF.

    3. Great stuff. Works like a charm. Since I am a beginner at Arduino stuff too, this post was really helpful to start getting up to speed and have fun at the same time :)

    4. +Arjan - am glad it worked for you. Thanks for the feedback.

  5. Hi Scott,

    Thank you for creating this tutorial! I am new to electronic/Arduino and have decided to use your tutorial to build my first real project for the home.

    The ceiling fans in my home seem to operate on 303.9MHz according to the FCC docs (https://apps.fcc.gov/oetcf/eas/reports/ViewExhibitReport.cfm?mode=Exhibits&RequestTimeout=500&calledFromFrame=N&application_id=u9yrEznUvQJtU3fTqdh%2BxA%3D%3D&fcc_id=L3HFAN-9T). Do you think the 315MHz receiver/transmitter would work for me?

    1. Hi Matt,
      I don't think the 315MHz transmitter will work with your fan - but I'm not 100% sure. However, the modules are so cheap, that it might be worth trying. If you want to make your own transmitter, then this article may be useful: http://www.talkingelectronics.com/projects/27MHz%20Transmitters/27MHzLinks-3.html

    2. This discussion may also enlighten you.

      I did not read all of it - so don't know if they figured it all out in the end.
      But looks like they were trying to do the same thing as you.

    3. Thanks for your reply, Scott. I think I will go ahead and buy the transmitters on the off chance that they do work (like you said, incredibly cheap). I'll be sure to report back with my findings just in case anyone else is looking for this information in the future. Thanks again!

  6. Forgive me for being a slow follower and thank you so much for this tutorial. I have been studying your tutorial for a few days now and still confused. I enabled the "view signal serial monitor". and got the log (listed below) when pressed the channel 1 o the ZAP Outet switch transmitter.


    @Scott, Can you please guide me what is the next steps to do to get the RF Calibration Table for on/off switch?

    1. Hi Unknown,

      I have moved your query to the ArduinoBasics forum - which is a much better place to discuss this type of thing: http://arduinobasics-forum.1116184.n5.nabble.com/Quick-questions-about-ArduinoBasics-projects-f3.html

      Thank you very much Paul Alcock for your response to Unknown's question. Just letting you know that I moved your response to the forum also.


  7. First of all thanks for sharing Scott. I tried this project and it works very well. I want to ask that; if we want to add 6 button have the same features, how arrange circuit and program code sketch? Help me please

    1. You may find that you have to re-use some variables - otherwise you may run out of memory. My advise is to try to add just one extra button... and then the rest will become clear. Give it a go - and if you still cannot get that to work - let me know.

    2. Thanks for your reply Scott. I've tried add a button and connected to arduino like other button. Also tried to change code configuration but it doesn't compile. There was too much error. I think I'm not good at programming

    3. Hi Omer,

      Perhaps paste your code and take a picture or show a diagram of you setup by posting these to the ArduinoBasics forum. I will have a look, and make the necessary recommendations from there.

    4. Thanks Scott. I posted to forum

  8. I'd like do to the same with a raspberry to not have the memory limitation and being able to listen for a longer period of time. Do you know of any project/code that would do that ?

    1. I know nothing about the Raspberry Pi. Actually that is not true. I know what they are, but have never used one.
      If you want more memory, perhaps consider the Arduino MEGA.

  9. thank you its a great tutorial
    i have a question lets say i want to control an rf relay module with remote .
    the rf relay have only receiver , can arduino know if the relay is on HIGH or LOW without the transmitter module on the rf relay ?
    thank you

    1. Hi Elidor,
      "If a tree falls in a forest and no one is around to hear it, does it make a sound?"

      You can transmit to the relay module, but will not know if it is actually on or not, unless you send some message back to the transmitting Arduino. If you test it and find that it works 100% of the time, then you could "assume" that it has worked, but will never know for sure.

      There has to be some signal back, (eg. RF response, or change in Light, or sound or something that you can receive from the relay event - providing the transmitting Arduino is in a place to be able to receive that signal.)

      Or you just trust that it happened.

  10. Great tutorial
    But I have a question it's possible to control a relay with a PS3 controller and Arduino?
    thank you

    1. Anything is possible, but I have never tried. Sorry don't know.
      But I am guessing it is possible.

  11. Hi scott C i have a problem with tutorial 4 that Mercator Ceiling Fan Light Remote you say it doesent fuond in my country, what i can do anather option

    1. Hi Abdullahi,
      Not sure what other ceiling fan/lights are out there ?
      I was just lucky enough that the fan that I had was using 433 Mhz RF to communicate. Maybe look for a fan that has a remote and then ask what frequency it uses ? Some countries use 315 MHz... I guess it just depends on what is legal in your country and what is available. But I am not an expert in fans.

    2. Hi scott
      i need your help,
      i have probleb with toturial 4 code that i used in arduini version 1.6.12 then when i generate the code the result is some error looklike this (Project_codes:41: error: stray '\240' in program

      Project_codes:43: error: stray '\302' in program
      ), what is your advice?
      thank you...

  12. than you Scott,
    i think you will help me if i find another problem...

  13. Excellent job. All this worked at first time with remote controller compatible with RC-Switch library. I used it with came remote controller and i doesn't work. I think noisy or sketch issues. I decoded came rf using tutorial 2 approach. The code was shorter and it didn't send correctly for missing high pulse. if i use sketch of tutorial 3 i sent code correctly but this not work.
    i update you for upgrades


  14. Tremendously helpful and worked first time due to very clear explanation through the tutorial, thank you. It's quite scary to think about the power in this little project!

    1. Yes - I agree it is a bit scary.
      But I am happy it worked for you.

  15. Thanks you for your tutorials. I was looking into purchasing these modules for my arduino for a project that I am working on. I have learned quite a bit from your information. I do have a question.

    How does the learning loop know when to end? From the code that I see, it keeps looking for a signal until the datasize/2 is reached. I guess I would code in some timeout in there, that if there is not a signal after a period of time it breaks the loop. Is my thinking correct here or did I miss something.

    1. Your thinking is correct.
      Once it starts recording, it just stops once the data limit is reached. It doesn't matter if it records silence after the signal has ended, just as it does not matter if it plays back silence after the signal is transmitted. The limitation of my code, is that the data limit may not be big enough to capture the entire signal. But if you followed all 4 tutorials on this topic, you would know how to check that (trial and error).
      There is definitely room for improvement in my code, and there is no harm in programming a timeout feature. In fact, it could be quite useful.

  16. Your tutorials have been very informative and interesting to work on. I've been trying to get another type of wireless device to work with this approach, and so far no luck. I've been able to get the signal from the remote to be recognized and it appears to be the same each time, however it doesn't turn on the device when broadcasted. My thought is perhaps the delay isn't right but I'm not sure. I also noted the back of my receiver lists 315/330/433 MHZ but the transmitter is only 433, that could be it as well. Thanks again for the good work.

    1. Yes - the transmitter must match the receiver.
      So if you are using a 315MHz receiver to receive the signals, then you should be using a 315Mhz transmitter. The range of the transmitter may also need to be considered.

  17. Hello is there a scetch that will clone, store and playback the diferent frequencies from my RF remote using and ESP8266 Wemos d1 mini or NodeMCU with connceted Arduino RF trassmiter and receiver modules? I want to be able to control my cielling fan via the internet.

    1. I don't have a sketch that would do that. But this tutorial will show you how to do the RF side of the project. And once that is done, all you have to do is set up the web-based side. I am sure there are projects out there that could help you with the web-based side. And just put the two together.


Feel free to leave a comment about this tutorial below.
Any questions about your particular project should be asked in the ArduinoBasics forum.

Comments are moderated due to large amount of spam.