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

(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


RXTX_004RXlink.jpg

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!!!!!!)

RXTXRXbasic.jpg


 // 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


 RXTXTXLink.jpg

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

RXTXTXBasic.jpg


// 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)

RXTXRXscreen.jpg

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.

hey gareth,

this stuff is awesome!

I have two arduino boards, a sender and reciever like you have used, two servos and a wii nunchuck.

Is it possible to have one board with the nunchuck sending a signal to another which is connect to the servos, thus
being a wireless pan/tilt system using a wii nunchuck??

I really have no idea on how to do this, if you could help me that would be awesome, I have attatched a code which can pan/tilt two servos using the nunchuck one one arduino board all wired up. WOuld you be able to separate these into what i was talking about above?

"#include <Wire.h>
#include <string.h>
#include <stdio.h>

uint8_t outbuf[6];

int cnt = 0;
int ledPin = 13;

int servoPin = 7;
int servoPin2 = 8;

int pulseWidth = 0;
int pulseWidth2 = 0;

long lastPulse = 0;
long lastPulse2 = 0;

int z_button = 0;
int c_button = 0;

int refreshTime = 20;

int minPulse = 1000;
int minPulse2 = 500;

int dtime=10;

#define pwbuffsize 10
long pwbuff[pwbuffsize];
long pwbuffpos = 0;
long pwbuff2[pwbuffsize];
long pwbuffpos2 = 0;

void setup()
{
    Serial.begin (19200);
    Wire.begin ();
    nunchuck_init ();
    pinMode(servoPin, OUTPUT);
    pinMode(servoPin2, OUTPUT);

    pulseWidth = minPulse;
    pulseWidth2 = minPulse2;
    Serial.print ("Finished setup\n");
}

void nunchuck_init()
{
    Wire.beginTransmission (0x52);
    Wire.send (0x40);
    Wire.send (0x00); 
    Wire.endTransmission ();
}

void send_zero()
{
    Wire.beginTransmission (0x52);
    Wire.send (0x00);
    Wire.endTransmission ();
}

int t = 0;

void loop()
{
    t++;
    long last = millis();

    if( t == 1) {

        t = 0;

        Wire.requestFrom (0x52, 6);

        while (Wire.available ()) {
            outbuf[cnt] = nunchuk_decode_byte (Wire.receive ());
            digitalWrite (ledPin, HIGH);
            cnt++;
        }

        if (cnt >= 5) {

            //            printNunchuckData();

            int z_button = 0;
            int c_button = 0;

            if ((outbuf[5] >> 0) & 1)
                z_button = 1;
            if ((outbuf[5] >> 1) & 1)
                c_button = 1;

            switch (c_button) {
            case 1:
                switch (z_button) {
                case 0:
                    break;
                case 1:
                    muovi();
                    break;
                }
                break;
            case 0:
                switch (z_button) {
                case 0:
                    delay(10000);
                    break;
                case 1:
                    delay(3000);
                    break;
                }
                break;
            }
        }

        cnt = 0;
        send_zero();

    } // if(t==)

    updateServo();

    delay(dtime);
}


void updateServo() {

    if (millis() - lastPulse >= refreshTime) {

        digitalWrite(servoPin, HIGH);
        delayMicroseconds(pulseWidth);
        digitalWrite(servoPin, LOW);

        digitalWrite(servoPin2, HIGH);
        delayMicroseconds(pulseWidth2);
        digitalWrite(servoPin2, LOW);

        lastPulse = millis();
    }
}

int i=0;
void printNunchuckData()
{
    int joy_x_axis = outbuf[0];
    int joy_y_axis = outbuf[1];
    int accel_x_axis = outbuf[2]; // * 2 * 2;
    int accel_y_axis = outbuf[3]; // * 2 * 2;
    int accel_z_axis = outbuf[4]; // * 2 * 2;

    int z_button = 0;
    int c_button = 0;

    if ((outbuf[5] >> 0) & 1)
        z_button = 1;
    if ((outbuf[5] >> 1) & 1)
        c_button = 1;
    if ((outbuf[5] >> 2) & 1)
        accel_x_axis += 2;
    if ((outbuf[5] >> 3) & 1)
        accel_x_axis += 1;

    if ((outbuf[5] >> 4) & 1)
        accel_y_axis += 2;
    if ((outbuf[5] >> 5) & 1)
        accel_y_axis += 1;

    if ((outbuf[5] >> 6) & 1)
        accel_z_axis += 2;
    if ((outbuf[5] >> 7) & 1)
        accel_z_axis += 1;

    Serial.print (i,DEC);
    Serial.print ("\t");

    Serial.print ("X: ");
    Serial.print (joy_x_axis, DEC);
    Serial.print ("\t");

    Serial.print ("Y: ");
    Serial.print (joy_y_axis, DEC);
    Serial.print ("\t");

    Serial.print ("AccX: ");
    Serial.print (accel_x_axis, DEC);
    Serial.print ("\t");

    Serial.print ("AccY: ");
    Serial.print (accel_y_axis, DEC);
    Serial.print ("\t");

    Serial.print ("AccZ: ");
    Serial.print (accel_z_axis, DEC);
    Serial.print ("\t");

    Serial.print (z_button, DEC);
    Serial.print (" ");
    Serial.print (c_button, DEC);
    Serial.print ("\r\n");
    i++;
}

char nunchuk_decode_byte (char x)
{
    x = (x ^ 0x17) + 0x17;
    return x;
}

void muovi (){
    float tilt = (700 - outbuf[3]*2*2);
    float tilt2 = outbuf[2]*2*2;

    tilt = (tilt);
    pulseWidth = (tilt * 5) + minPulse;

    tilt2 = (tilt2-288);
    pulseWidth2 = (tilt2 * 5) + minPulse2;

    pwbuff[pwbuffpos] = pulseWidth;
    pwbuff2[pwbuffpos2] = pulseWidth2;
   
    if( ++pwbuffpos == pwbuffsize ) pwbuffpos = 0;
    if( ++pwbuffpos2 == pwbuffsize ) pwbuffpos2 = 0;


    pulseWidth=0;
    pulseWidth2=0;

    for( int p=0; p<pwbuffsize; p++ ){
        pulseWidth += pwbuff[p];
        pulseWidth2 += pwbuff2[p];
    }

    pulseWidth /= pwbuffsize;
    pulseWidth2 /= pwbuffsize;

}

Thanks heaps mate!

Gareth's picture

Yes it is possible........however your code could do with a bit of trimming.

See this post Wiieasy rider of mine, it uses the nunchuck and two servos (one for direction and one for speed)

And read this comment here for Sending Wii variables and here too (gives a bit more info re the process)

Here too for multiple variable TXing & Rxing with code examples.

It is also possible to use the WiiMotion controller too.

dent's picture

Because 23 is the magic number?

Because this post has been collected by 23 members?

Because LMR is 2 years and 3 months old?

Gareth's picture

Hey ....Mr.Dent... even you know that the HitchHikers Guide states that the computer "Deep Thought" calculates "42" as the Magic number.

If i collect 19 move then for sure all the Arduinos could talk together and rival "Deep Thought"

 

samdaman's picture

First of all: No experience, and currently building my first robot, (the little 8).

Second of All: Thanks for the thorough walkthrough.

Question One: What is the object in the first/top picture on the right with the glowing screen.

Question Two: Can you expand a little on the CD audio trick?

Question Three: Is the antenna sold as 'Antenna' or another kind of wire, also what connects it to the reciever/transmitter?

Question Four: Do you use two identical arduinos, or different ones. Could I use two of these: (http://www.sparkfun.com/commerce/product_info.php?products_id=9152)?

Last Question (probably the dummest): Can PICAXE chips/boards be used??

 

 

 

Gareth's picture

Q1:- Glowing object is a LCD Display see this project here Remote Temparature/Humidity link

Q2:- On some computer cd drives there is a 4 pin plug cable that connects from the cd drive to the mother board (porting audio direct from cddrive to audio card - meaning that you can play cds direct off your computer without using any software) - over the years i have collected quite a few - as the cable is not really needed it can be recycled - it fits the link units perfectly. 

Q3:- The Antenna is just any piece of wire - around 30cms or so - connected direct to Antenna pin on bot Rx&Tx modules.

Q4:- The project should work on any combination of arduinos they do not have to be the same.

        Yes the Arduino Mega will work and in fact i bought mine from this supplier

(if the Supplier would like to send free samples to LMR bods for review then they would be greatly appreciated - hint-hint)

Q5:- http://letsmakerobots.com/node/5194 will help you with picaxe system (where i had my original impulse)

 

Noob alert.... can you use the arduino to transmit using the transmitter then have the receiver connected to a usb FTDI serial cable.  then using something like C# to read the serial port and collect what was sent from the transmitter that way?

Gareth's picture

I have no experience of using the FTDI serial link.

What would be the advantage of doing it this way ?.

....maybe its better to post your query in the Arduino forum

I want to allow the Arduino to wirelessly communicate with the pc.  The thought would be to have the transmitter connected to the Arduino and the receiver connected to the PC.  That way the Arduino detects something and notifies the PC.  The PC would monitor the serial port and then do an action based on the values passed in from the Arduino.  I bought a book today called "Make things Talk" and there is a section that says they do it for a one way communication.  so now I know it is doable, just need to see if I can understand it all...

Thanks for your help

 tim

Gareth's picture

Simplex communication refers to communication that occurs in one direction only.

(this is the type of communication link i use in the project above)

 

Half-Duplex communication refers to communication in both directions, but only one direction at a time (not simultaneously).

(you would have to add an extra RX&TX modules (on a different frequency) to acheive this with the project above)

Full Duplex communication is a system composed of two connected devices that can communicate with one another in both directions at the same time.

The Xbee for example can support both Half and Full Duplex.

 

If you want to experiment with arduino and the PC joined together then check out the processing language (its almost identical to the arduino IDE but with more goodies for the PC side)

give me total knowledge which help me  to construct a robot.

thank u 

Benbo231's picture

First, read this:

best practice

Then this:

Start here robot

Stigern's picture

Gareth:

 

I've run into trouble using the VirtualWire.h and Servo.h or MegaServo.h.

Seems like there are some conflicts using both those libaries at the same time.
 

C:\Users\Stig\AppData\Local\Temp\untitled30508.tmp\sketch_jan21a\applet\VirtualWire\VirtualWire.cpp.o:E:\Programming\Arduino\hardware\libraries\VirtualWire/VirtualWire.cpp:412: first defined here 

Sketch works fine, but when I add  #include <Servo.h> I get that error.

Gareth's picture

Virtualwire.h Servo.h and MegaServo.h dont mix

Basically because they all try to use Timer1 and thats what causes the conflicts.....

.... to get around this try using ServoTimer2.h   as its name suggest it uses Timer2 hence no conflicts.

i have used this library in all of my current sketches - i find it more accurate as you send the millisecond values to it (and not degrees).

Hope this helps - let me know how you get on...

ArvotroN's picture

I was using virtualwire.h and servo.h in two arduinos with two pairs of RF links (434 & 315mhz) ,to form a full duplex setup. I had run into the same problem - " multiple definition of `__vector_11' "

Looks like Servotimer2.h is the workaround. Tested with virtualwire v1.5 and works fine. :)

 

Gareth's picture

Yes, libraries fighting to use the same timers leads to all sorts of unexpected bugs..... Its a right pain to know which timers are being used with out jumping into the actual library code ....

..... it would be helpful if library developers would declare at least in some of thier example codes which timers are being "Hi_Jacked" 

patrickmccabe's picture
Well i can do this. But i am trying to send the analog value of a joystick, the x and y axis. Here is my forum and captain obvious's code and suggestions. WE got the first bit of code to work to send a single value but  we still cant do 2 values. We think this would help people out. Must say that this is a great blog but it seems to be a bit fuzzy around on how to do values. http://letsmakerobots.com/node/14000
Gareth's picture

 This is my current way of sending multiple variables, any ideas on slim-line_ing the code are Welcomed.

Its highly likely that a lot of the pre-code can be cut out - it was a nightmare to get it all working.

Yes i know my buffers are oversized...........

// www.letsmakerobots.com   (Gareth) Node 12336
// How to transmit more than one variable on a RF Serial Link
// Basic idea is So :- send a prefix character ie. "X" in front of your "Stringed" value
//                     Your next value will have a different prefix ie "Y" plus "stringed" value etc.etc.
//               This way the RX end can just sit and wait for incoming variables (even from multiple TX sources)

//                All the RX side needs to do is look at the prefix to see which variable it is .....easy.........

int X=0;   //First Variable
int Y=0;   //Second Variable

int ii=0;  int jj=0;

#include "Wire.h"
#include <VirtualWire.h> // library for RF RX/TX
#undef int
#undef abs
#undef double
#undef float
#undef round

char charnum[10];

int bz=0;
void setup() {
  // debug Serial.begin(9600);
  // Set up TX Link
  vw_set_tx_pin(8);   // adjust this value to point to your tx pin of module
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);     // Bits per sec
}

void loop() {
char bufferX[5] ; memset(bufferX, '\0', sizeof(bufferX));  // reset and zero buffer for first variable prefix
char numX[5]   ; memset(numX, '\0', sizeof(numX));      // reset and zero buffer for first variable Value
char bufferY[5] ; memset(bufferY, '\0', sizeof(bufferY));  // reset and zero buffer for Second variable prefix
char numY[5]   ; memset(numY, '\0', sizeof(numY));      // reset and zero buffer for Second variable Value
    
//-------------------First Variable Transmit ----------------------------------------------     
 X = (int)chuck.readRoll();      // read your first variable here.....mine was wiichuck data
  strcat(bufferX,"X");     // place an "X" as the first part of string
  ii=byte(X);                // Here i convert to a single byte - because for my applications value range (0-255)ie one byte
  itoa(ii,numX,10);       // convert the number to a string
  strcat(bufferX,numX); // Join the "X" and the string together
                                 //Debug  Serial.println(bufferX);
  vw_send((uint8_t *)bufferX, strlen(bufferX));  //actually send on RF
  vw_wait_tx();             // Wait until the whole message is TXed
  delay(20);                // found i need a short delay before second TX
//-------------------Second Variable Transmit ----------------------------------------------
 Y = (int)chuck.readPitch();     // read your second variable here
  strcat(bufferY,"Y");    // place an "Y" as the first part of string
  jj=byte(Y);                // Here i convert to a single byte - because for my applications value range (0-255)ie one byte
  itoa(jj,numY,10);       // convert the number to a string
  strcat(bufferY,numY); // Join the "Y" and the string together
                                 // Debug Serial.println(bufferY);
  vw_send((uint8_t *)bufferY, strlen(bufferY)); //actually send on RF
  vw_wait_tx();             // Wait until the whole message is gone
  delay(20);
//---------------------------------------------------------------------------------------------  
  }

Gareth's picture

 I have used this code in "Wiieasy rider"

Basically i TX either "P"or "R" plus the servoposition ie"213" as string...............eg "P213"

Then on the RX side split the "P" or "R"  and extract the number into an integer variable

(i have highlighted the important bits)

RX Loop coding is approx so :-

{
     uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      char val[buflen];
      memset(val, '\0', sizeof(val));   // Zero buffer

      strncpy(val, (char *)buf + 1, buflen - 1);  // extract value out of the string ie buf[1]+buf[2]+buf[3]

      int VAL = atoi ( val );  // then convert it to interger ie "213" to 213

      switch (buf[0]) {   // buf[0] is the first position of the RX string
               
        case 'P':
            Serial.print("Servo Pitch ");
            servopitch.write(VAL);            // ie buf[1]+buf[2]+buf[3]                  
            break;
        case 'R':
            Serial.print("Servo Roll ");
            servoroll.write(VAL);
             break;
        default:
            break;
      }
    }
   

Stigern's picture
What if you want to recieve a value? like a servo position ?
Gareth's picture
can be deleted (sorry admin)

hi Gareth!!

Please help me, i've already put the two arduino to talk each other. But i don't know how i can identify what message is coming. Like sending 0 or 1 to turn on the RED LED or the BLUE LED from my project, respectively. Can you put the code and explain it to me? i'm starting.

Congratulations for the post!

Thanks a lot!!

Renke

Gareth's picture

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

patrickmccabe's picture
posted below
Stigern's picture

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

 

Stigern's picture

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

vw_setup(200);  // Bits per sec

 

How come?

Gareth's picture

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

 

patrickmccabe's picture
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
Stigern's picture
Never mind! Seems like a connection error somplace, now it works.
Stigern's picture

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


 

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

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

 

Gareth's picture

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

CaptainObvious's picture

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! :)

Aniss1001's picture

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

Gareth's picture

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)

CaptainObvious's picture

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.

Gareth's picture

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

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

MechGeek2000's picture
Now I'm sorely tempted to make a sparkfun order. They will certianly warrant more temptation when I do order from them.  
Gareth's picture
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