Arduino Basics - 433 MHZ RF Module With Arduino Tutorial 3
Arduino Basics - 433 MHZ RF Module With Arduino Tutorial 3
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
20 July 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
The RF remote that I am using transmits the same signal 6 times in a row. The signal to turn the light on is
different from that used to turn the light off. In tutorial 2, we were able to "listen to" or receive the signal from
the RF remote using the RF receiver. I thought it would be possible to just play back the signal received on
the Arduino's analogPin, but the time it takes to perform a digital write is different to the time it takes to do an
AnalogRead. Therefore it won't work. You need to slow down the digitalWrite speed.
pow ered by
I would like to find out if it is possible to apply this delay to all 433 MHz signal projects, however, I only have
one 433 MHz remote.
If the delay in your project is the same as mine (or different) I would be keen to know - please leave a
comment at the end of the tutorial.
We are going to use trial and error to find the optimal digitalWrite delay time. We will do this by slowly
incrementing the delay until the transmission is successful. The transmission is considered successful if the
fan-light turns on/off. All we have to do is count the number of transmissions until it is successful, then we
should be able to calculate the delay.
Blog Archive
2014 (9)
November (1)
October (1)
September (2)
August (1)
July (2)
Parts Required
Arduino UNO or compatible board
Breadboard
Wires
RF Module (433 Mhz) - Transmitter and Receiver pair or the 315 Mhz version
Mercator Ceiling Fan/Light with Remote
433 MHz RF
module with
Arduino
Tutorial 4:
433 MHz RF
module with
Arduino
Tutorial 3
June (2)
2013 (13)
2012 (11)
2011 (25)
Total Pageviews
1,052,625
1 /*
2
Transmit sketch - RF Calibration
3
Written by ScottC 17 July 2014
4
Arduino IDE version 1.0.5
5
Website: http://arduinobasics.blogspot.com
6
Transmitter: FS1000A/XY-FST
7
Description: A simple sketch used to calibrate RF transmission.
8 ------------------------------------------------------------- */
9
10 #define rfTransmitPin 4 //RF Transmitter pin = digital pin 4
11 #define ledPin 13
//Onboard LED = digital pin 13
12
13 const int codeSize = 25;
//The size of the code to transmit
14 int codeToTransmit[codeSize]; //The array used to hold the RF code
15 int lightON[]={2,2,2,2,1,4,4,4,4,5,1,4,4,4,4,4,4,5,2,2,1,4,4,4,6}; //The RF code that will turn the light ON
16 int lightOFF[]={2,2,2,2,1,4,4,4,4,5,1,4,4,4,4,4,4,5,2,2,2,2,2,2,3}; //The RF code that will turn the light OFF
17 int codeToggler = 0; //Used to switch between turning the light ON and OFF
18 int timeDelay=5;
// The variable used to calibrate the RF signal lengths.
19
20
21
22 void setup(){
23
Serial.begin(9600);
// Turn the Serial Protocol ON
24
pinMode(rfTransmitPin, OUTPUT); //Transmit pin is an output
25
pinMode(ledPin, OUTPUT);
26
27 //LED initialisation sequence - gives us some time to get ready
28
digitalWrite(ledPin, HIGH);
29
delay(3000);
30
digitalWrite(ledPin, LOW);
31
delay(1000);
32 }
33
34
35
36
void loop(){
37
toggleCode();
// switch between light ON and light OFF
38
transmitCode(); // transmit the code to RF receiver on the Fan/Light
39
40
timeDelay+=10;
//Increment the timeDelay by 10 microseconds with every transmission
41
delay(2000);
//Each transmission will be about 2 seconds apart.
42
}
43
44
45
46
47
/*---------------------------------------------------------------48
toggleCode(): This is used to toggle the code for turning
49
the light ON and OFF
50
-----------------------------------------------------------------*/
51
void toggleCode(){
52
if(codeToggler){
53
for(int i = 0; i<codeSize; i++){
54
codeToTransmit[i]=lightON[i];
55
}
56
57
} else{
58
for(int i = 0; i<codeSize; i++){
59
codeToTransmit[i]=lightOFF[i];
60
}
61
}
62
codeToggler=!codeToggler;
63
}
64
65
66
67
68
/*----------------------------------------------------------------69
transmitCode(): Used to transmit the signal to the RF receiver on
70
the fan/light. There are 6 different HIGH-LOW signal combinations.
71
72
SH = short high or LH = long high
73
PLUS
74
SL = short low
or
LL = long low
or
VLL = very long low
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
-------------------------------------------------------------------*/
void transmitCode(){
// The LED will be turned on to create a visual signal transmission indicator.
digitalWrite(ledPin, HIGH);
//initialise the variables
int highLength = 0;
int lowLength = 0;
//The signal is transmitted 6 times in succession - this may vary with your remote.
for(int j = 0; j<6; j++){
for(int i = 0; i<codeSize; i++){
switch(codeToTransmit[i]){
case 1: // SH + SL
highLength=3;
lowLength=3;
break;
case 2: // SH + LL
highLength=3;
lowLength=7;
break;
case 3: // SH + VLL
highLength=3;
lowLength=92;
break;
case 4: // LH + SL
highLength=7;
lowLength=3;
break;
case 5: // LH + LL
highLength=7;
lowLength=7;
break;
case 6: // LH + VLL
highLength=7;
lowLength=92;
break;
}
/* Transmit a HIGH signal - the duration of transmission will be determined
by the highLength and timeDelay variables */
digitalWrite(rfTransmitPin, HIGH);
delayMicroseconds(highLength*timeDelay);
/* Transmit a LOW signal - the duration of transmission will be determined
by the lowLength and timeDelay variables */
digitalWrite(rfTransmitPin,LOW);
delayMicroseconds(lowLength*timeDelay);
}
}
//Turn the LED off after the code has been transmitted.
digitalWrite(ledPin, LOW);
}
I used an array to hold the RF code for light ON and light OFF. Each number within the code represents a
specific sequence of HIGH and LOW lengths. For example, 2 represents a SHORT HIGH and a LONG LOW
combination. A short length = 3, a long length = 7, and a very long length = 92. You need to multiply this by
the timeDelay variable to identify how much time to transmit the HIGH and LOW signals for.
The short and long lengths were identified from the experiments performed in tutorial 2 (using the RF
receiver). Each code is transmitted 6 times. The LED is turned on at the beginning of each transmission, and
then turned off at the end of the transmission. The timeDelay variable starts at 5 microseconds, and is
incremented by 10 microseconds with every transmission.
In the video, you will notice that there is some flexibility in the timeDelay value. The Mercator Fan/Light will
turn on and off when the timeDelay variable is anywhere between 75 and 135 microseconds in length. It also
seems to transmit successfully when the timeDelay variable is 175 microseconds.
So in theory, if we want to transmit a signal to the fan/light, we should be able to use any value between 75
and 135, however in future projects, I think I will use a value of 105, which is right about the middle of the
range.
Video
Now that I have the timeDelay variable, I should be able to simplify the steps required to replicate a remote
control RF signal. Maybe there is room for one more tutorial on this topic :)
+7 including Gary
Labels: 433Mhz, Arduino, ArduinoBasics, Fan, Light, Mercator, Remote, RF, Transmitter, tutorial
6 comments:
Rafael 21 July 2014 at 19:02
How far range did you get? May I suggest a tutorial 4: antennas (home made). Thanks for the
tutorials!
Reply
Replies
Scott C
Hi Rafael,
Without an antenna, I was able to turn the light on and off from the next room. But this
distance is much further than I need. I am not interested in transmitting beyond the
boundaries of my house (or that room for that matter). Thank you for the suggestion, I
would have to seek advice as to whether the use of an antenna would break any laws in
Australia... Perhaps somebody can help me out here and provide some advice. I am not
interested in breaking laws. But if I am legally allowed to, I might do a tutorial on antennas.
What about antennas do you want to know?
Reply
Reply
Comment as:
Publish
Google Account
Preview
Newer Post
Home
Older Post
2.3k
One in a million
Arduino Selfie
Relay Module
Grove Water Sensor