RF 315MHz/433MHz Wireless and Arduino...again!
by Mohannad Rawashdeh in Circuits > Arduino
24496 Views, 82 Favorites, 0 Comments
RF 315MHz/433MHz Wireless and Arduino...again!
Hello everyone ! in this artical i will try to update my older artical about RF ASK 315MHz and 433MHz ,with more application and update the library i used before
First it might be good to check my older artical about RF433/315MHZ from here
with many feedback arrived me about it, i decided to fix many issue like:
- Using Radio head Library , more better and a comprehensive library .
- Using a module from Seeedstudio comes with antenna to see if it will increase the range of Tx and Rx.
- add more codes and video for this RF.
let's start with component we need
Components and Software
- Arduino Board x 2 pcs "You can choose any 2 board type you want
I used Uno and Nano to do this experiment. - RF315/433 module, You can buy it from
Seeedstudio I used This one
Aliexpress
amazon - Breadboard
- Jumper wire
- if you choosed seeedstudio grove module, you need this type of wires with them too
- Power source"you can use power bank or 9V battery or even your PC usb port , it's up to you
You need to have an arduino IDE , you can download it from here.
I tested it on arduino 1.5.2 , 1.5.5 and newer 1.6.9 and worked well on them all.
you need also to download Radio head library and install it inside arduino library folder
Simple Code- Blink Rx Led
first i will write a simple code, sending from RF Tx a signal each 2 second to turn on-off led attached to D13
connection is very simple , you can see the Tx and Rx connection.
I powered my circuits from power bank to test the maximum range of this module.
The transmitter code
<p>/*<br>RF433 MHz Tx code this code for turn on and LED on receiver side every 2 seconds connect the Data pin to pin 12 written By: Mohannad Rawashdeh 13 Feb 2017 visit my instructables profile for more information <a href="https://www.instructables.com/member/Mohannad%20Rawashdeh/?publicView=true</p"> https://www.instructables.com/member/Mohannad%20R...</a>><p>*/ #include <rh_ask.h> #include <spi.h> // Not actually used but needed to compile RH_ASK Rawashdeh; const int LEDpin=13;// indicator pin const int delayTime = 2000; const char *On_command = "1"; const char *Off_command = "0"; void setup() { pinMode(LEDpin,OUTPUT); while (!Rawashdeh.init()) { // no RF connected ! or error on initi digitalWrite(LEDpin,1); delay(100); digitalWrite(LEDpin,0); delay(100); } }</spi.h></rh_ask.h></p><p>void loop() { Rawashdeh.send((uint8_t *)On_command, strlen(On_command)); Rawashdeh.waitPacketSent(); delay(delayTime); Rawashdeh.send((uint8_t *)Off_command, strlen(Off_command)); Rawashdeh.waitPacketSent(); delay(delayTime); }</p>
the receiver code
<p>/*<br>RF433 MHz Rx code this code for turn on and LED on receiver side every 2 seconds connect the Data pin to pin 11 written By: Mohannad Rawashdeh 13 Feb 2017 visit my instructables profile for more information <a href="https://www.instructables.com/member/Mohannad%20Rawashdeh/?publicView=true</p"> https://www.instructables.com/member/Mohannad%20R...</a>><p>*/ #include <rh_ask.h> #include <spi.h> // Not actually used but needed to compile RH_ASK Rawashdeh; const int LEDpin=13;// indicator pin const int delayTime = 2000; const char *On_command = "1"; const char *Off_command = "0"; void setup() { // RH_ASK(2000,11,12,10,false); pinMode(LEDpin,OUTPUT); if (!Rawashdeh.init()) { // no RF connected ! or error on initi digitalWrite(LEDpin,1); delay(100); digitalWrite(LEDpin,0); delay(100); } }</spi.h></rh_ask.h></p><p>void loop() { uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; uint8_t buflen = sizeof(buf);</p><p> if (Rawashdeh.recv(buf, &buflen)) // Non-blocking { if(buf[0]=='1') { digitalWrite(LEDpin,1); } if(buf[0]=='0') { digitalWrite(LEDpin,0); } } }</p>
Add Button on Transmitter Side to Gain More Control
if you want to send the signal to receiver and control when the led must turn on, we can add button to transmitter circuit and connect it to pin D2
Rather than using LED you can connect Relay , Servo motor , DC motor and control it from transmitter side.
Downloads
Send a Command From Serial Monitor
If you looking for upgrade the way you want to control RF module by,you can send a command from serial monitor.
no need to change the receiver code , all you need is to upload this code to transmitter arduino board and open a serial monitor
set the buad rate to 19200
Send X character to turn on the LED on the receiver
Send Y character to turn on the LED on the receiver
You can design an application on PC or MAC with interface to control this module for more advance project.
Finally:
I powered my circuits from power bank to test the maximum range of this module.
actually it was not that much of improvement as i expected,even with antenna the range in open area was around 44 meter , and inside my home it was about 20m max.
I noticed something from my experience :
- the range will be less if you put the Tx and Rx near WiFi router.
- the range will be less if you put the Tx and Rx near electricity transmission line "High voltage".
- if you touch the antenna the data might be lost
-
the range will be less if you put the Tx and Rx near Microwave oven.
-
the Transmitter will be more better if you install it on higher level "altitude"than the receiver
hope to hear your questions and suggestions about this artical in the comment below or on my facebook page from here
Downloads
Video to Summarize Everything
in this video you can see the connection and short demo for the code.
see the video from Here