RF Wireless Link - Arduino (TX) to BS2(RX)

So I was fooling around with the SparkFun RF Link - 4800bps - 315MHz for a school project. I needed to make a simple transmitter and receiver to control two servo motors. I don’t have two arduinos so I made do with the BS2 I got in highschool. The code is modified so its pretty generic now.

A few things to note:

  1. BS2 really can’t handle 4800bps so I made it run at 2400bps which worked fine.
  2. Sometimes garbage is received so we need to send a start byte and an end byte so that we can verify what is valid.

From the code below and the datasheet for the transmitter I hooked it up. Pin 4 from the arduino is hooked up to the rx pin on the transmitter.

I used the software serial library to set up everything.

//  Include the software serial library so we can control the RF
#include <SoftwareSerial.h>

//  Define some pins
#define rftx 4
#define rfrx 3

// Set up a new serial port for RF
SoftwareSerial rfSer = SoftwareSerial(rfrx, rftx);

void setup()
    // Define pin modes for rx, tx
    pinMode(rfrx, INPUT);
    pinMode(rftx, OUTPUT);
   // Set the data rate for the serial ports

void loop()

  rfSer.print("A11*");  //Send a command.  Start bit is A, end bit is *

From here on, all sent commands are: rfSer.print(“A(command)*”);

The receiver code is also pretty simple. The hardest part for me was trying to set the baud mode on the BS2. This may be intuitive to some, but I’m an idiot so, sorry. In this case its 396. The tx pin of the receiver is hooked up to pin 10 on the BS2.

' {$STAMP BS2}



SERIN 10, 396, [WAIT("A"),STR CHOICE\2\"*"]

GOTO loop

GOTO loop

GOTO loop

GOTO loop

GOTO loop

All of the BS2 code can be changed. Right now it takes commands 11, 12, 13, 14 and then the stamp can execute code based on those commands. This turned out to be a pretty simple project, but for a n00b like me, it was a nice challenge. Hope that someone can make use of this.


This is interesting. I was unable to use the sparkfun RF links I bought from them a year ago, by hooking them directly to a serial port. Due to the RF link's electronics, an encoding scheme was needed. Simply hooking them up to a serial UART would not work since the data being transmitted must be relatively DC-balanced, and must oscillate. IE, holding a DC signal on a transmitter's input pin, will not result in the receiver outputting the same DC level.

Hopefully the library I wrote was not completely unnecessary. The reliability of RF has it that some error checking should be used to verify data integrity, and some kind of method needs to be used to determine valid data from static. My library uses a kind of encoding that works with my RF links, uses error checking, and has methods to recognize valid data being transmitted by an arduino using the same library. You can read all about it here.

So my question is, are you receiving the same data as you put in? How reliable is the transmission? And are the modules sparkfun is selling now, different than the ones I purchased last year?

So my question is, are you receiving the same data as you put in?

When I send the A11* command, I receive exactly the same. In fact, I ran a counter that sent the digit from one to the other and each of the numbers transferred fine (0 to 255). When I was testing, I was writing "Hello world. This is the Arduino" and had no problem with it (once I figured out the 396 baud mode thing).

How reliable is the transmission?

The transmission seems to be very reliable. From across my apartment, I received everything I sent. The one problem I had with it was when I made antennae for the transmitter and the receiver I didn't measure the length (quarter wavelength on 315 mhz is supposed to be like 23cm or something like that I forget) and it changed my reliability to like 15%.

EDIT: For those of you who don't remember, wave length = speed of light / frequency. For the 315Mhz transmitter that I have, the length = 3x10^8/315000000 which equals .95238 m. I wanted a quarter wavelength antenna so divide by 4 = .238 m or 23.8 cm.

And are the modules sparkfun is selling now, different than the ones I purchased last year?

I can't say. This was my first order from Spark Fun.

That's great :confused:

I bought both modules twice, RF A315 and RF A434 and none of them work with either Serial, Softserial or the Lib who is mentioned in this thread.

Is there something special I have to know or todo?

Xmit Modul is connected
1 = Ground
2 = TX
3 = 5V

Rcv Module is connected
1, 6, 7 = Ground
2 = Rx
4, 5 = 5V

Every help is welcome :slight_smile:

Same here. I can't get these buggers to work, period. Definitely hooked up right. I even see my data periodically, though that may just be chance in all the noise I get.

I'd move to XBee, but you have to buy 2 at $25 each!

As I said before, encoding is in all likeliness required to use these modules. I've taken care of the hard part and written a library. (click here!).

My code is tested and works with these modules. With quarter-wave antennas the range is great.

Edit: oops, sorry. I didn't read the part where you tried the libraries I've written. Maybe the baud rate on your modules is less? In that case please change the timing value when creating an instance of the library. It should be changed from its current value of 208, to a slower rate of 416.

Has anyone make this library works on software version 14 o 15? when a try to compile it i recive this error:

In file included from arduino-0015-win\arduino-0015\hardware\cores\arduino/WProgram.h:4,

arduino-0015-win/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

arduino-0015-win/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

arduino-0015-win/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

In file included from arduino-0015-win\arduino-0015\hardware\cores\arduino/WProgram.h:6,

I have fixed the code. It involved a simple error in includes. The updated library may be downloaded here

You could also try the VirtualWire library. I'm using it with a 434MHz Tx/Rx pair also from Sparkfun and it works great (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208473338/20#20).



Woah, looks like that library goes where I was looking to go with my lib, with strings. I'll have to do some range testing, as well as checking to see the difference in code size. All in all, the virtualwire blows my lib out of the water. It lkooks like my slacking paid off ;D

My library may still have its uses, if you're only looking to transmit integers, or if the separate transmit/receive libraries lend themselves to better implementation in limited codespace.