Let's Make Robots!

Arduino RF Communication using RX & TX link Modules

Gareth's picture
RF communication link between two Arduinos
  • Control method:

This Tip/Walk-Through will guide you through a simple one way communication link between two Arduinos.

The Project uses these RX/TX Radio Frequency (RF) Link Modules.

Edit :- Links updated - old ones where retired .Boooooo

(Thanks to Fritsl for bringing these cool babies to my attention ,i just had to try them out on my arduino and i am well impressed with thier performance )

Both Transmitter and Receiver together cost less than two tin cans with a piece of long string connected between !!!!!!!

You will have to download the Virtualwire.h library and install it to your arduinos  hardware/libraries folder

More info on the Virtualwire communications library can be found http://www.open.com.au as pdf file


Receiver :- Basic link Arduino Mega using a  RF Link Receiver - 315Mhz


Only Four wires are required, i have used a audio cable from a cd drive which i rewired to accept the cables (neat).

Yellow is the Antenna - approx 30cm long (other end connected to thin air)

Red is connected to 5 Volts

White is the Received data (in my case connected to pin 23 on the mega - can be easily assigned to another pin)

Black is Ground (it has three separate ground pins all connected together!!!!!!)


 // Receiver Code     (as the code is very short i post direct here, its adapted from Mike McCauleys pdf file above)


// RF Link using VirtualWire to receive messages
// simplex (one-way) receiver with a 315MHz RF Link Receiver module
// rx pin 23 on mega


#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
    Serial.begin(9600);    

// Initialise the IO and ISR
    vw_set_ptt_inverted(true);    // Required for RX Link Module
    vw_setup(2000);                   // Bits per sec
    vw_set_rx_pin(23);           // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
    vw_rx_start();                      // Start the receiver
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
    int i;
     // Message with a good checksum received.
        
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf[i]);  // the received data is stored in buffer
        }
    Serial.println("");
     }
}


 

 

 


 Transmitter :- Basic link using an  Arduino Duemilanova and a  RF Link Transmitter - 315Mhz


 

This also has 4 wires and the same trick with the cd audio socket to make neat connection.

Black connected to Ground

White is the transmit data cable connected to pin 3 on the Arduino (however this is easy to re-assign to suit your needs)

Red is the power supply connected to 5 Volt pin on Arduino (actually you can apply anywhere between 2 Volts and 12 Volts - the higher the voltage the stronger the RF signal)

Grey (sticking out of the Top is the Antenna - around 30cm long


// Transmitter Code


 

// RF Link using VirtualWire to Transmit messages
// simplex (one-way) receiver with a 315MHz RF Link Transmitter module
// tx pin 3 on Duemilanova (arduino)

 
#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
     // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(2000);                 // Bits per sec
    vw_set_tx_pin(3);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs.
}

void loop()
{
    const char *msg = "LMR-II Rocks";       // this is your message to send

   vw_send((uint8_t *)msg, strlen(msg));
   vw_wait_tx();                                          // Wait for message to finish
   delay(200);
}


 


Power them both up and switch on the Serial monitor to 2400 Baud on the receiving Arduino (mega in our case)

 

Then Hey Presto Communication link established......... up to 152.4 Meters (thats 500 feet in old currency)

I tested (Tx at 5 Volts) from my Basement to roof (5 stories) no problem ( Mega impressed)

Ending Side Mystery :- Why did i use pin 23 as the Rx pin on the Arduino Mega ?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
NilsB's picture

Here another 315Mhz RF Link I use in my project:

http://letsmakerobots.com/node/30694?s=l

Hello,

 I am transmitting on pin 12 on one of my UNOs which is powered by a nine volt battery.

I'm receiving on pin 11 on the other UNO which is connected to my laptop.

The baud rate is set at 2000 in the program and the serial monitor is set at 2400 however I get the following characters on the serial monitor, "ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ".

The only thing i changed from the posted code above is "vw_set_rx_pin(11);" for the receiver and "vw_set_tx_pin(12);" for the transmitter.

Do have an idea about what my problem might be ?

Gareth's picture

From the above code your serial monitor would need to be set to 9600 Baud (check this first)

Only then Try setting the program Baud rate to 2400 as well.....

Out of curiosity what are you sending on the TX side to get "ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ$ÿ" on the rx side.....

Some-times depending on the RX/TX modules you use, the data signal has to be inversed (or not)....

(code line ............... vw_set_ptt_inverted(true);    // Required for RX Link Module)

... let me know what happens..

Hi,
I used this code, and it is fully working, but I have a doubt: is it possible to send a message that we write in the serial monitor? And if is it possible, can you say me how?

Thank's

so could ya answer my probs?

and one more thing i tested out the code given by sparkfun and it totally worked i dont seemed to know wat is wrong with urs it worked for u but not me 

another mystery!!!

hey the problem is that i have an uno and an atmega328 chip with the bootloader (not uno's) so i wanna communicat the chip with the uno see the problem is that...

when the arduino ide18 was created the uno was not invented so in the board section u wont see it !!

but then i downloaded the latest ide (22) and checked and the code worked!!!for both uno and the chip !!!!

and does this receiver receieve digital data or serial data???

wen i bought it they said it worked for digital data and mine is three pin receiver and transmiiter!!but there is no deference between urs and mine coz the fourth pin on urs is the antenna and ,mine has an antenna build on to it!!

but mine is NOT receiving any data !!!could ya help me i dont know if its the problem of the arduino or the receiver!!

mine is 21 IDE and i just copied the same code u pasted above and it showed

:

vw_set_ptt_inverted(true); // Required for RF Link module

as an error and few other errors!!!!!!!!!!!

Gareth's picture

Looks like you have cracked it........ in the comments below (somewhere)....

hey i got an error while i compiled right here

:

    vw_set_ptt_inverted(true); // Required for RF Link module

and few other errors !!wats the prob ??????? and this same problem came while i compiled other codes like urs 

and i got the vietual wire installed!