Moving Forward with Arduino – Chapter 14 – XBee introduction

Learn how to use XBee wireless data transceivers with Arduino. 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.

Updated 02/03/2013

We will examine the Series 1 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. In this tutorial we’re using Series One XBees.

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:

xbeeretailpackopenedsmall

This bundle includes two Xbee modules, an Xbee shield to connect one of the modules to an Arduino 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:

solder2s

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:

shieldswitchss

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.

acusbss

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:

numbers

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. Next, we’ll 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:

exam14p2boardss

… and the schematic:

exam14p2schemss

 

It never hurts to elevate your other Xbee:

xbeewallss

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.

LEDborder

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, 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.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

10 Responses to “Moving Forward with Arduino – Chapter 14 – XBee introduction”

  1. Stephen Holt says:

    Hello,

    Does this article apply to Series 1 or Series 2 xBees , or doesn’t it matter ?

  2. steve56 says:

    I bought the xBee Wireless retail kit from Little Bird electronics and I was amazed how easy it was for a novice like me to get it up and running.

    Thanks for the great tutorials John, are there any more xBee chapters planned ?

  3. DEEPANKAR says:

    i connected two xbee with two arduino. made one receiver and other one transmitter. i transmit a character with one xbee and receive it using other, the xbee do it correctly 3 or 5 times then it takes delay.
    pls give a suggetion for solving this problem

  4. A. Gafri says:

    I want to transfer analog signal from 3 or 4 different types of sensors to a computer and i want to see the analog signal on it, can I use the arduino to do that. In addition, how many arduinos do i need to do that.

    • John Boxall says:

      Sure, but depends on the signal you’re measuring. An Arduino can measure up to six 0~5V signals at once with 8-bit resolution. Then it can feed the data back to the PC and you can display it with a processing sketch. A simpler option would be to use a four-channel PC-based oscilloscope.

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: