Introduction: 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 <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="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 <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]=='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();

Comments

author
michelkeijzers made it!(author)2017-07-19

Thanks for this instruction. I got it working in like 15 mins. However, when using a 12V adapter for the transmitter (just USB for receiver) I get missing messages at about half meter at 4000 bps, with 200 bps, it is after one meter. Is this normal?

author
Mohannad+Rawashdeh made it!(author)2017-07-19

happy to hear that ! hope this instruction was useful to you
no it's not normal , try to use usb source for both Tx and Rx and check the message , if you missing any packet so this might not be a power supply issue.
I used it with 9V battery (for Tx and Rx) and I didn't get anything like that
please try it and update it here , thanks

author
ShanmukhaG made it!(author)2017-07-06

I used these connections and the code also but I'm unable to see the data can anyone help me with this issue

author
Mohannad+Rawashdeh made it!(author)2017-07-07

check your wires again , if not working, please follow this instructables

https://www.instructables.com/id/RF-315MHz433MHz-Wireless-and-Arduinoagain/

author
edko2005 made it!(author)2017-05-21

it's good

author
ericdaigh made it!(author)2017-05-17

Hello and thanks for this helpful tutorial. I'm wondering if these units can be used without a micro controller. I assumed they could when purchasing, but am running into trouble getting them to work. Is this possible? A standalone use, where we turn on an LED or other switch? Any help appreciated.

author
ocean750 made it!(author)2017-05-15

Hello Mohannad.

Thank you for writing down this guide. It is most helpful!

I would like to have your help with a project I am trying to build.

I have a blinker toy that works on remote control,

This is an image of the toy with the receiver unit on top of it.

http://tinypic.com/view.php?pic=50l6dy&s=9#.WRqYfZKGO70

What I would like to do is first to use the Arduinoto catch the
data stream from the receiver on the toy when I use the remote control.

The second stage will be to remove the receiver from the toy and use the
Arduinoto send the commands directly to the toy.

Is that possible ?

Can you help me with this ?

Thank you,

Angel

author
Mohannad+Rawashdeh made it!(author)2017-05-16

For the first stage , yes you can do it and all you need to do is check the receiver frequency and the data rate (speed) in Bit per second , you need to follow (try and error ) method until you can receive the RF message
for the second stage , you want to remove the RF Rx and replace it with arduino , well if you can finish stage 1 ,this one will be much easier.

author
ocean750 made it!(author)2017-05-16

Thank you for replying.

I would like to be able to view the data stream on my screen so that i could later copy it and send it.

can you help me with the code ?

author
eriff1 made it!(author)2017-03-15

hi. nice Instructable, i have a question, can i use one reciver and many transmiter, to make a proximity alert mesh. need to improve safety in mining labor to avoid cars and trucks hit people inside a mine tunnel

author
Mohannad+Rawashdeh made it!(author)2017-03-15

yes you can , with this module it's easy to do that.

author
HumzaL made it!(author)2017-04-29

Hey Mohannad, firstly thank you so much for all the work you've done here, it's been very helpful and with your permission I'd like to use it in my dissertation for my final year at university.

Secondly, in response to eriff1's comment, I was wondering if you could spend a few minutes giving some details as to how one would go about having several transmitters and several receivers, each transmitter transmitting to all nearby receivers.

I have done research into multiplexing but to be honest; I think I'm barking up the wrong tree. Google yields no answers for me :(

Many thanks!

Humza

author
Mohannad+Rawashdeh made it!(author)2017-04-30

Hey Humzal , thank you for your comment
because this type of of RF we don't have an address system which allow to us to setup a network or do a simple (one Transmitter and multi receiver system) here some tips to how to do a multi tx and multi Rx network
"this method is an experimental one , and from my own experience only)

1- if you want to build a single Tx and Multi receiver you need to set the speed from ( vw_setup(uint16_t speed)) to be similar for each other devices
** send a message contains at least 2 bytes ( for example X1 ) the receiver must be programmed to read the first char as a Target device , so if the receiver name is X that's mean this message to this receiver , otherwise ignore it ( do this using if statement and read the char name[0] to do the comparison )
i worked something similar before and it works
2- for multi Tx and Rx system do the same , but increase the number of char you must send so you can know from where this message came from , the target receiver , and the data , for Example
XL1 >>> The transmitter ID will be the first char " here X" and the receiver "L" and the data "1" , you need to program each tx and rx to what transmit and what to receive "a little bit complicated "
finally remember this type of RF used only to send signal , not data , so looking for other RF with network feature would be better "like nRF24 , CC110X"

author
sdcharle made it!(author)2017-04-01

Sadly the VirtualWire Link is broken now.

Try this, I got it from here and it worked: https://www.pjrc.com/teensy/td_libs_VirtualWire.ht...

author
Mohannad+Rawashdeh made it!(author)2017-04-18

exactly , and you can check my new article for the same rf using radio head library

https://www.instructables.com/id/RF-315MHz433MHz-W...

author
jays248 made it!(author)2017-04-16

is there a way to wire this with 9v battery?

author
Mohannad+Rawashdeh made it!(author)2017-04-18

actually yes , this module works from 3.5V - 12 V

author
chengchow made it!(author)2017-04-05

Hi, can i use this module to control my servo motor by potentiometer?

author
Mohannad+Rawashdeh made it!(author)2017-04-05

well theoretically you can, this module designed to send a signal not a data , you need to work a little bit on the code side to change the servo angle to character string and then send it .

author
chengchow made it!(author)2017-04-06

May I know how to change the servo angle to character string? Got any example code about this?

author
SaurabhB31 made it!(author)2017-03-21

Hey nice. I want to ask you can I use this module to control my quadcopter?

author
Mohannad+Rawashdeh made it!(author)2017-03-22

i think it's not an ideal for quadcopters , the RF range less than 40m.

but as an idea yes you can but you need to work on the RF packet you want to send and receive

author
sailorjohn34 made it!(author)2017-03-03

I am getting an error saying that vw_set..... was not declared... I know the library is available as it showing in the IDE examples as well as libraries... I'm baffled.

People are asking about longer range... The RF24 is a good transceiver for long range. They carry quite a few channels and have been proven to like 10Km..

author
Mohannad+Rawashdeh made it!(author)2017-03-04

what is your arduino version ? in the newer Arduino IDE this library is not working well .
please check my newer article about this RF using radio head library

https://www.instructables.com/id/RF-315MHz433MHz-W...

for nrf yes it's way better than this module ,but 10Km is not availabe in this module, the communication regulation in most of the country the nRF power<60mW and as a range about 2KM .

author
sailorjohn34 made it!(author)2017-03-11

Thank you for your reply. I will try an older version of the IDE and see how that goes. I am also checking out your other instructable. Thank you for posting this though. If it weren't for instructables and other people I would be lost with the arduino. I appreciate the time you've taken to help others out.

author
spaansebrabander made it!(author)2017-01-31

What do you mean with "serial"

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

author
Mohannad+Rawashdeh made it!(author)2017-02-14

I update a new artical with serial monitor code ,you can send your your command from serial port
https://www.instructables.com/id/RF-315MHz433MHz-Wireless-and-Arduinoagain/

author
Mohannad+Rawashdeh made it!(author)2017-01-31

sorry i edited this code later , before i wrote it to receive a data from serial (hardware serial pins "computer") so you can build more advance application
thanks for your question i will edit it soon

author
0xffff made it!(author)2016-08-03

You shall use RadioHead, the library that supersedes & replaces the obsolete Virtual Wire.

Same functionalities plus a lot more:

- takes all the advantage of all available radio modules (not only ASK, incl. bi-directional transceivers as well, different coding/modulation...)

- includes client-server, security....

- able to work on TIMER2, if you need TIMER1 for something else...

http://www.airspayce.com/mikem/arduino/RadioHead/classRH__ASK.html

author
Mohannad+Rawashdeh made it!(author)2017-02-14

Here my new artical for the same module with Radiohead library

https://www.instructables.com/id/RF-315MHz433MHz-Wireless-and-Arduinoagain/

author
leotimmermans made it!(author)2016-08-04

Hey, Its works well with Radiohead. But when I try to power my transmitter with 9V battery (see if Tx goes further) but leave datapin in 12, I have no transmission anymore ?????? Anybody knows why ??

author
0xffff made it!(author)2016-08-04

Not sure I get your point.

Do you mean it works with 5V, but not anymore when you power the transmitter with 9V?

One important thing here is to make sure both power sources have the same (GND) reference, e.g. both grounds are connected.

If they are not connected, both circuits are "floating", it means there is no reference for the DATA pin on the transmitter

In basic words, when there is a 0v/5v signal on arduino pin 12, it's 0v/5v relative to arduino ground. If arduino ground and transmitter ground are not connected, there is no way for the transmitter to guess the reference, hence to read the data coming from arduino.

See second schematics bellow.

arduino_433_9v.jpg
author
rupam222 made it!(author)2017-02-10

sir,can u plz tell me why we need virtual wire library without it why we r not able to do work

author
Mohannad+Rawashdeh made it!(author)2017-02-12

alright, now this module use Manchester code on the output and each packet of data contains many bits and need to synchronize a clock to read the packet.
https://en.wikipedia.org/wiki/Manchester_code

you need the library to decode this packet and make it easier for you to read.

now you wondering why there are many RFs with direct 0/1 output like this one
https://www.seeedstudio.com/2KM-Long-Range--RF-lin...
because it comes with decoder built in, so it gives you 0 / 1 on the output pin.
hope this answer is useful for you

author
0xffff made it!(author)2017-02-11

Sorry, I didn't get you question. Can you explain your problem more clearly?

author
leotimmermans made it!(author)2016-08-05

Hey Thanks, indeed a common ground solves it ! Thank you very much for your reply !

Tkx, Leo

author
a1m918 made it!(author)2016-09-01

can you make this library work with Attiny13 ?

author
Mohannad+Rawashdeh made it!(author)2017-02-12

absolutely no

author
FilipM44 made it!(author)2017-02-05

I have some question,how we can control more transmitters with one or more recivers at the same time?
For example we have 3 transmiters and 3 recivers and we send signal only at one transmitter,will it all 3 recivers recive that signal and send them to outputs?
So I need something to do like shift register to control more outputs,can I do with this module?

author
Mohannad+Rawashdeh made it!(author)2017-02-06

first you need to set all the transmitter and receiver with the same bit per second
using this command


vw_setup(uint16_t speed);

second,you need to write your code and just change the character you want to send from the transmitter.

this module can't work alone without mcu so you need, no shift register required in this case , and you can set each receiver to read a specific data "by change the if statement in your code".

author
eenander made it!(author)2017-02-06

Send your first bit a '#1' for receiver one, #2 for receiver two and #3 for receiver three, Each receiver receive all data, you have to write a program that starts listing after #1 for receiver 1 #2 for receiver 2 and...... Yes. You can use your one opening ~1 instead of #1. So you can write a program for receiver one that starts listing after #1 until ~1. ~1 is then end of data for receiver 1.

author
JakovV made it!(author)2017-02-01

why do i need two arduinos?

author
eenander made it!(author)2017-02-03

If you want to communicate between a transmitter (one Arduino) and receiver (second Arduino) then you need 2 Arduino's. If you only want to send ore receive data you only need one Arduino. ;-) Or Raspberry

author
JakovV made it!(author)2017-02-03

Thank you

author
MaAnnQ made it!(author)2017-01-14

Hi. I am using 315mhz transceiver without antenna and nothing happen. It should at least transmit data even without antenna. I've used two uno. The transmitter is powered with 9v battery. What could be the problem?

author
j_instuct made it!(author)2017-01-23

I've a newbie at these devices and in the process of checking up on them, I've come across the comment that running a transmitter without an antenna can be bad for the transmitter. Sounds like its possible it worked poorly at first and some point after it may have died. Hope not. Good luck.

author
Mohannad+Rawashdeh made it!(author)2017-01-31

antenna for this module will not improve the range so much and some time cause damage for the module "it's weird the antenna must be straight and any bent in the antenna cause a problem for the data"
without antenna it works fine and for along time and you can fund the same module on many remote control .

thanks

author
chartog made it!(author)2017-01-26

Have you connected the ground of the battery with the ground of the arduino?

author
Mohannad+Rawashdeh made it!(author)2017-01-31

yes

author
Mohannad+Rawashdeh made it!(author)2017-01-31

maybe from the connection , or the module you use is not working

About This Instructable

1,059,208views

736favorites

License:

Bio: Maker, PCB designer , electronics instructor from Jordan just one word ! I Adore electronics follow me on FB https://www.facebook.com/Mohannad-Rawashdeh-Raw-774983565988641/
More by Mohannad Rawashdeh:Convert Your Pringles Cans to RTTTL Audio PlayerTTP224 Digital Touch Sensor Applications Using ArduinoRF 315MHz/433MHz Wireless and Arduino...again!
Add instructable to: