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.

I have just blogged a new project using the above basic system - RF remote LCD Temparature & Humidity sensor

Shows how to transmit floating point variables over RF and receive/display on a LCD display

I just had to share this, this is from Ezekiels bot Ozzy http://letsmakerobots.com/node/2935 

Took me forever to get something like this! I'm sure there's an easier way, but this is just too cool! Thanks again Eze :D

 

#include <VirtualWire.h>

typedef struct {
  byte command;
  char delim;
  char buffer [3];   //don't forget to account for the terminator.
}
packet_t;

void rfPacketOut(char commandChar,int data)
{
  packet_t packet; // initialize
  packet.command = commandChar; //"command char", buf[0] on receiving end
  packet.delim = '.'; // "delim char", buf[1] on receiving end
  itoa(data, packet.buffer, 10); // turns Integer to ASCII
  vw_send((uint8_t *)&packet, sizeof(packet));// Sends packet!
}

#undef int
#undef abs
#undef double
#undef float
#undef round

int ldr = 0;   // LDR on analog 0
int ldrVal;    // LDR Value


void setup()
{
    Serial.begin(9600);      // Debugging only
    Serial.println("setup");
 
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);     // Bits per sec
}

void loop()
{
    int ldrVal = analogRead(ldr) / 4;
    delay(10);

    rfPacketOut('A', ldrVal); // sends "A.255"
    delay(200);
}

 

Now on the receiving end, 'A' will be buf[0], the delim '.' will be buf[1], and the value will be buf[2], so you can do things accordingly! :)

1st off..thanks for a great walkthru, Gareth.

I'm ready to go wireless with my Arduino but I haven't decided whether to get a bluetooth module or a couple of RF modules like yours. Allthough the RF's are cheaper and have better range (I think?) I believe I'll go for bluetooth because:

* They're full duplex.

* They're faster (up to 115200 BAUD).

* I can connect it directly to my PC via a dongle, while the RF's would require my PC to be hooked up to ANOTHER MCU.

* They have less dataloss (again I think?).

On the other hand I love cheap lowtech solutions so I might as well get a couple of the RF's as well, since they ARE so damn cheap, plus I'm putting together an order at seeedstudio and they have some similar RF's (both 433 and 315 Mhz).

Anyway thanks for the walkthru. I'll definately use it sooner or later ;)

I was supprised at how inexpensive the bluetooth modules are becoming now, wow i have to get some.

Thanks for the RF links - i will make a list of suppliers and post it in the above content. (as i hate quote_ing from one source, unless they  send me free samples haha)

From my experience my bluetooth dongle is only good through 1 stone wall after that its unpredictable.

As far as i gather the Higher the frequency the less it is able to radiate through things, can anyone enlighten me on this (BT is around 2.4 Ghz)

The modules i use can go up to 4800 Baud but my application presently requires low speed. (to be revealed later)

I had to point one thing out, the Receiver (longer of the two) should *only* be at 5v, where the Transmitter (smaller, obviously :D) can be from 2 - 12v.  Haha, don't try put 12v to the receiver... I have, luckily, it's still alive, but it got really hot, really quick.

But I agree, these things are badass! I didn't even think about getting the 315mhz version for duplex, all though, you can use a transmitter and receiver (of the same frequency) on the same arduino, but I think it's only half-duplex with VirtualWire.  I like your setup :D I just ordered a couple battery holders for the same kind of idea.

HeHe i got all the right notes but in wrong order.

Thanks for the "Proof" read have ammended the walkthrough.

Now I'm sorely tempted to make a sparkfun order. They will certianly warrant more temptation when I do order from them.  
I wish i had bought the two versions they have 316Mhz and also 434Mhz then i could have made a duplex comm link........ next time