Pages

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.

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:

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 :

56 comments:

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.

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.

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 !!

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.

'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).

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.

I am not seeing your on/off signals recorded by rtl_433.exeYou 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.

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...

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.

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.

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).

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

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?

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

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!

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.

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

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.

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

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

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.)

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.

Hi scotti 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

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

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.

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.

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.

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.