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 - ** you are here **
- Part 4: Record and play back a 433 Mhz RF remote signal
Project 3: RF Remote Control Emulation
In the first tutorial, I introduced the 433 MHz Transmitter and Receiver with a simple sketch to test their functionality. In the second tutorial, the 433MHz receiver was used to receive a signal from an RF remote. The RF remote signal was coded based on the pattern and length of its HIGH and LOW signals. The signals received by the remote can be described by the code below:
Code comparison table
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.
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.
Code comparison table
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.
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.
Parts Required
- Arduino UNO or compatible board
- Breadboard
- Wires
- RF Module (433 Mhz) - Transmitter and Receiver pair
- Mercator Ceiling Fan/Light with Remote
The Transmitter Fritzing Sketch
RF Calibration - Arduino Sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Transmit sketch - RF Calibration | |
Written by ScottC 17 July 2014 | |
Arduino IDE version 1.0.5 | |
Website: http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html | |
Transmitter: FS1000A/XY-FST | |
Description: A simple sketch used to calibrate RF transmission. | |
------------------------------------------------------------- */ | |
#define rfTransmitPin 4 //RF Transmitter pin = digital pin 4 | |
#define ledPin 13 //Onboard LED = digital pin 13 | |
const int codeSize = 25; //The size of the code to transmit | |
int codeToTransmit[codeSize]; //The array used to hold the RF code | |
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 | |
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 | |
int codeToggler = 0; //Used to switch between turning the light ON and OFF | |
int timeDelay=5; // The variable used to calibrate the RF signal lengths. | |
void setup(){ | |
Serial.begin(9600); // Turn the Serial Protocol ON | |
pinMode(rfTransmitPin, OUTPUT); //Transmit pin is an output | |
pinMode(ledPin, OUTPUT); | |
//LED initialisation sequence - gives us some time to get ready | |
digitalWrite(ledPin, HIGH); | |
delay(3000); | |
digitalWrite(ledPin, LOW); | |
delay(1000); | |
} | |
void loop(){ | |
toggleCode(); // switch between light ON and light OFF | |
transmitCode(); // transmit the code to RF receiver on the Fan/Light | |
timeDelay+=10; //Increment the timeDelay by 10 microseconds with every transmission | |
delay(2000); //Each transmission will be about 2 seconds apart. | |
} | |
/*---------------------------------------------------------------- | |
toggleCode(): This is used to toggle the code for turning | |
the light ON and OFF | |
-----------------------------------------------------------------*/ | |
void toggleCode(){ | |
if(codeToggler){ | |
for(int i = 0; i<codeSize; i++){ | |
codeToTransmit[i]=lightON[i]; | |
} | |
} else{ | |
for(int i = 0; i<codeSize; i++){ | |
codeToTransmit[i]=lightOFF[i]; | |
} | |
} | |
codeToggler=!codeToggler; | |
} | |
/*----------------------------------------------------------------- | |
transmitCode(): Used to transmit the signal to the RF receiver on | |
the fan/light. There are 6 different HIGH-LOW signal combinations. | |
SH = short high or LH = long high | |
PLUS | |
SL = short low or LL = long low or VLL = very long low | |
-------------------------------------------------------------------*/ | |
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.

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 :)
Update: Here it is - tutorial 4
Where you can record and playback an RF signal (without using your computer).
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 :)
Update: Here it is - tutorial 4
Where you can record and playback an RF signal (without using your computer).

Description: 433 MHz RF module with Arduino Tutorial 3 Rating: 3.5 Reviewer: Unknown ItemReviewed: 433 MHz RF module with Arduino Tutorial 3
0 comments:
Post a Comment