You are on page 1of 13

13

Liên kết khác

Blog tiếp theo»

Tạo Blog

Đăng nhập

Arduino Basics
An Arduino blog that follows the footsteps of an enthusiastic Arduino user, from the ground up. Level : Basic
Home

Arduino Basics Projects Page

Feedback Page

27 June 2014

Search This Blog

433 MHz RF module with Arduino Tutorial 2

Search

Translate
Chọn Ngôn ngữ
Được hỗ trợ bởi

Dịch

Pages
Arduino Basics Projects Page
Arduino Basics YouTube
Videos
Feedback Page
Home

Subscribe
Posts
Comments

Project 2: RF Remote Copy

My Arduino Videos

In the previous project, we transmitted a signal wirelessly from one Arduino to another. It was there to help
troubleshoot communication between the modules. It was important to start with a very short distance (1-2
cm) and then move the RF modules further apart to test the range. The range can be extended by soldering
an antenna to the module, or by experimenting with different voltage supplies to the modules (making sure to
keep within the voltage limits of the modules.)
In this project - we aim to receive a signal from an RF remote. The remote that I am using is a Mercator
Remote Controller for a Fan/Light. (Remote controller code is FRM94). It is important that you use a remote
that transmits at the same frequency as your receiver. In this case, my remote just happens to use a
frequency of 433MHz. I was able to receive RF signals from from a distance of about 30cm without an
antenna (from my remote to the receiver).

Video

pow ered by

Receiver or the 315 Mhz version Remote Controller You can quickly test your remote. by pressing one of the buttons in close proximity to the RF receiver (using the same sketch as in Project 1).613 . If you don't see the LED flickering.Blog Archive ▼ 2014 (9) ► November (1) ► October (1) ► September (2) ► August (1) ► July (2) ▼ June (2) 433 MHz RF module with Arduino Tutorial 2 433 MHz RF module with Arduino Tutorial 1 ► 2013 (13) Here are the parts that you will need to carry out this project: ► 2012 (11) ► 2011 (25) Parts Required 1 x Arduino UNO or compatible board Total Pageviews Breadboard Wires Mercator FRM94 Remote Controller for Fan/Light (Transmitter Model: TR107A) RF Module (433 Mhz) .052. and you should see the LED flicker on an off in response to the button press. Here is a picture of the remote controller that I am using: 1. then this project will not work for you.

//upper threshold value const unsigned int lowerThreshold = 80. So you will need to have the Serial monitor open when you press the remote control button.. //Turn LED ON //Read and store the rest of the signal into the storedData array for(int i=0. Once triggered. //Update start time with every cycle. I only really needed 300 data points.blogspot.. //Variable to record the start time unsigned long endTime=0. //Variable to measure the length of the signal unsigned long startTime=0.0. i=i+2){ //Identify the length of the LOW signal---------------LOW dataCounter=0. and that they can be different lengths. because there was a "flat" signal for the last 200 data points (characterised by 200 repetitions of a LOW signal length of 0 and HIGH signal length of 255) -------------------------------------------------- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 /* RF Remote Capture sketch Written by ScottC 24 Jun 2014 Arduino IDE version 1.Arduino Sketch . //Arduino memory is limited (max=1700) byte storedData[dataSize].begin(9600). it will turn the LED ON. This sketch aims to identify how long each LOW and HIGH signal is (to make up the complete RF remote signal). HIGH).com Receiver: XY-MK-5V Description: Use Arduino to Receive RF Remote signal ------------------------------------------------------------. The remote control signal will be made up of HIGH and LOW signals .//reset the counter . In my case. //Set the maximum length of the signal int dataCounter = 0. and start to collect and store the signal data into an array.Remote Receiver The following sketch will make the Arduino wait until a signal is detected from the remote (or other 433 MHz RF device). pinMode(ledPin.*/ const int dataSize = 500. OUTPUT).*/ while(analogRead(rfReceivePin)<1){ //Wait here until a LOW signal is received startTime=micros().You may wish to increase or decrease the dataSize variable to accomodate your specific RF signal.which I will try to illustrate later in the tutorial. I have chosen to capture 500 data points(or 250 LOW/HIGH combinations). /* The following code will only run ONCE ----------------Press the reset button on the Arduino to run again-. } storedData[i]=dataCounter.The aim is to get the Arduino to focus on reading ONLY. But for now. //lower threshold value int maxSignalLength = 255. it will report the signal data to the Serial monitor. //Identify the length of the HIGH signal---------------HIGH dataCounter=0. and once the reading phase is complete. I did my best to keep the signal reading section of the sketch free from other functions or interruptions.5 Website: http://arduinobasics. //Variable to record signal reading time void setup(){ Serial. //Variable to record the end time unsigned long signalDuration=0. all you need to know is that the Signal will alternate between HIGH and LOW signals. //Create an array to store the data #define ledPin 13 //Onboard LED = digital pin 13 #define rfReceivePin A0 //RF Receiver data pin = Analog pin 0 const unsigned int upperThreshold = 100. i<dataSize. //reset the counter while(analogRead(rfReceivePin)>upperThreshold && dataCounter<maxSignalLength){ dataCounter++. } digitalWrite(ledPin.

55 //The LOW or HIGH signal length must be less than the variable "maxSignalLength" 56 //otherwise it will be truncated. 58 //The maximum number of signals is 1700 .HIGH"). 81 } 82 } 83 84 void loop(){ 85 //Do nothing here 86 } 87 Receiver Fritzing Sketch .49 while(analogRead(rfReceivePin)<lowerThreshold && dataCounter<maxSignalLength){ 50 dataCounter++.//Turn LED OFF 67 68 //Send report to the Serial Monitor 69 Serial. 64 signalDuration = endTime-startTime. otherwise it will be truncated.if you try to extend this variable to a higher 59 //number than 1700 . 72 Serial. 80 delay(20). 65 66 digitalWrite(ledPin. //Record the end time of the read period.then the Arduino will freeze up and sketch will not work.println(" microseconds"). 79 Serial.print(". 51 } 52 storedData[i+1]=dataCounter.print("Read duration: "). 60 //------------------------------------------------------------61 } 62 63 endTime=micros(). i=i+2){ 77 Serial. 71 Serial. All of the HIGH signals and LOW signals combined 57 //must not exceed the variable "dataSize".println("LOW. 76 for(int i=0.println("====================="). 78 Serial. LOW).println(storedData[i+1]).print(signalDuration). i<dataSize.print(storedData[i]). 73 Serial."). 75 delay(20).println("====================="). 53 54 //Any readings between the two threshold values will be ignored. 70 Serial. 74 Serial.

the data signal is printed to the Serial Monitor.Results After pressing the button on the RF remote. This is an example of the signal produced after pushing the button on the remote for turning the fan/light on. You can copy the data to a spreadsheet program for review. .

. I then used a formula in the spreadsheet to calibrate the readings and make them a bit more uniform. If it was less than 4 analogReads. I grabbed the LOW column and produced the following chart: The chart above is a bit messy . then I converted it to 2. in that sometimes it can squeeze an extra read from a particular signal. I have drawn a couple of red dotted lines where I believe most of the readings tend to sit.The following code was produced from pushing the button responsible for turning the light off: The code sequence above may seem a bit random until you start graphing it.. **The meaning of "frequency" in the following tables relate to the "number of times" a specific signal length is recorded. and just decided to pick the two values (2 for short.mainly because the timing is slightly out. But what is important to note here is that you can differentiate a LONG signal from a SHORT signal. but there were more 6's overall. then I converted this to 6. I could have chosen 5 as the LONG value. For example. and 6 for long) based on the frequency tables below. if the length of the signal was greater than 4 analogReads. I used a frequency table to help decide on the cutoff value of 4..

I helped to identify the sections with vertical red lines (near the bottom of the chart). In other words. I then did the same for the HIGH signal column and combined the two to create the following chart: . the signal produced by the remote is repeated 6 times.And this is the resulting chart: You will notice that the pattern is quite repetitive.

or long yellow bar VLH = [Very long HIGH} signal .or long blue bar LH = [Long HIGH] signal . . This is almost a break to separate each section.or short blue bar SH = [Short HIGH] signal . however have a Very long length at the end of each section.You will notice that the HIGH signals also have a repetitive pattern. .or short yellow bar LL = [Long LOW] signal .or very long yellow bar (~92 analogReads in length) You will notice that there are only about 6 different combinations of the signals mentioned above. The charts below show the difference between turning the LIGHT ON and LIGHT OFF. We can use this to create a coding system as described below: We can use this coding system to describe the signals. This is what a single section looks like zoomed in: SL = [Short LOW] signal.

we will use the code acquired from the remote to turn the FAN LIGHT on and off (using the 433 MHz RF transmitter).which generally occurs after the signal is complete. . This is actually a timeout sequence . In the next tutorial. Here is an example of what I mean.255) combinations. This is the end of tutorial 2.PLEASE NOTE: You may notice when you copy the signals from the Serial monitor that you get a series of (0.

Reply Replies Scott C 1 August 2014 at 00:13 Hi Jeroen. Now i want to receive and let the arduino make a sound or something like that. I think I understand your question. Arduino. Anyway . that you have to transmit them the other way around (LOWs become HIGHs and vice versa). Please be aware that somewhere in tutorial 1&2 I have managed to get LOWs and HIGHs mixed up. You want the Arduino to listen for a specific code. but that is not my question. please can you give a hint or better write a tutorial how to receive the code found in tutorial 2 to start a sub in the sketch? thanks for this great work. This signal will be stored within the array called . Or maybe I haven't. thanks for your reaction. i have no idea how to start arduino listen only to the found code ? i hope my question is now better. plus the flow of information is specific to your question. Can you please explain what you mean by "Start a sub in the sketch" ?? If you want to know how to transmit the code you acquired in tutorial 2. i want to receive de code with the arduino! i have a pir sensor sending 433Mhz codes. Receiver. Remote. and then get it to do something else ONLY when it receives that code. it's easy to follow.where multiple respondents can provide relevant info and code snippets etc. This kind of question is always best served within an Arduino forum . See how you go. code. caroline & Jeroen 1 August 2014 at 05:50 Hi Scott. Jeroen.Click here for Tutorial 3 Posted by Scott C at 01:05 +13 Recommend this on Google Labels: 433Mhz. RF 9 comments: caroline & Jeroen 31 July 2014 at 23:12 Thanks for this tutorial. Having said that .which will show you how to get the Arduino to listen for the signal. ArduinoBasics. Capture. good explanation. i have found the code. i have also read tutorial 3 where you send the code with the Arduino. then continue on to tutorial 3.you will find that when you are transmitting the code. as i say.. i have managed to retrieve the code from a pir sensor.your best bet is to have a look at tutorial 4 . (sorry my english is not very good) Scott C 1 August 2014 at 08:29 Hi Jeroen.

and may need to go back and revisit where I have gone wrong. IS. Best regards. upgraded it according to my previously non-working socket (added High medium low) set and used it to calculate combinations. but there is a lot of room for improvement. there should be different timeDelay lengths as in my case one is 115 and the other is 150 (middle values). that pair 0. but not the other set.. Miroslav J..255 should be 0 for HI and 255 for LO as it should be "silent" for a while.but please post your question on the Arduino Forum .I've been busting my brain with the rcswitch library as I have 2 different remote socket sets and they work with different protocols and I was able to control one.because it would almost be a whole tutorial in itself ..html . So i made it a bit simpler for me. You can then use a function to clean up the signal using "IF" statements. YOU made it work for me! Thank you again. Tutorial 4 is where I wanted to end up.storedData[]. } You will need to do this also for values above or equal to 4.I still have a wireless doorbell to try with. As you already assumed.blogspot.. What I did was to use M$ Excel for code calculation. you may only be interested in the first 10 or first 1000 values. I must point out. and I managed to do this is in tutorial 4. Good Luck Miroslav Jernejšek Perec 19 August 2014 at 19:31 Hi Scott. perhaps even with calculated timeDelay.. Keep up the good work and keep in touch. whereas Tutorial 1-3 just show how I got there.. that the pairs (HI.LO) in your sketch are correct. Perec (mirojp) Scott C 23 August 2014 at 12:46 Thanks for the feedback Miroslav !! I know I have somehow managed to reverse HIGHs and LOWs somewhere in my investigation process. but it also lets me believe we could replicate almost any "as simple as these" control signal.and feel free to come back a leave a link to your forum query in the comments.. Once you have cleaned up the code. where I used the combination table. So at this point I have 3+4 sockets.. eg. Thank you for your tutorial a 1000 times. Glad to hear that it worked for you !! Scott C 23 August 2014 at 12:48 Here is the link for tutorial 4: http://arduinobasics. Amazing. This... And would have to find a way to match these values in the storedData[] array with the pre-defined code you speak of. but not also in the table.com/2014/07/433-mhz-rf-module-with-arduinotutorial_30. I can't go through the details here . I wanted a quick way to record the signals and play them back without the need of Excel or a computer.. I figured out from received timeouts. I can control with your code fragments. if(storedData[i]<4){ storedData[i]=2.. as you already mentioned. including the scanner that would display a code to use.

I don't mind how you use my code. So far I've often seen the suggestion to hook up the receiver to your computer's Mic In and record the signal with Audacity. (In the hope of getting the best of both worlds. I'm trying to read a weather station's signal (and ultimately decode it). When I started this project. Not sure if it works for anyone else. When it did work. and would be happy with just a reference link back to this blog somewhere in your code or Github. Comment as: Publish Google Account Preview Feel free to leave a comment : Links to this post Create a Link Newer Post Home Subscribe to: Post Comments (Atom) Older Post . I'm thinking of increasing the Arduino's analogread speed to improve the resolution. great tutorial — thank you for the work.Reply tj 9 October 2014 at 20:09 Hi Scott. Tom Reply Replies Scott C 9 October 2014 at 23:48 Hi Tom. Reply Enter your comment. The audio ADC's sample rate is high enough to produce a very detailed graph.) Is your code available under an open license? I'd throw the result on Github (assuming I produce something sensible)... I did a little happy dance. and I'll give this method a go. and then simply analyze the waveform visually. I would be interested to hear how your project turns out. I did not know if it was going to work or not. Anyway. Providing that your project is legal.

3k This Week's Most Popular Posts Most Recent Posts 433 MHz RF module with Arduino Tutorial 1 One in a million HC-SR04 Ultrasonic Sensor DIY Canon Intervalometer using Arduino Simple Arduino Serial Communication Bluetooth Tutorial 1 Arduino Selfie Relay Module Grove Water Sensor Bluetooth Android Processing 1 Recent Posts Widget by Helplogger Awesome Inc. template.2. . Powered by Blogger.