RF 315/433 MHz Transmitter-receiver Module and Arduino
by Mohannad Rawashdeh in Circuits > Arduino
1356534 Views, 845 Favorites, 0 Comments
RF 315/433 MHz Transmitter-receiver Module and Arduino
Materials:
at first let's take a look for what we need :
1) 2 Arduino Board "I used Uno"
2) RF 315MHz or 433MHz transmitter-receiver module .
3) jumper wire .
4) BreadBoard .
5)External Power supply (9V Battery *2) "Optional" .
Module Specification
Transmitter :
Working voltage: 3V - 12V fo max. power use 12V
Working current: max Less than 40mA max , and min 9mA
Resonance mode: (SAW)
Modulation mode: ASK
Working frequency: Eve 315MHz Or 433MHz
Transmission power: 25mW (315MHz at 12V)
Frequency error: +150kHz (max)
Velocity : less than 10Kbps
So this module will transmit up to 90m in open area .
Receiver :
Working voltage: 5.0VDC +0.5V
Working current:≤5.5mA max
Working method: OOK/ASK
Working frequency: 315MHz-433.92MHz
Bandwidth: 2MHz
Sensitivity: excel –100dBm (50Ω)
Transmitting velocity: <9.6Kbps (at 315MHz and -95dBm)
the use of an optional antenna will increase the effectiveness of your wireless communication. A simple wire will do the trick.
Schematics
for Transmitter :
Vcc >>>>5V
ATAD>>>D12"You can change it as you like from Software" .
Gnd >>> Gnd
Receiver :
Vcc>>>>5V
Data>>>D12
Gnd>>>Gnd
Arduino Virtual Wire Library
Fortunately , There is a popular Library for arduino Called "" VirtualWire"" Created by Mike McCauley
VirtualWire is an Arduino library that provides features to send short messages, without addressing, retransmit or acknowledgment, a bit like UDP over wireless, using ASK (amplitude shift keying). Supports a number of inexpensive radio transmitters and receivers.
This library allow You to send and receive data"byte" and string easily ,
First Download the library from Here .
after extract the folder, and move it to " Libraries " on the arduino Folder
this is a simple code , it will send character '1' and after 2 sec will send character '0' and so on .
this code for transmitter :
//simple Tx on pin D12
//Written By : Mohannad Rawashdeh
// 3:00pm , 13/6/2013
//http://www.genotronex.com/
//..................................
#include
char *controller;
void setup() {
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(2000);
controller="0" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,0);
delay(2000);
}
and this is code for receiver :
The D13 LED On the arduino board must be turned ON when received character '1' and Turned Off when received character '0'
//simple Tx on pin D12
//Written By : Mohannad Rawashdeh
// 3:00pm , 13/6/2013
//http://www.genotronex.com/
//..................................
#include
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='1'){
digitalWrite(13,1);
}
if(buf[0]=='0'){
digitalWrite(13,0);
}
}
}
One Transmitter, Multi Receiver
For more secret you may need Encoder-Decoder .
Encoder is a circuit that changes a set of signals into a code .
Decoder is a circuit that changes a code into a set of signals .
if You need an Encoder/Decoder IC , You can use PT2262 and PT2272
this is a simple example , for 1 master Transmitter , 2 ReceiverS , and send a command through Serial for a receiver To Turn LED On/Off .
Tx code :
//simple Tx on pin D12
//Written By : Mohannad Rawashdeh
// 3:00pm , 13/6/2013
//http://www.genotronex.com/
//..................................
#include <VirtualWire.h>
char *controller;
void setup() {
pinMode(13,OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
controller="A1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(1000);
digitalWrite(13,0);
delay(1000);
controller="B1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13,1);
delay(1000);
digitalWrite(13,0);
delay(1000);
}
First Rx
//simple Tx on pin D12
//Written By : Mohannad Rawashdeh
// 3:00pm , 13/6/2013
//http://www.genotronex.com/
//..................................
#include <VirtualWire.h>
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if((buf[0]=='A')&&(buf[1]=='1')){
digitalWrite(13,1);
delay(1000);
}
}
else{
digitalWrite(13,0);
}
}
Second Rx
//simple Tx on pin D12
//Written By : Mohannad Rawashdeh
// 3:00pm , 13/6/2013
//http://www.genotronex.com/
//..................................
#include <VirtualWire.h>
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if((buf[0]=='B')&&(buf[1]=='1')){
digitalWrite(13,1);
delay(1000);
}
}
else{
digitalWrite(13,0);
}
}
Virtual Wire ..... Inside
Messages are sent with a training preamble, message length and checksum. Messages are sent with 4-to-6 bit encoding for good DC balance, and a CRC checksum for message integrity.
Can we use Serial communication with ? answer is No
ASK receivers require a burst of training pulses to synchronize the transmitter and receiver, and also requires good balance between 0s and 1s in the message stream in order to maintain the DC balance of the message, UARTs do not provide these. They work a bit with ASK wireless, but not as well as this code.
The full function for this library :
To use the VirtualWire library, you must have
#include <VirtualWire.h>
To select the Transmitter Data Pin , void :
vw_set_tx_pin
To select the Receiver Data Pin , void :
vw_set_rx_pin
Setup the speed of transmission , The speed of Tx must be as same as On Rx .
the speed will be a Number of Bit Per Second between 0-9600 , for short distance you can use fast speed , For long distance "Up to 90m" you must use lower transmission speed as much as possible .
vw_setup(uint16_t speed);
Start the receiver PLL running ,You must do this before you can receive any messages,Call
vw_rx_start();
You must do this before you can receive any messages. When a messageis available (good checksum or not), vw_have_message() will return true.
vw_rx_stop();
Block and wait until the transmitter is idle,called :
vw_wait_tx();
Block and wait until a message is available from the receiver, call :
vw_wait_rx();
Send a message with the given length, call :
vw_send(uint8_t* buf, uint8_t len);
Returns true if an unread message is available from the receiver.,call :
vw_have_message();