Home Automation Series: Learning XBee (ZigBee) with Arduino

Backstory (Hey, it is my blog)

XBee
Big Hero 6 recently was released in theaters and I took my three boys to see it. Aside from being a superb (if somewhat dark at times) movie, both my eldest son and I both left thinking that we, like Hero, could build some robotics of our own! Well… he thinks robotic dragons and such… I am actually thinking more about home automation projects. Which leads me to this post.

For Christmas I deiced I wanted a Raspberry Pi and an Arduino as the basis for projects. (But what they are and why is a completely different post…) This post is to share my learnings as much as it is a way for me to document them so I can refer back if needed in the future.

In the technology department where I work, we are making some extensive use of ZigBee and I figured I would play with it at home to get some experience and with the low power needs seemed potentially perfect for my needs. XBee is Digi’s brand name for their ZigBee protocol products… Read me at this page about Is XBee ZigBee if you are interested.

Introduction

This is a basic tutorial explaining my learnings about how to setup two XBee modules to talk to each other to enable Ardunio or other devices to transmit some data without cluttering your normal WIFI traffic.

Hardware

The first thing you need to know to play with this at home (and in my case with RasPi and Ardunio) is what hardware you will need. Here is my Amazon short list:

If you do not already have an Ardunio, then I recommend this starter kit to get introduced to the basics!Arduino Uno Ultimate Starter Kit — Includes 72 page Instruction Book
These are the actual ZigBee devices.2 x XBee 1mW Wire Antenna – Series 1 (802.15.4)
This is needed to program the XBees and for this tutorial, one will stay connected to your computer. (It does need a micro USB to USB cord, so if you do not have one, add that to your list as well.)XBEE Explorer USB
This is needed to connect the module to your Ardunio.Xbee Shield Module for Arduino

 

Walkthrough on how to configure the XBees

I recommend following Digi’s guide: http://examples.digi.com/get-started/basic-xbee-802-15-4-chat/

Testing the Setup

If you open the terminal window on both the Audrino Panel and the Cool Termial you should be able to type back and forth and see the messages. To make sure though, I used the Sketch below on my Ardunio to confirm I had it all up and working. If yours does not work, see troubleshooting at bottom of the post.

Ardunio Sketch:

int myData = 0;
int const ledpin = 13;
void setup(){
//Start up our serial port, we configured our XBEE devices for
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
}
void loop(){
//Serial.write("Hello");
//delay(1000);
while(true)
{
if(Serial.available() > 0){
myData = Serial.read();
if(myData == '1'){
digitalWrite(ledpin, HIGH);
Serial.write(myData);
}
if(myData == '2'){
digitalWrite(ledpin, LOW);
Serial.write(myData);
}
else{
Serial.write(myData);
}
}
}
}

 

Troubleshooting

  • Cannot get the Explorer/XBees to read n my computer
    • If you plug in your Explorer and you cannot get the Cool Terminal to read your XBee… the issue is that you first need to install the drivers.
  • Cannot receive data on my Ardunio
    • If you cannot get data to appear on the Ardunio (RX) then likely like me, you did not realize that the Ardunio shield has these small pins at the bottom which you need to change from USB to XBEE. This disables your ability to upload new sketch to the Ardunio until you re-position the pins, but does enable the Ardunio to listen via Serial to the XBee.

 

Logan

Clean eating advocate, home gym rat, gardener, costumer, play director, web-developer, and soo much more. :-) I love Jesus, my wife & kids, legos, xbox, duct tape, cardboard, and anything else which results in good clean fun with my three boys.

Leave a Reply