Moving Forward with Arduino – Chapter 14 – XBee introduction
Please note that the tutorials are not currently compatible with Arduino IDE v1.0. Please continue to use v22 or v23 until further notice.
This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Welcome back fellow arduidans!
From this chapter on, the title of this series will now be Moving Forward with Arduino, as we are well past the Getting Started stage
There is also a new Arduino-based project in another article – blinky the clock.
This instalment is by user request – we will examine the XBee wireless data transceivers from Digi in the USA. Although in the past we have experimented with the inexpensive 315MHz transmit/receive pair modules (chapter 11), they have been somewhat low in range and slow with data transmission. The XBee system changes this for the better.
First of all, what is an Xbee module? It is a very small piece of hardware that can connect wirelessly with another using the Zigbee communication protocols. There are many different models, including aerial types and power outputs. At this stage I will demonstrate with the 1mW output chip-aerial model.
From Wikipedia, Zigbee is:
ZigBee is a specification for a suite of high level communication protocols using small, low-power digital radios based on the IEEE 802.15.4-2003 standard for wireless home area networks (WHANs), such as wireless light switches with lamps, electrical meters with in-home-displays, consumer electronics equipment via short-range radio. The technology defined by the ZigBee specification is intended to be simpler and less expensive than other WPANs, such as Bluetooth. ZigBee is targeted at radio-frequency (RF) applications that require a low data rate, long battery life, and secure networking.
Phew. For this chapter I will try and keep things as simple as possible to start off with. Here is an image of a typical Xbee unit:
Note that the pin spacing is small than 2.54mm, so you cannot just drop these into a breadboard. However for the purposes of our experimenting more equipment is needed. Therefore I am making use of this retail package from Sparkfun retailers:
This bundle includes two Xbee modules, an Xbee shield to connect one of the modules to an Arduino Duemilanove/Uno-style board. When it comes time to solder the sockets into your shield, the best way is to insert them into another shield that is upside down, then drop the new shield on top and solder. For example:

Finally, the bundle also includes a USB Explorer board, which allows us to connect one Xbee to a personal computer. This allows us to display serial data received by the Xbee using terminal software on the PC. One can also adjust certain Xbee hardware parameters by using the explorer board such software.
Let’s do that now. You will need some terminal software loaded on your computer. For example, Hyperterminal or Realterm. Plug an Xbee into the explorer board, and that into your PC via a USB cable. Determine which port (for example COM2:) it is using with your operating system, then create a new terminal connection. Set he connection to 9600 speed, 8 bits, no parity, 1 stop bit and hardware flow control. For example, in Hyperterminal this would look like:
Once you have established the connection, press “+++” (that is, plus three times, don’t press enter) and wait. The terminal screen should display “OK”. This means you are in the XBee configuration mode, where we can check the settings and change some parameters of the module. Enter “ATID” and press enter. The terminal window should display a four-digit number, which is the network ID of the module. It should be set by default to 3332. Unless you plan on creating a huge mesh network anytime soon, leave it be. To be sure your modules will talk to each other, repeat this process with your other XBee and make sure it also returns 3332. However as this is the default value, they should be fine.
Now for our first example of data transmission, insert one Xbee into the explorer module, and the other into the Xbee shield. With regards to the Xbee shield – whenever it is connected to an Arduino board and you about to upload a sketch, look for a tiny switch and change it to DLINE from UART. Don’t forget to change it back after uploading the sketch. See:
We are going to use the two Xbee modules as a straight, one-way serial line. That is, send some data out of the TX pin on the transmit board, and receive it into the terminal on the PC. Now upload this sketch into your Arduino board. This is a simple sketch, it just sends numbers out via the serial output. Then set the switch on the shield back to UART, and reset the board. If you can, run this board on external power and put it away from the desk, to give you the feeling that this is working
Note: More often that not one can purchase AC plug packs that have USB sockets in them, for charging fruity music players, and so on.
Or you might have received one as a mobile phone charger. These are great for powering Arduino boards without using a PC.
Now ensure your explorer module is plugged in, and use the terminal software to connect to the port the explorer is plugged into. After connecting, you should be presented with a scrolling list of numbers from 0 to 99, as per example 14.1 sketch:
How did you go? Sometimes I used to get the COM: ports mixed up on the PC, so that is something to keep track of. If you are powering both Xbees from your PC using USB cables, double-check the terminal software is looking at the explorer board, as an Arduino transmitting serial data through an Xbee shield will still send the same data back to the PC via USB.
Now that we have sent data in one direction, we can start to harness the true power of Xbees – they are transceivers, i.e. send and receive data.
Example 14.2
We will create an on-demand temperature and light-level sensor. Our arduino board will have a temperature sensor and a light-dependent resistor, and using the terminal on the computer, we can request a temperature or light-level reading from the remote board. More about temperature sensors in chapter two. First of all, the remote board hardware setup:
… and the schematic:
And as I live in a block of solid concrete/brick flats, it never hurts to elevate your other Xbee:
For the PC side of things, use the explorer board and USB cable. Here is the sketch. It is quite simple. The remote board ‘listens’ to its serial in line. If it receives a “1″, it reads the temperature, converts it to Celsius and Fahrenheit, and writes the result to its serial out line, which is sent over our Xbee data bridge and received by the host computer. A “2″ will result in the analogue value of the photocell to be sent back as a “light level”. Once again we use the terminal software to control the system. Here is a quick video of the terminal in action:
The speed is quite good, almost instantaneous. By now hopefully you can see how easy it is to end some data backwards and forwards over the ether. The range is only limited by the obstacles between the Xbee transceivers and the particular power output of each model. With example 14.2, there were two double-brick walls between them. Furthermore, we can build fully computer-independent systems that can talk to each other, such as more portable remote controls, or other data-gathering systems. In the next few chapters, sooner rather than later.
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.














[...] This post was mentioned on Twitter by Jonathan Oxer, John Boxall. John Boxall said: Moving Forward with Arduino – Chapter 14 – XBee introduction: http://wp.me/pQmjR-Hf [...]
Pingback by Tweets that mention Moving Forward with Arduino – Chapter 14 – XBee introduction « t r o n i x s t u f f -- Topsy.com | August 6, 2010 |
Nice one
I’ll give it a go over the weekend.
Thanks. Have fun!
john
Success!
Had some issues with Hyperterminal but after I got that sorted it was all good. I didn’t have a temp sensor so I added in an LED instead. Pretty kewl being able to turn it on and off from the other side of the room.
Hooray!
It feels good, doesn’t it? I’m very happy for you – thanks for letting me know. (It’s great at this end to hear people are actually doing things)
Enjoy the rest of the weekend
regards
john
Question for you this time
When the XBee shield is on the Arduino, can I still use all the digital pins as normal or are some being used by the XBee?
I’m thinking of setting up a LED matrix using the TLC5940 and then controlling it over wireless with the XBee modules.
If I’m using XBee will I still have enough pins to control a TLC5940 (or 2, or 3) as well?
Hello
Excellent question. In our examples, we use the XBee on the TX/RX pins (digital D0 and D1), so you will be fine with a TLC5940 or 2 or 3. Don’t forget to allow for the current draw on your LED matrix etc.
Thanks John.
I’ll see what I can get working over the weekend, assuming parts arrive.
No worries. I hate waiting for parts!
cheers
john
Hmmm, I think I have ordered common cathode RGB LEDs. That’s not going to work with the TLC5940 is it, because it’s a current sink?
Yes you are correct.
You could use inverters to make it work.
Great post. I was looking to mess around with XBee and this will help a lot.
Hello
Thank you very much for your kind words. There will be more on Xbee in the near future, so please stay tuned.
cheers
john
[...] USB explorer board to connect a PC to an XBee (as we have done in Moving Forward with Arduino – Chapter Fourteen), but they are around Au$33. However I already have an FTDI USB cable, so all I really need is this [...]
Pingback by adafruit industries XBee adaptor kit review « adafruit industries blog | September 6, 2010 |
Many thanks! I was getting a little frustrated with my Xbee’s and your page help clear things up and put me back on track.
Hello Wes
Thank you very much for your comment. To hear that you have resumed your project really makes what I do all the more worthwhile – you’ve made my day!
Thank you
john
I hope this doesn’t come up as a duplicate, WordPress had a spasm there …
I looked on LBE and saw they had a 50mW XBee that has a range of 1.6km. Am I correct in thinking that I could use this unit at my remote device, and use a smaller (1mW) at my home, and still be able to read the data? I realise that, if this works, I can’t send to the remote device, but that’s cool.
Howdy Stu
Great question, but a bad answer I’m afraid. Even if you’re only wanting to send data one way, the receiver still needs to say “OK, got it” (etc) back to the transmitter module – over such a distance there will be a communication breakdown (good song…) So you will need both of them to be 50mW.
have fun
john
Ah, ok, fair enough. I thought it sounded too good to be true. I’ll just have to wait for another week or so before getting them.
I have a look at Google maps and saw just how far 1.6km from my house would be and got excited
That happens to me a lot … I have an idea, then get hit by the reality and have to start again. However every time I fail at something, it is a success in that something new is learned.
John
It’s also possible to program the XBee to read data off of its own IO pins and ADC without having to hook up an Arduino to it. You can free up a microcontroller that way!
Wow. Do you have a link for that?
thanks
john
Not to steal codeMonk’s thunder, but it was mentioned in a recent Hack a Day post:
http://hackaday.com/2010/12/14/garage-monitor-has-an-extra-arduino/
Excellent, thanks for that
john
Ladyada uses that functionality in the Tweet-a-watt here: http://www.ladyada.net/make/tweetawatt/config.html
Good call, good call Jamie =)
Hi,
I’m new to the arduino and the XBees, I got your example 14.1 working with out any problems but I can’t say the same with example 14.2. I can upload the sketch without any issues and communicate with the remote board, but I don’t have any communication between the XBees. Could you please help me?
Thanks
Lauren
Hello
It is hard to say without ‘being there’ so to speak. If you had example 14.1 working then that is a great start. This can sound silly, but rebuild the sensor circuit from scratch, checking the connections and wiring; make sure you aren’t trying to use them over too long a distance; check you have the UART/DLINE switch on the xbee shield set to UART, etc.
if you have any more questions please email me directly john at tronixstuff dot com
It’ s possibile to do this on a Mac?
Yes, you just need some terminal software such as Syncterm (http://syncterm.bbsdev.net/)
However I do not have access to a MacOS computer so cannot answer specific questions.
cheers
john
Hello John! Just getting started with XBee. I have configured my explorer module. Now, I have connected my shield to the Arduino UNO, so that the +5V,GND and D1 pins are connected to the corresponding ones on the shield. However, nothing seems to be happening. How can I diagnose? Many thanks in advance!
Actually just got it working
haha. Thanks!
I am getting a confusing result. I have terminal windows for both xbee modules but for the receiving module nothing is showing up and the temps are showing up in the terminal window for the transmitting module. However, if I type in the transmitting term window the results show up in the receving terminal window. I should also indicate that I am doing this without a xbee shield, making the connections directly via the breadboard.
Does your breadboard solution directly replace the Xbee shield (i.e. 3.3V, level shifting etc?) Here’s the schematic of the shield – http://www.sparkfun.com/datasheets/DevTools/Arduino/xbeeshield-v13.pdf
What happens if you don’t have the transmitter connected to a terminal window?
The positive 3.3V lead plugs into pin 1, the ardiino digital pin 0 (RX) plugs into the xbee RX pin 3, arduino dig pin 1 into the xbee TX pin 2, and the 3.3V ground into the xbee pin 10. If the transmitter does not have a terminal window running then I still see nothing.
Thanks
Try this – Arduino TX to XBee 3 and Arduino RX to XBee 2.
See http://www.sparkfun.com/datasheets/DevTools/Arduino/xbeeshield-v13.pdf
can you give upcomming tutorial on Series2 Xbee redios,,
that will be a great help
thanks
I don’t have any Series 2 XBees to write about them.
That did the trick. Thanks! Curious though the examples I have seen demo the connections with the TX connected to Xbee 2 and RX to Xbee 3.
A lot of people get TX and RX mixed up
Thanks! Will try to make it right this time.
thinking to go with series2 xbee radios, Is the case same?
can i follow same setup for series2?
I don’t have any Series 2 to test or check, so cannot accurately answer this for you.
hai sir,
i want to communicate between two xbees.
one should be connected to pc and the other to be with sensor and this 2′nd xbee should send the sensed data to the pc using the xbees.
can you please list out what all are required.
thanks in advance
This is demonstrated with example 14.2.
hello sir,
we are humble students with upcomming 5th year final project for our campus and we were wondering if there is any affordable xbee transciever that we can connect with an 8085 microcontroller which inturn will be connected to a pc. this pc will act as a central control to various xbees connected on remote locations (with in range), and it will compute all the sensed signals sent by all the remote xbees.
we would like to thank u for ur help
waiting humbly and eagerly for ur answers
NB we are studnets for an east african country collage
Hello
I am not familiar with the 8085 microcontrollers. However if they support serial I/O at 9600 bps you should be fine.
Dear John I am new with these devices. I am so interested to do the projects. I have a question. How about programing the adruino?? Do we have to define a protocol or something or xbee chips send and receive the data automatically?
Ali
All you need to do is shown in the tutorial, nothing extra to do.