Cheap RF Wireless Between Arduinos

I was looking for a way to handle wireless communications between two Arduino boards. Other options like Xbee or Bluetooth were going to cost $50 to over $100. Then I found a cheap RF transmitter and receiver at Sparkfun. The total cost is only $9!

For a full description and all the code check out this writeup. http://www.glacialwanderer.com/hobbyrobotics/?p=291

Here's the circuit I used.

And some of the code:

// Sends an unsigned int over the RF network
void writeUInt(unsigned int val)
{
  byte checksum = (val/256) ^ (val&0xFF);
  Serial.write(0xF0);  // This gets reciever in sync with transmitter
  Serial.write(g_network_sig, NETWORK_SIG_SIZE);
  Serial.write((byte*)&val, VAL_SIZE);
  Serial.write(checksum); //CHECKSUM_SIZE
}

// Receives an unsigned int over the RF network
unsigned int readUInt(bool wait)
{
  int pos = 0;          // Position in the network signature
  unsigned int val;     // Value of the unsigned int
  byte c = 0;           // Current byte
  
  if((Serial.available() < PACKET_SIZE) && (wait == false))
  {
    return 0xFFFF;
  }
  
  while(pos < NETWORK_SIG_SIZE)
  { 
    while(Serial.available() == 0); // Wait until something is avalible
    c = Serial.read();

    if (c == g_network_sig[pos])
    {
      if (pos == NETWORK_SIG_SIZE-1)
      {
        byte checksum;

        while(Serial.available() < VAL_SIZE + CHECKSUM_SIZE); // Wait until something is avalible
        val      =  Serial.read();
        val      += ((unsigned int)Serial.read())*256;
        checksum =  Serial.read();
        
        if (checksum != ((val/256) ^ (val&0xFF)))
        {
          // Checksum failed
          pos = -1;
        }
      }
      ++pos;
    }
    else if (c == g_network_sig[0])
    {
      pos = 1;
    }
    else
    {
      pos = 0;
      if (!wait)
      {
        return 0xFFFF;
      }
    }
  }
  return val;
}

For a full description and all the code check out this writeup. http://www.glacialwanderer.com/hobbyrobotics/?p=291

I believe you can also use the VirtualWire library with these modules. I know it works for the 433 MHz modules from Sparkfun.

That is an amazing price compared to Xbee and Bluetooth! Thanks for letting us know.

Veronica, that VirtualWire library looks like it would work. It seemed to be pretty nice, but I didn't see an option to use the hardware UART (hardware serial support on pins 0/1). Did I miss this? If you're using the UART for for other things this looks like it might be a nice library, but using the hardware UART would give big advantages like using less cycles and having a built in buffer that you don't need to constantly watch with the receiver.

I've been working on this exact concept for a little while now. I've build a protocol which sits ontop of the reliable VirtualWire library.

http://milesburton.com/wiki/index.php?title=HyperCom_Packet_Library

It's been quite an interesting project so far. I've setup two protocol radios so allow half-duplex, two way communication between arduinos.

THe only bad aspect of these radios is speed. You cannot tranfer much data, reliably.

To be honest, I've only used it for one project, as a cheap replacement for a broken tx/rx in an rc car.

I know you can set which pins to use as rx/tx but I just used the defaults. Not sure what would happen if you used 0/1 of the arduino.

Ver

You could use 0,1 if you wanted. I'd avoid it just incase you get some kind of conflicts

Some media:

There's a slight bug with the transmitter but you can see it all working here:

I honestly think these little radios are the way forward for cheap long distance. If you throw in a small controller chip to provide reliability - it would rock

Your enthusiasm taken to a whole new level:
http://news.jeelabs.org/