Let's Make Robots!

Arduino RF Communication using RX & TX link Modules

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.

Check out this post Remote Temparature/Humidity link for some more ideas on how to encode strings.

Also here is some neat code using the case command - this is very basic switching .......

 

The idea is on the TX arduino you send character "A" (Red on) or "B"(Red off) or "C" (Blue on) or "D" (Blue off)

On the RX Arduino the loop() part of the code will be something like so:-

void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) //              RX  data

{

switch (buf[0]) { // we are only interested in the First buf[0] position

case 'A':
// this would be your switch code to turn RED LED ON
break;
case 'B':
// this would be your switch code to turn RED LED OFF
break;

case 'C':
// this would be your switch code to turn BLUE LED ON
break;
case 'D':
// this would be your switch code to turn BLUE LED OFF
break;

default:
break;
} } }

posted below

Gareth:

I've got the 2400bps receiver, so maybe thats why I can't run such high bit.rates?

And yes, I only use the code above, and v1.4 of the libary, only changed what wires to send and receive on.

EDIT:

Tried to modify, so I could store the last message in a char. But somehow it always adds an extra letter.
If the message sent was "LMR" it displays "LMRR".

Seems like the variable message, only gets the last letter stored. how come? Since the code is exactly the same as for the Serial.print.

It has to be something with the for loop, anyone know how to do this? I've also tried sending only numbers trough a int, but seems like thats kind of tricky too.

CODE: http://pastebin.org/57422

 

Hm, somehow it only work when lowering the bits per sec to under 300.

vw_setup(200);  // Bits per sec

 

How come?

 Just some pointers :-

It does not matter which data pin you use ...... they are both connected together - also the 3GND pins are common.

Change the Arduinos around ie the Tx one to Rx and Rx to TX and see if you get the same responce.

I run the TX voltage @5V and is overkill for 30 meter range at 4800Baud

Use only with the code posted above in the walk-through above (including the VirtualWire library above vers 1.4) - to eliminate any other code-ing clashes

I have been able to run my system at  vw_setup(4000);  // Bits per sec (serial monitor set to 4800Baud) at long distance - error free.

Sometimes certain other libraries mess the VirtualWires timer (timer 1 )  meaning if any other part of your code uses timer 1 then it will cause problems (eg standard servo library uses timer 1 and does not work- however servotimer2 works see this node)

Let me know how you get on.....

 

i have the same rf links as you. But can not hook them up till i get another arduino. I would like to see you solve this problem, will help me :P
Never mind! Seems like a connection error somplace, now it works.

Mine got two DATA connections on the Reciever, which one to use?

Wont recieve anything :P

 

Got the:

RF Link 2400bps Receiver - 315MHz
RF Link Transmitter - 315MHz


 

It does not matter which data pin you use ...... they are both connected together - also the 3GND pins are common.

"Wiieasy Rider" using RF Links modules

Just field tested my latest RF link experiment - by hacking a Tamiya RC offtrack car and installing a RF link module:-

"Wiieasy Rider"

It a cool way to control any RC equipment using Nintendos Wii Nunchuck controller.