Arduino Basics - 433 MHZ RF Module With Arduino Tutorial 2
Arduino Basics - 433 MHZ RF Module With Arduino Tutorial 2
Lin kt khc
To Blog
ng nhp
Arduino Basics
An Arduino blog that follows the footsteps of an enthusiastic Arduino user, from the ground up. Level : Basic
Home
Feedback Page
27 June 2014
Search
Translate
Chn Ngn ng
c h tr bi
Dch
Pages
Arduino Basics Projects Page
Arduino Basics YouTube
Videos
Feedback Page
Home
Subscribe
Posts
Comments
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
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) - 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), and you should see the LED flicker on an off in response to the button
press. If you don't see the LED flickering, then this project will not work for you.
Here is a picture of the remote controller that I am using:
1,052,613
--------------------------------------------------
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.0.5
Website: http://arduinobasics.blogspot.com
Receiver: XY-MK-5V
Description: Use Arduino to Receive RF Remote signal
------------------------------------------------------------- */
const int dataSize = 500; //Arduino memory is limited (max=1700)
byte storedData[dataSize]; //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; //upper threshold value
const unsigned int lowerThreshold = 80; //lower threshold value
int maxSignalLength = 255; //Set the maximum length of the signal
int dataCounter = 0;
//Variable to measure the length of the signal
unsigned long startTime=0; //Variable to record the start time
unsigned long endTime=0;
//Variable to record the end time
unsigned long signalDuration=0; //Variable to record signal reading time
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
/* The following code will only run ONCE ----------------Press the reset button on the Arduino to run again-- */
while(analogRead(rfReceivePin)<1){
//Wait here until a LOW signal is received
startTime=micros(); //Update start time with every cycle.
}
digitalWrite(ledPin, HIGH); //Turn LED ON
//Read and store the rest of the signal into the storedData array
for(int i=0; i<dataSize; i=i+2){
//Identify the length of the LOW signal---------------LOW
dataCounter=0; //reset the counter
while(analogRead(rfReceivePin)>upperThreshold && dataCounter<maxSignalLength){
dataCounter++;
}
storedData[i]=dataCounter;
//Identify the length of the HIGH signal---------------HIGH
dataCounter=0;//reset the counter
49
while(analogRead(rfReceivePin)<lowerThreshold && dataCounter<maxSignalLength){
50
dataCounter++;
51
}
52
storedData[i+1]=dataCounter;
53
54
//Any readings between the two threshold values will be ignored.
55
//The LOW or HIGH signal length must be less than the variable "maxSignalLength"
56
//otherwise it will be truncated. All of the HIGH signals and LOW signals combined
57
//must not exceed the variable "dataSize", otherwise it will be truncated.
58
//The maximum number of signals is 1700 - if you try to extend this variable to a higher
59
//number than 1700 - then the Arduino will freeze up and sketch will not work.
60
//------------------------------------------------------------61 }
62
63 endTime=micros(); //Record the end time of the read period.
64 signalDuration = endTime-startTime;
65
66 digitalWrite(ledPin, LOW);//Turn LED OFF
67
68 //Send report to the Serial Monitor
69 Serial.println("=====================");
70 Serial.print("Read duration: ");
71 Serial.print(signalDuration);
72 Serial.println(" microseconds");
73 Serial.println("=====================");
74 Serial.println("LOW,HIGH");
75 delay(20);
76 for(int i=0; i<dataSize; i=i+2){
77
Serial.print(storedData[i]);
78
Serial.print(",");
79
Serial.println(storedData[i+1]);
80
delay(20);
81
}
82
}
83
84
void loop(){
85
//Do nothing here
86
}
87
Results
After pressing the button on the RF remote, the data signal is printed to the Serial Monitor. You can copy the
data to a spreadsheet program for review. This is an example of the signal produced after pushing the button
on the remote for turning the fan/light on.
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. I grabbed the LOW column and produced the following chart:
The chart above is a bit messy - mainly because the timing is slightly out... in that sometimes it can squeeze
an extra read from a particular signal. But what is important to note here is that you can differentiate a
LONG signal from a SHORT signal. I have drawn a couple of red dotted lines where I believe most of the
readings tend to sit. I then used a formula in the spreadsheet to calibrate the readings and make them a bit
more uniform. For example, if the length of the signal was greater than 4 analogReads, then I converted this
to 6. If it was less than 4 analogReads, then I converted it to 2. I used a frequency table to help decide on
the cutoff value of 4, and just decided to pick the two values (2 for short, and 6 for long) based on the
frequency tables below. I could have chosen 5 as the LONG value, but there were more 6's overall.
**The meaning of "frequency" in the following tables relate to the "number of times" a specific signal length
is recorded.
You will notice that the pattern is quite repetitive. I helped to identify the sections with vertical red lines (near
the bottom of the chart). In other words, the signal produced by the remote is repeated 6 times.
I then did the same for the HIGH signal column and combined the two to create the following chart:
You will notice that the HIGH signals also have a repetitive pattern, however have a Very long length at the
end of each section. This is almost a break to separate each section.
This is what a single section looks like zoomed in:
You will notice that there are only about 6 different combinations of the signals mentioned above. We can
use this to create a coding system as described below:
We can use this coding system to describe the signals. The charts below show the difference between
turning the LIGHT ON and LIGHT OFF.
PLEASE NOTE: You may notice when you copy the signals from the Serial monitor that you get a series of
(0,255) combinations. This is actually a timeout sequence - which generally occurs after the signal is
complete.
Here is an example of what I mean.
This is the end of tutorial 2. In the next tutorial, we will use the code acquired from the remote to turn the FAN
LIGHT on and off (using the 433 MHz RF transmitter).
9 comments:
caroline & Jeroen 31 July 2014 at 23:12
Thanks for this tutorial.
it's easy to follow, good explanation,
i have managed to retrieve the code from a pir sensor.
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,
Jeroen,
Reply
Replies
Scott C
Hi Jeroen,
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, then continue on to
tutorial 3.
Please be aware that somewhere in tutorial 1&2 I have managed to get LOWs and HIGHs
mixed up. Or maybe I haven't. Anyway - you will find that when you are transmitting the
code, that you have to transmit them the other way around (LOWs become HIGHs and vice
versa).
See how you go.
Scott C
Hi Jeroen,
I think I understand your question. You want the Arduino to listen for a specific code, and
then get it to do something else ONLY when it receives that code.
This kind of question is always best served within an Arduino forum - where multiple
respondents can provide relevant info and code snippets etc, plus the flow of information is
specific to your question.
Having said that - your best bet is to have a look at tutorial 4 - which will show you how to
get the Arduino to listen for the signal. This signal will be stored within the array called
storedData[].
You can then use a function to clean up the signal using "IF" statements. eg.
if(storedData[i]<4){
storedData[i]=2;
}
You will need to do this also for values above or equal to 4.
Once you have cleaned up the code, you may only be interested in the first 10 or first 1000
values..... And would have to find a way to match these values in the storedData[] array
with the pre-defined code you speak of. I can't go through the details here - because it
would almost be a whole tutorial in itself - but please post your question on the Arduino
Forum - and feel free to come back a leave a link to your forum query in the comments.
Good Luck
Scott C
Scott C
Reply
Hi Tom,
When I started this project, I did not know if it was going to work or not. When it did work, I
did a little happy dance. Not sure if it works for anyone else.
Providing that your project is legal, I don't mind how you use my code.
I would be interested to hear how your project turns out, and would be happy with just a
reference link back to this blog somewhere in your code or Github.
Reply
Comment as:
Publish
Google Account
Preview
Newer Post
Home
Subscribe to: Post Comments (Atom)
Older Post
2.3k
One in a million
Arduino Selfie
Relay Module
Grove Water Sensor