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!
Here are a few limitations to RF solution:
- Communications is only one way. If you wanted two way communications you’d need to buy two receivers and two transmitters which would raise the cost to $18. This is still cheaper than other solutions I found.
- The variable gain on the receiver causes it to pick up lots of background noise. I had to do some processing with the Arduino to filter out this noise. More details about this below in the code section.
- Bandwidth maxes out at 2400 bps, but there is a version with 4800 bps. A large portion of this bandwidth is used for network protocol I wrote that handles error detection.
- Range is limited to a max of 500 feet.
The advantages are that it is cheap and it is pretty easy to use.
Below are some images showing how I hooked up the receiver and transmitter to two different Arduino boards. When wiring the receiver/transmitter you only need is to give them power/ground and then a pin for the TX (serial transmit) or RX (serial receive) pin. I also wired a button to the Arduino doing the transmitting, and used the LED on pin 13 that is built into my Arduino boards on the receiver so I could test this setup. The test app just flashes a button on the receiving board when a button is pressed on the transmitting board.
Since the receiver is constantly picking up random noise I add a few extra bytes to every data packet. I add two bytes to signify the start of a data packet. Then I send the a byte address. This address allows multiple devices to work in the same area without interfering with each other. Next is the data (in my example code it’s an unsigned int (2 bytes). Lastly I send a checksum which is a simple xor of all the data bytes to make sure the data got received without being corrupted.
I broke the Arduino code into two files. If you’ve never used two files before with Arduino all you need to to is keep both files in the same directory and the Arduino IDE merges them for you. Here is the full code for the main application, and here is the full code that does the network error catching.
Increasing the Range
I did all of my initial testing without any of these improvement and everything worked fine with these devices inside the same room.
- Add an antenna. All you need is a 23 cm piece of wire. I did this and it made it so I could reliably transmit data from one corner of my house to the other (3 floor town house).
- Increase the voltage for the transmitter. The transmitter can use 2-12 volts. With 5 volts I got pleanty of range for my use case, but increase this if you need more range.
- Reduce the baud rate. My test app runs at 1200 bps out of the max 2400 bps. You could drop this even further to something like 300 bps and that should help reduce transfer errors and hopefully increase range.
I’ll mention an even cheaper idea I had while doing this. If you will always have line of sight between your devices you could setup something very similar to this with an IR LED and IR transistor. It would work like a TV remote. It won’t work for me because I want this to go through walls, but if line of sight is fine for you then you could use this code and an IR LED/transistor would probably cost under $3.