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.
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:
There are 4 parts to this tutorial:
- Part 1: Testing the 433 MHz RF transmitter and receiver
- Part 2: Receive and interpret code from an RF remote
- Part 3: Transmit a known 433 Mhz RF code to a 433 Mhz RF device
- Part 4: Record and play back a 433 Mhz RF remote signal - ** you are here **
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:
- Arduino UNO or compatible board
- Breadboard
- Button
- Red and Green LED
- 330 ohm resistor(s)
- Wires
- RF Module (433 Mhz) - Transmitter and Receiver pair
- Mercator Ceiling Fan/Light with Remote
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 ??
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.
Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
Have a look at my videos on my YouTube channel.
Feel free to share this page with your friends in any way you see fit.
Great
ReplyDeleteHello, 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.
ReplyDeleteAt 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.
DeleteOnce you have the stored signal, you can just send it back to another Arduino, and transmit the signal as required.
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 :)
ReplyDeleteThat 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.
DeleteWhile 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 !!
Here is an article that supports the use of a resistor in series.
DeleteBut 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.
Hello,
ReplyDeleteThanks 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.
Thanks.
Ha Ha, I always forget about this floating problem... Well picked up. Thank you.
Delete'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.
DeleteAs 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).
This comment has been removed by the author.
DeleteSorry Scott, forget to paste in the on off signals. See below.
Deletesignal_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
Hi Paul,
DeleteWow - 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.
Sorry Paul,
DeleteI 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...
Hi Paul,
DeleteGeoff Johnson uses a timeDelay of around 222 Microseconds ??
Hi Scott,
DeleteSpent 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.
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)??
DeleteI 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.
Regards
Scott
Hi Scott,
DeleteThe 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.
Hi there,
ReplyDeletebest 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
Possibly because I don't have much knowledge :)
DeleteThanks for the feedback Georg
You have plenty of knowledge Scott. Thanks for a great set of tutorials on RF.
DeleteGreat 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 :)
Delete+Arjan - am glad it worked for you. Thanks for the feedback.
DeleteHi Scott,
ReplyDeleteThank 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?
Hi Matt,
DeleteI 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
This discussion may also enlighten you.
Deletehttps://community.particle.io/t/303-9-mhz-rf-transmitter/9062/9
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.
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!
DeleteHi Matt,
DeleteI was wondering if the 315MHz transmitter worked for you. I am working on a similar project and need advice on where to find a 303.9 module.
Thanks,
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.
ReplyDeletehttp://www.amazon.com/Etekcity-Programmable-Electrical-Converter-Appliances/dp/B00DQELHBS/ref=sr_1_sc_1?ie=UTF8&qid=1435444721&sr=8-1-spell&keywords=ZAP+Outet+switch
@Scott, Can you please guide me what is the next steps to do to get the RF Calibration Table for on/off switch?
This comment has been removed by the author.
DeletePainlessly instructive, thanks.
ReplyDeleteThanks for the feedback
DeleteFirst 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
ReplyDeleteYou 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.
DeleteThanks 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
DeleteHi Omer,
DeletePerhaps 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.
Thanks Scott. I posted to forum
DeleteResponded
DeleteI'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 ?
ReplyDeleteI know nothing about the Raspberry Pi. Actually that is not true. I know what they are, but have never used one.
DeleteIf you want more memory, perhaps consider the Arduino MEGA.
thank you its a great tutorial
ReplyDeletei 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
Hi Elidor,
Delete"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.
Great tutorial
ReplyDeleteBut I have a question it's possible to control a relay with a PS3 controller and Arduino?
thank you
Anything is possible, but I have never tried. Sorry don't know.
DeleteBut I am guessing it is possible.
Great Job!
ReplyDeleteHi 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
ReplyDeleteHi Abdullahi,
DeleteNot 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.
Hi scott
Deletei 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...
than you Scott,
ReplyDeletei think you will help me if i find another problem...
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.
ReplyDeletei update you for upgrades
alt83
Ok - good luck.
DeleteTremendously 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!
ReplyDeleteYes - I agree it is a bit scary.
DeleteBut I am happy it worked for you.
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.
ReplyDeleteHow 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.
Your thinking is correct.
DeleteOnce 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.
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.
ReplyDeleteYes - the transmitter must match the receiver.
DeleteSo 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.
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.
ReplyDeleteI 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.
DeleteHello,
ReplyDeleteThank you for your great tutorials.
Do you have any experience decoding data from weather stations ?
I would like to get data from some Swedish weatherstations sold by Clas Ohlson in Norway and Sweden and store the data in a MySql Database.
They are sold under the name NEXA and produced in China.
regards,
Nils
Hi Nils,
DeleteNo I don't have any experience decoding data from weather stations.
I document my Arduino project experience on this blog.
Sorry.
Great tutorial, learned a lot from your work. Thank you.
ReplyDeleteThanks Marcel
DeleteHi! How would I go about changing the code so that the signal is stored on the board for a long period of time? Could I even use an SD chip to store it?
ReplyDeleteHi,
ReplyDeleteHow would I go about storing the signal on the board for a long period of time? Could I use an SD card or somehow encode the signal without knowing what it is?
Thanks.
That would be very difficult. Mainly because, while you are writing to the SD card, it won't be listening for the signal. So you may miss important parts of a signal.
DeleteBut yes - you could potentially encode the signal to help minimise the writing time.
Not sure if the Arduino would be the best solution for that type of project.
Hello,
ReplyDeleteThank you for your great tutorials. But I have a question it's possible to learn rolling code remote tx.
hi
ReplyDeletenice project can we print the result on lcd and how ?
Years after writing these tuts and they're still the best ones I've found in 2018! Congrats on that.
ReplyDeleteI've got a fancy remote control fireplace that uses a 433mhz remote and it's temperamental at best in the interest of aitomatong everything I got a 433 RX n TX bundle with the intention of learning the codes from the RX then writing a sketch to send them as required using a wemos mini and smartthings hub.
I've sat on the hardware for months not knowing where to start and by chance stumbled upon your guide tonight and buddy you've just reignited this project! (Pun intended)
I've now decided to team it up with an IR TX for more features i.e. turn fire on and TV!
Wouldn't be getting anywhere without your guide so thank you! (I clicked an ad for support!)
Thanks for your support and positive feedback.
DeleteHello!
ReplyDeleteI'm beginning to learn arduino. View Public Profile Send a private message to
"Scott C". I've used your code on the computer, it's done.
But when I use that sketch on the "Arduinodroid" app there is an error:
Line Col Message
36 6 use undeclared identifier 'initVariables'
37 6 use undeclared identifier 'listenForSignal'
44 6 use undeclared identifier 'sendSignal'
Please help me fix it!
Thank you!
I have no experience with Arduinodroid, but my guess is that you have accidentally missed a closing tag or something like that.
Deletehello ...awesome project
ReplyDeleteim working on something my self and i stumbled on to this.... im tring to copy rf codes and send them out of a third party device
im doing home automation
so i would like to see if any one can help me i wan to copy a bunch of rf codes and then send them when i want home automation can send codes via rs232 so im guessing it can be sent to the arduino via rx/tx can any one help
Hi Scott
ReplyDeleteFirst of all, AMAZING series. I was able to scan my Hunter Fan/Light remote control with almost no glitches. The explanations are very detailed.
I have just one question: my control has one on/off button for light and 4 buttons for fan (speeds 1 through 3 plus stop or 0). I was able to code all buttons except for the fan stop. I can read the code, I did it multiple times and I always get the same sequence, but when I try to mirror it with the transmitter, it does not work. I changed the number of sequences (6,12,even 24) and still does not work.
The remote sends series of 78 signals (78 high +78 low)
Any ideas on how to solve this?
Thanks and great work again!
Have you tried using the sketch in tutorial 3?
DeleteMaybe it has something to do with the PWM frequency, and maybe you need to play around with the delays. The fact that you can read the signal is good. But make sure you are receiving the entire signal ? Unfortunately, the only way to get through this is by trial and error. If you have an oscilloscope, you could possibly try to hook up the RF receiver to it to capture the signal that way.
But if you feel confident that you have captured the correct signal, then it is a bit of trial and error to send that code at the correct "frame rate".
Thanks for the prompt answer. Yes, I tried tutorial 3 (all buttons except Fan stop worked) and I even used tutorial 4 (again, same result) . I played with the delays and let it run multiple times until I counted over 20 increases (I think that would mean it went from 5 to 1050 ms) and the fan still would not stop.
DeleteThere is only one thing that I realized may be introducing a variable: if you keep pressed the fan-stop button on the remote for 5 seconds, the receiver performs a different task (it turns light on and dims it after 30 seconds, like a timer so you can walk off the room without being in total dark).
I'll probably try to emulate that full sequence (a 5 second keypress emulation) and see if that works Anyway, I have been playing with all variables and still no luck with that #$!@&* button .If you can think of something else I'm missing, it will be greatly appreciated. Thanks!
I am not sure what to tell you. As you are able to replicate the other codes, I could not see why the stop button is different. The only possible thing that I can think of, is that the capture window that is being used, may not be capturing the entire code. There may be some white-space at the beginning, at the end, or in the middle. And so you may be thinking you have captured the code, but have only captured half of it. Or you are not providing the whitespace at the end (for example). Other than that, I am not sure why that one button does not work for you.
DeleteHello, and thanks for taking the time to help us, if I use the 315Mhz modules, will it work with the current sketch or do I need to change something on the code ?
ReplyDeleteTKS again for youre answer!!!
Como posso receber universal 433 e enviar como fasso
ReplyDeleteC'est vraiment super et ça fonctionne très bien, je vais vous suivre de près, vos explication sont très bonnes. Un gros merci pour tout ce travail.
ReplyDeleteRobert Lupien