Wireless Modules with Arduino

Tutorial on how to use cheap wireless modules with Arduino 28 Dec 2010

Wireless Transmitter and Receiver Modules
Wireless Transmitter and Receiver Modules

I recently ordered a wireless transmitter and receiver, from Sparkfun.  They are super cheap, but getting them to work is a little tricky.

Important Note: It's been a long time since I've written this, so keep in mind that some things could be improved. In particular, it would be a good idea to implement some form of run-length limiting

Circuits

Here is the transmitter circuit.  In my case, I had to remove the antenna in order to make it work.

Transmitter Circuit Diagram
Transmitter Circuit Diagram

Here’s the general receiver circuit.

Receiver Circuit Diagram
Receiver Circuit Diagram

However, if you are using an Arduino microcontroller board with a built in USB to serial converter, it will pull the Rx pin of the Arduino high through a 1K resistor overpowering the Receiver module.

One solution is to use a different Arduino pin as a serial input and use the softwareserial library to receive data.

If you still want to use the Arduino’s hardware UART, you can add a buffer between the wireless module and the Arduino so that the receiver can overcome the USB to serial connection’s pull-up effect:

Wireless Receiver Circuit Diagram with Buffer
Wireless Receiver Circuit Diagram with Buffer

You could also use a transistor or op-amp as a buffer.

Code

Packet Format

Data is sent in packets which consist of the following

Byte # Description
1 0xAA Preamble
2 0x55 Preamble
3 Length (number of bytes in data Block)
4 ... n Data
n+1 Checksum (data bytes summed and truncated)

First the microcontroller looks for the preamble bytes which mark the start of the packet in the random stream of data the microcontroller is receiving, then the microcontroller reads the length byte so that it knows how many bytes to read.  Last, the receiving microcontroller reads the checksum and compares it to the one calculated for the data it received.  If the checksums don’t match, then it knows that something was corrupted.

The checksum is calculated by summing the data bytes and truncating the result to one byte:

modules

Sample Transmitter Code

Sample Receiver Code (with hardware UART)