How to add an Xbee wireless link

Ladyada has written a really good tutorial on how to do this and supplies Xbee modules and Xbee adapters that make it easy to use the xbee's with the 5.0V provided by the arduino, the links to the adapter assembly and point-to-point communication tutorials can be found below.

I've added below some details on the way I've set up the Xbee link for the home energy monitor and an arduino sketch for sending data and another for receiving data, which turns the received character stream back into double values.

A note on range: I bought two 1mw Xbee's however I've been having a few problems with range. If your wondering which Xbee to get I would recommend going for higher wattage xbee's and maybe the one's with a socket for an aerial too.

Here's the part list, with links to suppliers and component costs:

Part list

Here's the full list of the component for the whole house energy monitor, the measurement board components are the second block.

Download OpenOffice: partlist28Jan.ods

Download Exel: partlist28Jan.xls

Step One

The first step in adding an Xbee link using adafruit adapters is to assemble the xbee adapters, as they come in kit form. Ladyada's assembly tutorial can be found here:

Xbee adapter assembly page

Step Two

The next step is to use a USB TTL-232 cable to configure the xbee's to work as a simple point-to-point link. Ladyada's tutorial can be found here:

Xbee radios: Basic point-to-point communication

Note: If your using linux X-CTU seems to work fine in wine.

Step Three

Now that you have two xbee's configured you can connect one up to the arduino that's taking the measurements and the other to the ethernet arduino.

In the sketch below the measurement arduino has digital pins 6 (Arduino RX) connected to Xbee TX and 7(Arduino TX) connected to Xbee RX assigned for communication with the xbee.

The ethernet arduino has digital pins 2 (Arduino RX) connected to Xbee TX and 3(Arduino TX) connected to Xbee RX.

The nice thing about the Xbee point to point link is that the Arduino just sends the data via serial to the Xbee and the xbee does all the packet creation and other clever things, you can take the xbee's out and replace them with a cable and the arduino sketch's dont need to be changed. When I built the energy monitor I wasn't sure If I would use the Xbee's or just have a wire link and so I made it modular so that the Xbee's can be removed fairly easily. The smaller box in the pictures below are the xbee+xbee adapter modules:

Left: Xbee module on top of the main box.  Middle: Xbee module on top of the ethernet box. 

The wire link between the xbee and the arduino has 4 wires: 5V, GND, DATA1, DATA2.

There is then a little mini adapter on the Xbee side that routes the 4 wires to the right pins on the xbee.

Left: Xbee module top removed.  Right: Arduino to xbee wiring in the ethernet unit.

Step Four - Arduino Software

The two sketches below demonstrate the xbee link independently of any of the other energy monitor code and hardware. The measurement side sketch simply Serial.prints() double values to the xbee. While the Ethernet side sketch reads in the data in character form and converts it back to double values so that they can be used again for useful things.

Download measurement side arduino sketch: XbeeSend.tar.gz

Download ethernet side arduino sketch: XbeeRecieve.tar.gz

Step one - compile and upload the sketches to their respective arduino's. For a guide on compiling and uploading the sketch to the Arduino have a look here.

Step two - power up both arduino's and listen with the arduino ide serial monitor to the ethernet arduino, hopefully you should see values being printed to the serial monitor. If you do and they are the same values that you sent, exellent you have set up your wireless link!

To go back to the home energy monitor main documentation page click here.