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.
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:
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
- Part 4: Record and play back a 433 Mhz RF remote signal - ** you are here **
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:
Parts Required:
- Arduino UNO or compatible board
- Breadboard
- Button
- Red and Green LED
- 330 ohm resistor(s)
- Wires
- RF Module (433 Mhz) - Transmitter and Receiver pair
- Mercator Ceiling Fan/Light with Remote
Fritzing Sketch
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
/* | |
433 MHz RF REMOTE REPLAY sketch | |
Written by ScottC 24 Jul 2014 | |
Arduino IDE version 1.0.5 | |
Website: http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html | |
Receiver: XY-MK-5V Transmitter: FS1000A/XY-FST | |
Description: Use Arduino to receive and transmit RF Remote signal | |
------------------------------------------------------------- */ | |
#define rfReceivePin A0 //RF Receiver data pin = Analog pin 0 | |
#define rfTransmitPin 4 //RF Transmitter pin = digital pin 4 | |
#define button 6 //The button attached to digital pin 6 | |
#define ledPin 13 //Onboard LED = digital pin 13 | |
const int dataSize = 500; //Arduino memory is limited (max=1700) | |
byte storedData[dataSize]; //Create an array to store the data | |
const unsigned int threshold = 100; //signal threshold value | |
int maxSignalLength = 255; //Set the maximum length of the signal | |
int dataCounter = 0; //Variable to measure the length of the signal | |
int buttonState = 1; //Variable to control the flow of code using button presses | |
int buttonVal = 0; //Variable to hold the state of the button | |
int timeDelay = 105; //Used to slow down the signal transmission (can be from 75 - 135) | |
void setup(){ | |
Serial.begin(9600); //Initialise Serial communication - only required if you plan to print to the Serial monitor | |
pinMode(rfTransmitPin, OUTPUT); | |
pinMode(ledPin, OUTPUT); | |
pinMode(button, INPUT); | |
} | |
void loop(){ | |
buttonVal = digitalRead(button); | |
if(buttonState>0 && buttonVal==HIGH){ | |
//Serial.println("Listening for Signal"); | |
initVariables(); | |
listenForSignal(); | |
} | |
buttonVal = digitalRead(button); | |
if(buttonState<1 && buttonVal==HIGH){ | |
//Serial.println("Send Signal"); | |
sendSignal(); | |
} | |
delay(20); | |
} | |
/* ------------------------------------------------------------------------------ | |
Initialise the array used to store the signal | |
------------------------------------------------------------------------------*/ | |
void initVariables(){ | |
for(int i=0; i<dataSize; i++){ | |
storedData[i]=0; | |
} | |
buttonState=0; | |
} | |
/* ------------------------------------------------------------------------------ | |
Listen for the signal from the RF remote. Blink the RED LED at the beginning to help visualise the process | |
And also turn RED LED on when receiving the RF signal | |
------------------------------------------------------------------------------ */ | |
void listenForSignal(){ | |
digitalWrite(ledPin, HIGH); | |
delay(1000); | |
digitalWrite(ledPin,LOW); | |
while(analogRead(rfReceivePin)<threshold){ | |
//Wait here until an RF signal is received | |
} | |
digitalWrite(ledPin, HIGH); | |
//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 HIGH signal---------------HIGH | |
dataCounter=0; //reset the counter | |
while(analogRead(rfReceivePin)>threshold && dataCounter<maxSignalLength){ | |
dataCounter++; | |
} | |
storedData[i]=dataCounter; //Store the length of the HIGH signal | |
//Identify the length of the LOW signal---------------LOW | |
dataCounter=0;//reset the counter | |
while(analogRead(rfReceivePin)<threshold && dataCounter<maxSignalLength){ | |
dataCounter++; | |
} | |
storedData[i+1]=dataCounter; //Store the length of the LOW signal | |
} | |
storedData[0]++; //Account for the first AnalogRead>threshold = lost while listening for signal | |
digitalWrite(ledPin, LOW); | |
} | |
/*------------------------------------------------------------------------------ | |
Send the stored signal to the FAN/LIGHT's RF receiver. A time delay is required to synchronise | |
the digitalWrite timeframe with the 433MHz signal requirements. This has not been tested with different | |
frequencies. | |
------------------------------------------------------------------------------ */ | |
void sendSignal(){ | |
digitalWrite(ledPin, HIGH); | |
for(int i=0; i<dataSize; i=i+2){ | |
//Send HIGH signal | |
digitalWrite(rfTransmitPin, HIGH); | |
delayMicroseconds(storedData[i]*timeDelay); | |
//Send LOW signal | |
digitalWrite(rfTransmitPin, LOW); | |
delayMicroseconds(storedData[i+1]*timeDelay); | |
} | |
digitalWrite(ledPin, LOW); | |
delay(1000); | |
/*-----View Signal in Serial Monitor | |
for(int i=0; i<dataSize; i=i+2){ | |
Serial.println("HIGH,LOW"); | |
Serial.print(storedData[i]); | |
Serial.print(","); | |
Serial.println(storedData[i+1]); | |
} | |
---------------------------------- */ | |
} |
Now let's see this project in action !
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 ??
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 :
Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
Have a look at my videos on my YouTube channel.
Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
Have a look at my videos on my YouTube channel.

Feel free to share this page with your friends in any way you see fit.
Description: 433 MHz RF module with Arduino Tutorial 4: Rating: 3.5 Reviewer: Unknown ItemReviewed: 433 MHz RF module with Arduino Tutorial 4:
0 comments:
Post a Comment