28 April 2011

A "Minimal" Arduino/XBee/Pachube Sensor Network

One or two people have asked in online forums for code from my sensor network, and while I'm usually happy to share, it's full of a lot of extraneous stuff (RTCs, NTP, displays, thermocouples) that might not be of interest to everyone, but more importantly, that probably only obscures the fundamentals of XBee networking and communicating with Pachube.

So with that in mind, I cut out the extraneous stuff, and just left the bare essentials: A remote sensor unit which transmits a single reading from a photocell once per minute to a base unit which connects to the internet and forwards the data on to Pachube.

Bill of materials -- Base unit:
(1) Arduino Uno, Through-hole or SMD edition
(1) Arduino Ethernet shield
(1) XBee ZB low power Zigbee Module, Digi Product ID XB24-Z7CIT-004, XB24-Z7WIT-004, XB24-Z7SIT-004, or XB24-Z7UIT-004 (these differ only in the antenna, they are functionally equivalent)
(1) Adafruit Industries XBee Adapter
(1) LED for heartbeat (optional)
(1) 330-ohm resistor for heartbeat LED (optional)

XBee configuration:
  • Load the Zigbee Coordinator API firmware (I'm using Version 2170).
  • Set the PAN ID as desired, to match that of the sensor unit(s).
  • Set API mode 2 (AP=2).
  • Set baud rate to 9600.

Bill of materials -- Remote unit:
(1) Arduino Uno or similar (Through-hole, SMD edition, Boarduino, etc.)
(1) XBee ZB low power Zigbee Module, Digi Product ID XB24-Z7CIT-004, XB24-Z7WIT-004, XB24-Z7SIT-004, or XB24-Z7UIT-004.
(1) Adafruit Industries XBee Adapter
(1) CdS photocell
(1) 10K resistor

XBee configuration is same as above, except:
  • Load the Zigbee Router API firmware (I'm using Version 2370).

Here are the sketches.  Unzip into the Arduino Sketchbook folder.  Before uploading, be sure to disconnect the XBee from Arduino pin 0.  Also be sure to enter your MAC, IP, and Pachube API key in the base station main module, and your Pachube feed number and the address of your network coordinator XBee in the main module for the remote unit.

Here is the Pachube feed. Pretty boring, but at least you can see that it does work. Not sure how long I'll leave it running, probably until I need the parts for something else!  Feedback and questions welcome!

Note that in the following wiring diagrams, the XBees plug into the Adafruit adapter, which in turn plugs into the breadboard. The XBee pins do not (in fact, cannot, spacing is different) connect to the breadboard.  The adapter plugs into the breadboard, this is represented by the 10-pin header below the XBee.

Wiring the base unit



Wiring the remote unit

My base unit

My remote unit (using a Boarduino)

18 comments:

  1. It was pointed out to me that the remote sensor unit could be implemented with only an XBee, i.e. without a microcontroller. That is certainly true. The XBee has the ability to take an analog signal, such as from the photocell, and transmit it periodically. However, my intent was to show the more general case where the sensor may require a more intelligent interface. I only chose a photocell because it was simple and common, and because folks could easily replace it with a potentiometer or even with a switch if they wanted to implement this simple demonstration.

    ReplyDelete
  2. Great post and very helpful.
    Could you provide more details around the xbee setup:
    - which tool did you use. I am using X-CTU
    - did you only configure the 4 paramaters ( PAN ID, firmware, API mode and baud rate )?

    and more importantly, thanks for this procedure.

    ReplyDelete
  3. Hi, thanks for your comment! I do use X-CTU to configure the XBees, and an Adafruit "FTDI Friend" to connect to them. Those are the only parameters that should be needed. Many times I'll also set the Node Identifier (NI) but it's not required by this example. I've just recently been using the newer 2x8C firmware, so far it seems to work fine. Hope this helps!

    ReplyDelete
  4. for whatever reason, the xbees would not talk in API mode...but only with the AT firmware...any clue or idea as to how troubleshoot welcome :)

    ReplyDelete
  5. That seems odd, not sure off the top what would cause that. Glad to help troubleshoot, would you mind posting an item on the Arduino forum? http://arduino.cc/forum/ ... It's a better place than here to troubleshoot, there's a networking section with a lot of chat about XBees, suggest posting there. If it turns out that I can't help you there's lots of other folks there too. Please include all the details that you can.

    ReplyDelete
  6. In case, anyone has the problem, I had to tweak the remote arduino code so that the coordinator address should be set to all 0's. I think hat should be the default value unless you configure specifically the addressing in X-CTU.

    ReplyDelete
  7. It will work with zeros, or the coordinator's actual address can be used. The latter requires less network discovery overhead, but I haven't noticed that using all zeroes slows anything down. I have some newer versions of the code that I need to finalize and git up to github, and I've been using all zeroes lately as well.

    ReplyDelete
  8. Oh, and configuring the destination address (DH, DL) only applies to AT mode. With API mode, the destination address is part of the packet.

    ReplyDelete
  9. hi, thanks for the post.

    could you talk us about how would have to be if we would want to make a XBee only remote sensor, as an end device? i've been surfing internet and i can´t find a clear example for non-electronic people.

    thanks in advance

    ReplyDelete
  10. I haven't actually played with end devices yet, but I do have a couple ideas for using them. Good topic for a future post! In the meantime, I recommend Robert Faludi's book, http://www.amazon.com/Building-Wireless-Sensor-Networks-Processing/dp/0596807732/

    ReplyDelete
  11. The arduino is beneficial for those user who working on projects because it is less expensive chip system and easy to made device board.
    Jaycon

    ReplyDelete
  12. Hi, do you have the code for the Arduino available? Or send it to my mail.

    ReplyDelete
    Replies
    1. The code is on github, there is a link at the beginning of the third to last paragraph.

      Delete
  13. Hi, I have some problem compiling your files in Arduino. First it do not find Xbee.h. And a whole lot of other xbee variables and parameters.

    Do you have some helping tips. If there is something that I am doing wrong...

    thanks

    ReplyDelete
  14. Sounds like you need to install the XBee library. Follow the link in the comment on the #include statement:

    #include //http://code.google.com/p/xbee-arduino/

    ReplyDelete
  15. Can you use Series 1 Xbees in this configurations? Are the Zigbee firmware configs required?

    Thanks in advance!

    ReplyDelete
    Replies
    1. Not as it stands. It's probably possible to adapt it though.

      Delete
  16. Nice post. However, there are other alternatives to Xbee nowadays. Some of them are even arduinos themselves, and much more compact than the arduino+shield+xbee set. Ex: http://www.panstamp.com/wirelessarduino

    (Sorry, I'm a bit biased ;))

    ReplyDelete