433 MHz RF module with Arduino Tutorial 1
If you are looking for a way to communicate between Arduinos, but don't have much cash at your disposal, then look no further. These These RF modules are not only affordable, but easy to use. They are much easier to set up than an !ee, plus you can use them without the need of a special shield. !efore you rush out and buy a ton of these modules, make sure that you are not breaking any radio transmission laws in your country. "o your research, and buy them only if you are allowed to use them in your area. There are a few #$%TI$&A( libraries that can be used to help you and your particular pro)ect. •
*irtual +ire at I-tation/
•
Radio0ead 1 which supercedes *irtual+ire
•
R-1witch for communication with remote controls
•
&in)ablocks 233 4tilities
I will mention at this point however, that I did &$T use any libraries in this particular tutorial. That's right. I will show how easy it is to transmit data from one arduino to another using these RF modules +IT0$4T libraries. Also if you are looking for an easy way to record the signals and play them back without a computer 1 then )ump to this tutorial.
Video
Project 1- RF Blink Firstly we need to test if the RF modules are working. o we will design a very simple transmit and receive sketch to test their functionality. +e will use the Arduino's onboard 5" to show when the transmitter is transmitting, and when the other Arduino is receiving. There will be a slight delay between the two Arduinos. 6ou can solder an antenna onto these modules, however I did not do this, I )ust kept the modules close together 718cm apart/. I also found that I was getting better accuracy when I used 3* instead of 9* to power the receiver. +hile using 9* for *-- on the receiver, I would get a lot of interference, however with 3*, I hardly got any noise. If you find you are getting unpredictable results, I would suggest you switch to 3* on the receiver and move the transmitter and receiver modules right ne:t to each other. Remember this is )ust a check... you can e:periment with an antenna or a greater distance afterwards. 0ere
are
the
parts
that
you
will
need
to
carry
out
this
Part Re!uired •
8 : Arduino 4&$ or compatible boards
•
!readboard
•
+ires
•
RF
The Tranmitter and Recei"er Fritzin# $ketch
pro)ect;
The Tranmitter The transmitter has 3 pins,
Notice the pin called "ATAD". It took me a while to figure out what ATAD stood for, when I suddenly realised that this was just a word reersed. It should !e DATA not ATAD#. Neertheless, this is the pin responsi!le for transmitting the signal. $e will make the
Arduino%s on!oard &'D illuminate when the transmitter pin is (I)(, and go off when &*$ as descri!ed in the following ta!le.
And this is the Arduino +ketch to carry out the data transmission.
Arduino ketch - Tranmitter 1 2
/* RF Blink - Transmit sketch
3
Written ! "c#tt$ 17 %&n 2014
4
'r(&in# )+ ,ersi#n 105
5
Wesite. htt.//ar(&in#asicsl#s#tc#m
6
Transmitter. F"1000'/-F"T
7
escriti#n. ' simle sketch &se( t# test RF transmissi#n
8 9
------------------------------------------------------------- */
10 11 (eine rTransmitin 4
//RF Transmitter in (iital in 4
12 (eine le(in 13
//n#ar( + (iital in 13
13 14 ,#i( setup:;
15
in<#(erTransmitin= >T>T:?
16
in<#(ele(in= >T>T:?
17 @ 18 19 ,#i( loop:; 20
#rint i4000? iA5? ii-i/3::;
21
(iitalWriterTransmitin= )C:?
//Transmit a )C sinal
22
(iitalWritele(in= )C:?
//T&rn the + #n
23
(ela!2000:?
//Wait #r 1 sec#n(
24 25
(iitalWriterTransmitin=W:?
//Transmit a W sinal
26
(iitalWritele(in= W:?
//T&rn the + #
27
(ela!i:?
28
//Dariale (ela!
@
29 @
The Recei"er
If all goes to plan, the on!oard &'D on this Arduino should light up and go off# at the
same time as the on!oard &'D on the transmitting Arduino. There is a chance that the receier may pick up stray signals from other transmitting deices using that specific freuency. +o you may need to play around with the threshold alue to eliminate the "noise". -ut don%t make it too !ig, or you will eliminate the signal in this eperiment. /ou will also notice a small delay !etween the two Arduinos.
Arduino ketch - Recei"er 1
/*
2
RF Blink - Recei,er sketch
3
Written ! "c#tt$ 17 %&n 2014
4
'r(&in# )+ ,ersi#n 105
5
Wesite. htt.//ar(&in#asicsl#s#tc#m
6
Recei,er. -
7
escriti#n. ' simle sketch &se( t# test RF transmissi#n/recei,er
8 9
------------------------------------------------------------- */
10 11 (eine rRecei,ein '0
//RF Recei,er in 'nal# in 0
12 (eine le(in 13
//n#ar( + (iital in 13
13 14 &nsine( int (ata 0?
// ,ariale &se( t# st#re recei,e( (ata
15 c#nst &nsine( int &erThresh#l( 70?
//&er thresh#l( ,al&e
16 c#nst &nsine( int l#erThresh#l( 50?
//l#er thresh#l( ,al&e
17 18 ,#i( setup:; 19
in<#(ele(in= >T>T:?
20
Serialein9600:?
21 @ 22 23 ,#i( loop:; 24
(ataanal#Rea(rRecei,ein:?
//listen #r (ata #n 'nal# in 0
i(ataA&erThresh#l(:; 25
(iitalWritele(in= W:?
//) a W sinal is recei,e(= t&rn
26 + FF 27
Serial rintln(ata:?
28
@
29 30
i(ataGl#erThresh#l(:;
31
(iitalWritele(in= )C:?
//) a )C sinal is recei,e(= t&rn
32 + H 33
Serial rintln(ata:?
34
@ @
+hen a 0I>0 signal is transmitted to the other Arduino. It will produce an AnalogRead ? @. +hen a $+ signal is transmitted, it will produce an AnalogRead ? 2@@. This may vary depending on on your module, and voltage used. The signals received can be viewed using the erial