Anda di halaman 1dari 7

433 MHz RF module with Arduino Tutorial 4:

ADVERTENCIA: Por favor, compruebe si puede utilizar legalmente transmisores de RF y receptores en su


localidad antes de intentar este proyecto (o la compra de los componentes). Este proyecto est dirigido a
aquellos que estn buscando para automatizar su hogar.
Continuando desde mi anterior "transmisor y receptor de 433 MHz" tutoriales ( 1 , 2 y 3 ): He tirado la
necesidad de procesar la seal con un ordenador. Esto significa que ahora podemos obtener el Arduino para
grabar la seal de un control remoto RF (muy cerca), y reproducirlo en ningn momento a todos.
El Arduino olvidar la seal cuando apaga o cuando se restablece el tablero. El Arduino no tiene una extensa
memoria - hay un lmite al nmero de seales se pueden almacenar en el tablero en un momento
dado. Algunas personas han optado por crear un "cdigo" en sus proyectos para ayudar a maximizar el
nmero de seales almacenadas en el tablero. En el nombre de la simplicidad, no voy a codificar la seal
como lo hice en mis tutoriales anteriores.
Voy a tener el Arduino para grabar la seal y reproducirla - con la ayuda de un botn. El botn le ayudar a
gestionar el proceso global, y controlar el flujo de cdigo.
Aparte de la posibilidad de subir el boceto para el Arduino, este proyecto no requerir el uso de una
computadora. Tampoco se necesita una tarjeta de sonido, o cualquier bibliotecas especializadas. Aqu estn
las piezas necesarias:

Piezas necesarias:

UNO Arduino o junta compatibles

Breadboard

Botn

El rojo y el LED verde

330 ohmios (s)

Alambres

Mdulo de RF (433 Mhz) - Transmisor y receptor par o la versin de 315 Mhz

Ventilador de techo Mercator / luz con control remoto

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.
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 or the 315 Mhz version

Mercator Ceiling Fan/Light with Remote

Fritzing Sketch

Arduino Sketch

1
/*
2
3
4
5
6
7

433 MHz RF REMOTE REPLAY sketch


Written by ScottC 24 Jul 2014
Arduino IDE version 1.0.5
Website: http://arduinobasics.blogspot.com
Receiver: XY-MK-5V
Transmitter: FS1000A/XY-FST
Description: Use Arduino to receive and transmit RF Remote signal
------------------------------------------------------------- */
#define
#define
#define
#define

rfReceivePin A0
rfTransmitPin 4
button 6
ledPin 13

//RF Receiver data pin = Analog pin 0


//RF Transmitter pin = digital pin 4
//The button attached to digital pin 6
//Onboard LED = digital pin 13

8
9
10
11
12
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)

14

void setup(){
Serial.begin(9600);
//Initialise Serial communication - only required if you
15 plan to print to the Serial monitor
pinMode(rfTransmitPin, OUTPUT);
16
pinMode(ledPin, OUTPUT);
pinMode(button, INPUT);
17 }
18

void loop(){
buttonVal = digitalRead(button);

19
20
21

if(buttonState>0 && buttonVal==HIGH){


//Serial.println("Listening for Signal");
initVariables();
listenForSignal();
}

22
buttonVal = digitalRead(button);
23
24
25

if(buttonState<1 && buttonVal==HIGH){


//Serial.println("Send Signal");
sendSignal();
}

26

delay(20);
}

27
28
29
30
31
32

/* -----------------------------------------------------------------------------Initialise the array used to store the signal


-----------------------------------------------------------------------------*/
void initVariables(){
for(int i=0; i<dataSize; i++){
storedData[i]=0;
}
buttonState=0;
}

33
34
35
36
37
38
39
40

/* -----------------------------------------------------------------------------Listen for the signal from the RF remote. Blink the RED LED at the beginning t
o 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);

41
42

//Read and store the rest of the signal into the storedData array
for(int i=0; i<dataSize; i=i+2){

43

//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

44
45
46
47

//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

48
49
50

51

storedData[0]++; //Account for the first AnalogRead>threshold = lost while


listening for signal
52
digitalWrite(ledPin, LOW);
}
53
54

/*-----------------------------------------------------------------------------Send the stored signal to the FAN/LIGHT's RF receiver. A time delay is required

55 to synchronise
the digitalWrite timeframe with the 433MHz signal requirements. This has not be
56 en tested with different
frequencies.
57
-----------------------------------------------------------------------------*/
58 void sendSignal(){
digitalWrite(ledPin, HIGH);
59
for(int i=0; i<dataSize; i=i+2){
//Send HIGH signal
60
digitalWrite(rfTransmitPin, HIGH);
delayMicroseconds(storedData[i]*timeDelay);
61
//Send LOW signal
digitalWrite(rfTransmitPin, LOW);
62
delayMicroseconds(storedData[i+1]*timeDelay);
}
63
digitalWrite(ledPin, LOW);
delay(1000);
64
65

/*-----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]);
}
---------------------------------- */

66
67
68
69
70
71
72
73
74
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
10
0
10
1
10
2
10
3
10
4
10
5
10
6
10
7
10
8
10
9
11
0
11
1
11
2
11

3
11
4
11
5
11
6
11
7
11
8
11
9
12
0
12
1
12
2
12
3
12
4
12
5
12
6
12
7

Con esto concluye mi transmisor de 433 MHz y tutoriales receptor (por ahora). . Espero que les hayan
disfrutado
favor,
hgamelo
saber
si
esto
funcion
para
usted
o
no.
No he probado este proyecto con otros mandos a distancia u otras frecuencias - por lo que estara interesado
en saber si esta tcnica se puede utilizar para todos los proyectos de RF ??
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 ??

Anda mungkin juga menyukai