Skip to content

Look, no Arduino – XBee ZB Series 2.x Digital Input

IMG_0350In preparation for my next project (an XBEE powered rain gauge) I have been investigating how to collect sensor data with just Digi XBee modules. So far all my sensor projects have used an Arduino to collect data then use either WiFi or XBee to send the data to my server for processing. It turns out that the XBee modules have 12 digital input/output and 4 analog input pins that can be used directly. For basic sensor projects it should be possible to use an XBee to collect sensor data without the need for an additional micro-controller such as the Arduino.

There is plenty of information on the web about using digital IO with Series 1 XBee, but I have the Series 2.x ZB modules. Digital IO works quite differently on Series 2.x than to Series 1, so I thought I’d share how I got a basic setup working.

For this setup I used:

Setup X-CTU and FTDI drivers
Both XBees are going to need upgrading and extra configuration. For this you need to have Digi’s X-CTU software running on a Windows PC. I have the XBee connected to the PC a the Sparkfun Explorer USB.

If you haven’t used the Explorer with X-CTU before you will first need to install the FTDI Serial USB driver on your PC. Download and unzip the driver archive from here to a temporary directory. The drivers don’t have an installer. Carefully plug an XBee module into the Explorer USB (make sure you get it the right way round) and plug that into a free USB port on the PC. Windows will probably complain it can’t find an appropriate driver. Open Windows’ Device Manager and look for a USB device with a yellow exclamation mark. Right click the device and update the driver, choose the directory where you unzipped the archive when prompted for a driver location. I had to repeat this a couple of times to get rid of all the exclamation marks.

Download and install X-CTU from Digi’s web site. It does have a regular installer so installation is straightforward. After installation has finished, run X-CTU and you should see the USB port with your XBee Explorer listed. Select that port and click the test button to ensure everything is configured OK.

Upgrade XBee firmware
By default, XBees come with the Router firmware installed. On both my Xbees the firmware version pre-installed was not the latest version so I updated both. One module needs to be configured as a Coordinator. For digital IO to work, the Coordinator must use the API version of the firmware. The other module I just upgraded to the latest Router AT firmware.

Configure the Sensor XBee (with Router firmware)
Although you can use the XBee’s command mode and AT commands to configure the module, it is much easier to configure the module using X-CTU.

x-ctu configSet the following XBee module parameters:

  • PAN ID (under Networking)
    This identifies the network to use. If you don’t set this, the modules are supposed to negotiate a common PAN ID but I haven’t had much luck with that. I find it simpler to just choose a number a set all XBees to that number.
  • DH and DL (under Addressing)
    This is the destination address where this module will send all its data. Each module has a unique number which is made up of a high and a low value. As a convinience the Coordinator can also be addressed as 0/0, so make sure both DH and DL is 0 (zero).
  • D0 (under I/O Settings)
    Setting this to 3 enable the D0 input pin for Digital Input.
  • Digital IO Change Detection (under I/O Settings, I/O Sampling)
    Using Change Detection means that the XBee will send a message to the DH+DL (i.e. the Coordinator in our case) whenever the reading at the pin changes. This setting is a bit field, where each bit represents an individual pin, that allows you to enable Change Detection on specific pins. I’m lazy so I just enabled it on all pins by setting it to FFFF 🙂

Configure the Server XBee (with Coordinator firmware)
The only configuration change I had to make to the Coordinator was set the Pan ID to be the same as the Router XBee.

Prepare the Explorer (Regulated)
In theory I could just connect a few wires to an XBee to make this work, but the break out board has a few benefits. Firstly it means I can swap an XBee in or out of this project without breaking anything. Secondly the break out board has a built in 3.3v voltage regulator so I will have more options for powering the project later. It also has a few status LEDs so I can see what’s going on. To use the break out board with a breadboard you need to solder on some pin headers. I decided to put two full strips of pins on mine just give me a few more options for experimentation.

IMG_0357 IMG_0355

Build the circuit
With the extra pins soldered to the Explorer it’s simple enough to build a simple test circuit on a breadboard. The diagram below shows the layout on the breadboard but with out the XBee fitted so its easier to see the wires.

XBee Sensor schematicXBee Sensor breadboard


There are four connections to the Explorer; 5V, 3.3V, Gnd and D0. The regulated 3.3V is used to drive the switch circuit. Never, ever put more than 3.3V directly into an XBee (thanks go to N8 for pointing this article out). D0 is connected to the switch circuit between the LED and the resistor. The resistor will pull the pin LOW when the switch is not being pressed.

Power Up and Test
All that remains is to power everything up and test it. Ensure that the Coordinator module is in the XBee Explorer USB and connected to the PC and that the Router module is in the Explorer (Regulated) on the breadboard. X-CTU should be running on the PC and the Terminal tab selected. Connect a power supply to the breadboard and you should see the power LED light up on the Explorer. When you press the switch you should see the RSS LED light on both the Regulator’s and Coordinator’s Explorers, and you should see the received data displayed in X-CTU. When you release the switch you should see another message in X-CTU. After a short while of inactivity the RSS lights should go out to show that the modules have disconnected.


Interpreting the Data
X-CTU displays the complete API frame as received by the Coordinator. The message starts with a delimiter byte, 0x7E. The next 14 bytes are header information that mostly describe message length, 64bit and 16bit message sender addresses. The next 6 bytes are what interest us. I have laid them out in a table below and provided values for when the switch is down (pressed) and up (released).

Bytes Name Notes Switch Down Switch Up
1 Sample Sets Samples in packet, always 1 0x01 0x01
2 Digital channel mask Which digital inputs have sampling enabled 0x00 0x01 0x00 0x01
1 Analog channel mask Which analog inputs have sampling enabled 0x00 0x00
2 Digital IO data Actual data values 0x00 0x01 0x00 0x00

The final byte is a checksum byte to help verify message integrity.

Next step is to see how the Java XBee-API handles these messages and update my Apache Camel component appropriately.

Useful Links

Posted in Internet of Things.

Tagged with , , , .

26 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. N8 says

    Is the LED to provide a ~2.0V voltage drop so the voltage that arrives at the DI is ~3.0V instead of 5V? Or was that just just an unintended outcome?

    • martin says

      I hadn’t considered the drop from from 5V to 3V, it was just there to give a visual indication that something was happening.

  2. N8 says

    Ha, I guess just dumb luck then. It’ not clear if you had skipped the LED and you pumped 5V into XBee DI pins expecting 3.3V if you would have done some damage.

    BTW: Much thanks for writing this up, the information about the API frame gave me a big head start on a remote control project that I am working on.

  3. N8 says

    According to DigiKey, you should not apply more than 3.3V to any input : , so yeah dumb luck 😉

    • martin says

      N8, you are absolutely right. I was using a variable power supply and it turns out I had it set at 3.3V instead of 5V, hence no damage. I will update the diagrams to use of the regulated 3.3V output into the switch.

    • martin says

      N8, I have updated my post to correctly show no more than 3.3V being applied to D0. Many thanks for the feedback!

  4. developpef says

    Awesome!! You just saved my weekend!! Since more than 2 days I was looking for a simple explanation of standalone Xbee confiduration… Nowhere it is indicated that with Coordinator and Router, router DH+DL can only be set to 0… You are my god 🙂

  5. avinash says

    my thing is not working. Please help me out. I have exactly the same XBee module (S2). Does ATMY id matter? What could possibly going wrong with me? Can u please tell me in detail about the configuration of the coordinator.

    • martin says

      As I said in my blog, the only parameter I had to change on the coordinator was the PAN ID. I recommend re-flashing the firmware to the latest, which should also reset everything to defaults, and then just setting the PAN ID.

  6. eyad says

    in your project you transferred the digital input pin status of the router to the coordinator then read it through x-ctu , my question is can you directly transfer the digital input on the router digital input pin directly to a digital output pin of the coordinator ?

    • martin says

      I don’t believe so, not without a micro-controller or another computer connected to the coordinator to parse the message from the router. Maybe that Series 1 XBee have this feature.

  7. Johann Uys says


    I have tried everything you said must be done but there is no ways I can get a Xbee to talk from input an A to output on B.
    I can get two computers to talk to one another with the very same Xbee’s.
    Please help my I have tried everything.
    What am I doing wrong.



    • martin says

      Johann, that’s not how I am using the S2 XBee’s. The receiving XBee (the coordinator) is being accessed through external software via the API. I think the S1 XBee’s might support what you are expecting. If you monitor the receiver using the X-CTU software you should see data messages being received.

      • Johann Uys says

        Martin, Please be so kind as to post me your complete and total setup for S2 Xbee as I also have some of them. If possible line for linefor X-CTU. I have been battling for the past week with this. I also find that for some obscure reason I can not talk to some of the units after a while. I am even trying to reset these units manually ie. Reset (Pin5) to Gnd. I am beginning to think that Xbee is not very reliable. I have used the above units in projects for some time. If you can help I will be very thankful. Johann

        • martin says

          Everything I did is detailed in this blog post. Nothing else I can add.

      • Johann Uys says

        Martin, Another problem, why when I do a Test Query I only get an answer on the second try and NOT on the first attempt. Johann

        • martin says

          Which firmware are you using? Sounds like the XBee may be entering sleep mode. I have found my XBee’s to be 100% reliable for many months.

  8. Jee Won Kim says

    Hello, thanks for post.
    Xbee Series 1 radio can do direct Input/Output function without microcontroller?
    If yes, only digital for now? I heard that the latest firmware can now support analog output for Xbees but I am not sure if that refers to only Xbee Series 2 (Zigbee)

    • martin says

      I don’t have series 1 XBee so I can not say.

  9. phyllicia says

    I would like to ask how you qualify the test of the XBee Sensor and the accuracy?
    Any Certificate of Conformance for these sensors?

    • martin says

      In my set up the XBee isn’t the sensor, it’s the communications mechanism. The accuracy of any sensor you connect to the XBee would have to be separately verified as suitable for the application for which it is being used.

  10. Camilo says

    I was looking for an example like this to xbee s2, but only found for s1, thanks.
    Can you do the same for an analog signal (without microcontroller)? Is enough to set analog input to enable DIO ? or should I make other changes? Is it true, that the analog input must not exceed 1.2V? Thank you.

  11. Sam says

    Hello martin I want to transmit 4 bit [D0-D3 of xbee s2(pin 17-20)] data form coordinator xbee s2 to router xbee s2 (or form router xbee s2 to router xbee s2)..
    So plzz help me.
    how to do this configure.
    i don’t able to buy s1 now… so plz reply as soon as possible…..

  12. Morgan says

    Hello Martin
    Thanks a lot for your examples … I am actualli having trouble to find examples of Only-Xbee (no-arduino) kind of projects …
    the truth is really i have like million questions but i will try to keep it simple ….
    have you tried or have some examples with XBee Pro S3B ??
    is too different drom S2 ???

    other … have you any example code for the procesor inside the xBee Pro S3B ??
    anything to turn it on or turn it sleep remotely ??
    thanks !!!

Some HTML is OK

or, reply to this post via trackback.

%d bloggers like this: