Xbee communication between two arduinos

Sunday, November 8, 2015


Welcome to this tutorial about wireless communication with arduino, I hope that you’ll find this tutorial useful.

What do we need?

  1. Two arduino UNO;
  2. Two xbee modules (I use xbee Series 2 module);
  3. Two wireless proto shield (with or without sd cards support) Link;

Here you can see the arduino uno with the wireless shield and xbee module mounted on.

xbee

Preparing arduino

First of all put the xbee module on wireless shield and then the shield on arduino. After this, move the lever of serial-select (you find it on wireless shield) from micro to usb and then connect the arduino to the PC.
To configure the xbee module you have to upload this program on arduino.

void setup() { }
void loop() { }

Make this on both arduinos.

Configure Modules

To configure the xbee modules you need X-CTU (only Windows) [download it HERE].
After installing X-CTU, update it and then connect the arduino with the wireless shield and the module to PC(THE SERIAL SELECT LEVER MUST BE ON USB SIDE).
once you’ve connected  arduino, search its  port and select it, then click on Test/Query.

xctu


If there is a positive response click  modem configuration and then click Read.
Now let’s configure the arduino sender:

  1. click on FUNCTION SET and select ZNET 2.5 ROUTER/END DEVICE AT;
  2. change the DESTINATION NUMBER HIGH with the SERIAL NUMBER HIGH of the other xbee module  that you can read connecting the other xbee module to X-CTU (if you have xbee module s2 write  13A200 on destination number high);
  3. change the DESTINATION NUMBER LOW with the SERIAL NUMBER LOW of the other xbee module that you can read connecting the other xbee module to X-CTU (if you have xbee module s2 write 407B0DEC on destination number low);
  4. the PAN ID  must be the same for both xbee modules.

Now let’s start with arduino receiver:

  1. click on FUNCTION SET and select ZNET 2.5 COORDINATOR AT;
  2. change the DESTINATION NUMBER HIGH with the SERIAL NUMBER HIGH of the other xbee module   (if you have xbee module s2 write  13A200 on destination number high);
  3. change the DESTINATION NUMBER LOW with the SERIAL NUMBER LOW of the other xbee module (if you have xbee module s2 write 407B0DEC on destination number low);
  4. use the same PAN ID of the other module.

Programming part

Sender

To program arduino with xbee communication you have to use the normal serial library as you can see from the code:

Sender's Code

Upload this code on your arduino sender.

Receiver

Code:

Receiver's Code

Now, once you have  uploaded this code on the arduino receiver, you’ll be able to try the wireless communication.

This is the end of the tutorial, I hope (again) that you can find this useful for your future projects.

For any problem, write a comment below.