RF 315/433 MHz Transmitter-receiver Module and Arduino

1.4M843362

Intro: RF 315/433 MHz Transmitter-receiver Module and Arduino

Hi every body , I searched on Instructables about a simple RF Transmitter-receiver module , Which is used in Remote control for cars , or to control simple tasks , like control relay on/off unfortunately I didn't find What I need   , So i decided to write a simple artical about this transceiver and How we can connect it with arduino  and program it .

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" .

STEP 1: Module Specification

This module has a specification for :

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.

STEP 2: Schematics

the connection for this module is very easy .

for Transmitter :

Vcc >>>>5V
ATAD>>>D12"You can change it as you like from Software" .
Gnd >>> Gnd

Receiver :

Vcc>>>>5V
Data>>>D12
Gnd>>>Gnd

STEP 3: 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);
}

}
}


STEP 4: One Transmitter, Multi Receiver

You can connect many Receiver and send a Data from One Master Transmitter .

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);
    }

}

STEP 5: Virtual Wire ..... Inside

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.

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();

324 Comments

Is it possible to use this transceiver without Arduino or microcontroller if we need only one signal say on or off and act accordingly ? Say when my door is opened I need that signal to ring bell ?
My car has the tpms system to monitor tire pressure. It transmits on 443MHz. Can I use this module to pick up those signals to display the tire pressure?
RTL_433 on github, download and install

I might be wrong, but such device might use a encoder/decoder to transmit, therefore even though you manage to catch the transmission you might not be able to read it properly without the right decoder. But try along! :)

I am currently building an RC with Arduino. I am using your code for the RF portion, but I need to be able to send other values other than 0 and 1. How do I do that?

Hi can you help me with detail instruction for connecting LEDs

LED has 2 pin (Anode & Cathode) , connect the anode pin to arduino digital pin (Pin D5 for example) and the cathode to a resistor (330 Ohm) and the other pin of the resistor to Gnd , simple isn't it ?

please explain more ! I don't understand what do you want !?

hello i need to make 2 tx / 1rx what i need to change ??

actually nothing ! just upload the tx code to both tx circuit and change the character you want to send from each tx , so at least the rx will know from which tx the message came from.

i have a project of electromagnetic field meter, when you are an experiance for this project please help me

Great Instructable, Mohannad! You mentioned lowering the baud rate for longer distances. How low do you mean ( 1? or 500? ) for can it go. Does the lower rate mean a more reliable transmission? Also what I have read is that the receiver and transmitter antennas need to be a certain length for the 433mhz, is that correct or if it is longer does to transmit further? One last question can you coil, the antenna mostly so my cats don't chew on it or does that lower the effectiveness of the antenna.

hello, do I need to put antenna to my transmitter and receiver, because my receivers seems to not receive anything or maybe because it doesn't have an antenna, but I already tried all the example codes for receiver nothing works

this is the receiver that I'm using

thanks

One question, the LED connected to the receiver data pin was always on when nothing was connected to the transmitter data pin. I tried to feed 5V to the data pin of the transmitter and the LED stopped glowing, Is this how it's supposed to work? (HIGH on transmitter data pin gives LOW on receiver data pin and vice versa).
One question, the LED connected to the receiver data pin was always on when nothing was connected to the transmitter data pin. I tried to feed 5V to the data pin of the transmitter and the LED stopped glowing, Is this how it's supposed to work? (HIGH on transmitter data pin gives LOW on receiver data pin and vice versa).

Thanks, I appreciate that. But can I use HT12E and HT12D as encoder and decoder instead of PT2262 and PT2272 ?

More Comments