Saturday, December 27, 2014

Zigbee Communication Between Two Arduino Boards

In this post, I'm writing down the steps I followed to exchange some simple wireless messages between two Arduino boards which are attached with Xbee wireless modules. For this purpose, I used two Arduino Uno boards, two Xbee shields which are the model of Seeed Studio XBee Shield v2.0 and two XBee modules from Digi XBee S2 module type.

Initially I searched through the web and found out that I have to configure XBee modules to create a Zigbee network by setting PAN IDs and some other stuff. For that there are two methods available as I read in the web. I attempted to try the first method which is using X-CTU tool from Digi international to configure XBee S2 modules. However, my efforts went in vain due to some reason which I still didn't figured out. The second method of configuring XBee S2 modules is using some tool such as PuTTy to communicate with the module from our PC. However I didn't try that second method yet. So, that means I didn't configure the XBee S2 modules at all.

Without making any configurations, we can simply transmit some data from an XBee S2 module which can be received by another XBee S2 module. That is what finally I did and write in this article about. For that purpose we just need two little programs (sketches) for Arduino boards. I will list down the steps I followed one by one.

(1) First of all, take an XBee shield and connect it to the Arduino Uno board. Then attach an XBee S2 module to the shield. Do the same to another set of Arduino board, XBee Shield and XBee S2 module so that we have to setups.

Assembled units

(2) Then, we need to program the Arduino boards. For this purpose, we should remove the two jumpers on Seeed Studio XBee shields. That's is to prevent Arduino IDE from sending programming data into the XBee S2 module while programming the Atmega MCU of the Arduino  Uno board. After removing the jumpers, we are ready to program them. From the two programs shown below, put the sender program (sketch) to one Arduino board and put the receiver program (sketch) to the other Arduino board.

Sender program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("H"); //turn on the LED
  delay(2000);
  Serial.println("L");//turn off the LED
  delay(2000);
}

Receiver program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
char msg = ' '; //contains the message from arduino sender
const int led = 13; //led at pin 13

void setup() {
  Serial.begin(9600);//Remember that the baud must be the same on both arduinos
  pinMode(led,OUTPUT);
}

void loop() {
  while(Serial.available() > 0) {
    msg=Serial.read();
    if(msg=='H') {
      digitalWrite(led,HIGH);
    }
    if(msg=='L') {
      digitalWrite(led,LOW);
    }
    msg = ' ';
    delay(1000);
  }
}

(3) After putting two programs into the two separate Arduino boards, we should disconnect them from the USB cables from PC. To connect the XBee S2 modules TX and Rx pins with the correct Rx and TX pins of the Arduino board, place the two jumpers in correct place of the XBee shield. Following picture shows the two jumpers in correct position.
Jumpers placed on XBee shield
(4) Connect the receiver device first into the PC using USB cables to power it up. You will notice that its on-board LED connected to Arduino pin 13 is not blinking yet. It need the command messages from the sender device to blink it according to our program. Then connect the sender device to the PC using USB cable to power it. After a short while you will notice that now receiver device is blinking its on-board LED in pin 13 giving the proof of wireless message exchange.

Our two modules powered up :)
Cheers!

12 comments:

  1. If I have more than one sensor, how can I my receiver show all the sensor results? Since your example only for 1 data receiving.. Thank you

    ReplyDelete
  2. if you want the configure the xbee modules using x_ctu
    follow this steps:
    1.pan id need to same for the both modules
    2.channels also need to same
    3.set SH,SL of the 1st module values to second module DH,DL
    4.set SH,SL of the 2nd module values to first module DH,DL
    and baudrate also need to same for both modules

    ReplyDelete
  3. how you transfer the data without configuration of zigbee modules. i think its not possible

    ReplyDelete
  4. how to communicate two xbee and two arduino and sensor with pc

    ReplyDelete
  5. nice tutorial
    it helps me, thanks

    ReplyDelete
  6. hi sir,
    i have some problem with zigbee network
    how to config zigbee chip not through arduino , program on its?

    ReplyDelete
  7. hey bro can we do the same with the Xbee S2C module... and how to you have configure both the modules .... as receiver and sender.... thanks in advance

    ReplyDelete
  8. can we store the data receieved in a database ?

    ReplyDelete
  9. Pls Am getting a -1 or [] character at the Rx terminal on my PC. the actual message was Hello World. What could be the problem?

    ReplyDelete
  10. see am gettting printed as
    3.52
    3.62
    3.62
    3.52
    3.71
    3.81
    3.71
    3.81
    3.81
    3.813.3.91 // see this i dnt knw y it is printing like this
    3.91
    333.3.3.91
    33.3.3.3.91
    3.91
    313.3.3.91//// ...
    33.3.3.3.91////....
    3.91


    see tell me how to over come this problem

    ReplyDelete