Sunday, January 30, 2011

How Zigbee got its name

This question puzzles many of us, I've just found the answer in a very useful book called "Zigbee Wireless Networks" which I've just added to my Safari bookshelf.

Author Drew Gislason starts the book with this explanation:-

"Before I delve into ZigBee in detail, I'd like to address one question that seems to come up every time I speak about ZigBee in public. Where did the name ZigBee come from?

Well, the way I first heard it was at the ZigBee Open House in Seattle, back in 2004.

This story was told during a time when ZigBee was often confused with Bluetooth™. Just so you don't confuse the two: Bluetooth™ is great at point-to-point (as seen in many headsets and cell phones). ZigBee is great at wireless control, where anywhere from two to thousands of nodes are all connected together, in multi-hop mesh network.

Bob Heile, Chairman of the ZigBee Alliance explained the origin of ZigBee something like this:

A Norwegian legend speaks of a little troll by the name of ZigBee, who lived in the village of Vik far inland on the fjord of Sogn. Now, Norwegian trolls aren't the big, nasty and smelly, hard-as-rock variety often told of in other tales, at least not always. ZigBee was a kindly, quiet little troll, who didn't speak much, but when he did speak it was always reliable. A person could count on ZigBee.

One time, ZigBee sensed that a decomposing pile of hay stacked up against a barn had become too hot and had begun to smolder. ZigBee, in no time at all, sounded the alarm to every house in the village, and the villagers were able to put out the fire before the barn was lost.

Another day, a grandfather left the port of Vik i Sogn in his small fishing boat to catch Salmon with his granddaughter Brita. This day, unlike other days, Brita was not being careful. Bestefar (that is the name Norwegians give to their grandfathers) didn't notice when Brita fell overboard as he was busy hauling in a net full of fish off the stern of the little boat. ZigBee, sensing immediately that Brita had fallen, alerted Bestefar who was able to save her from drowning.

Yet another time ZigBee saved the whole village of Vik. And the way I heard it was this. A local villager by the name of Haarold Bluetooth, was far up in the snow-capped mountains, tending his flock of sheep in the early spring. It had been a warm spring that year, following a particularly hard winter.

The shepherd, Bluetooth, brought his flock to a stream he knew well, but this year he couldn't approach it. The steam had turned into a flooding river from the rapidly melting snow. Alarmed, Bluetooth now wished he could let the villagers know about the flood before it reached the village, but the village was too far away for him to be heard. Bluetooth simply didn't have the range to help the village.

ZigBee, sensing there was trouble, saw the flood as well. And ZigBee, like Bluetooth, realized he was too far away for a single shout to be heard. So he immediately began to hop down the mountain, ledge by ledge until he reached the village. He automatically opened the dam and the flood passed through without harm to the village.

It was a very lucky thing for Vik i Sogn that they had ZigBee, and that ZigBee knew how to multi-hop."

Sunday, January 23, 2011

Temperature monitoring, TMP36 (LM35), Arduino and Xbee Shield


Components for heating sensor network
I'm using an XBee mesh radio network and Arduino boards to measure the efficiency of the way we use our central heating system at home. We've done a similar thing with power consumption previously using an MQTT feed and graphs at http://www.taoma.co.uk to reduce power consumption by around 15% through better awareness of which behaviours in appliance use are most expensive - the next step is to do the same for natural gas use, which is rising in cost with every quarterly bill.

Initially I planned to measure gas consumption by fitting a modern meter I could read using an Arduino board or gas company web service. I may still go down this route, but since I don't know the sampling interval here, and since nearly all the gas is used by the central heating system, it looks easier just to identify when the boiler fires up and shuts down by putting a temperature sensor in the exhaust manifold. A quick test with a measuring probe indicates this reaches 147°C when the burner has been running for a few seconds. The LM35 temperature sensor conveniently reads to 150°C, which would be an ideal sensor package, however what I've got in stock are TMP36 ICs which read to around 124°C, so we'll have to cheat a little with the readings. The flue is at head hight at the back of the house, making it straightforward to mount a sensor in the exhaust gas flow.

The remainder of this post describes tools, the bill of materials, an overview of the project, and the steps required to build it.

Tools
* Stanley knife and cutting board
* Wire stripper
* Soldering iron and solder
* Glue gun
* Hack saw for cutting sensor mount
* Electric drill and 5mm drill bit for securing the sensor mount to the house

Bill of Materials (I'm in the UK, so some component suppliers are UK-specific)
* 2x XBee Series 2 mesh network devices (www.digi.com, coolcomponents)
* 2x ArduinoXBee v1.1 shields ( see the ArduinoXbee page at www.arduino.cc for an overview)
* 2x Arduino Duemilanove boards (coolcomponents or oomlout)
* 1x XBee Micro USB Explorer breakout board (www.sparkfun.com)
* 5x TMP36 temperature sensors from oomlout.com (www.tinyurl.com/lcwul5)
* 4 metres Cat-5 patch cable
* 2x Power supply (part 00569 at (coolcomponents)
* short length of threaded rod for sensor mount arm (hardware store)
* 4x cable ties to secure sensor to sensor mount arm (hardware store)
* 6x patch-cable sized cable clips, 5mm, to secure patch cable to the wall (hardware store)
* 2x Lock&Lock Arduino-sized plastic food containers to act as enclosures for boards. CoolComponents sells an ABS enclosure for the Arduino, but the ZigBee shield is just a bit too wide for this.

Project Overview

The wiring for the probe is CAT.5 patch cable, which given that it wraps eight wires, provides for six sensors (two of the wires are reserved for common +5v and GND, six are free for connection to the middle pin of each LM35 sensor at one end, and to analogue pins 0 to 5 on the Arduino Duemilanove board at the other).

The XBee Series 2 mesh radio chips are used because it's not convenient to connect the Arduino board measuring the sensor inputs to the Internet - it's in a fairly inaccessible position on the inside of the house in what used to be the kitchen larder, near an air brick that provides a convenient hole to thread the patch cable through. So the sensor unit board has an on-board ArduinoXBee v1.1 shield mounted on it, with a XBee transmitter/receiver configured in "ROUTER/END DEVICE AT" firmware mode. The sensor unit board is responsible for polling each sensor, smoothing out readings, and sending network packets to the remote Monitor Unit board.

The Monitor Unit board is connected via a USB cable to the low-power 8-watt Ubuntu PC in the workshop that monitors power consumption and handles home automation. The Monitor Unit is another Arduino with an ArduinoXBee v1.1 shield and XBee configured in "COORDINATOR AT" firmware mode. This establishes the mesh radio network, and receives messages from the sensor board, which is physically located about 15 metres away and on the floor above the workshop. The USB cable powers the board and interfaces it to the PC using the Arduino Serial library, so that messages from the remote sensor board can be processed, logged in an RRD database , and sent over the Internet using MQTT.

Step by Step
1. Attach sensors at various points on the patch cable after establishing a colour coding convention for each wire - I used blue for Ground, orange for +5v, and green for the signal from the flue sensor, sensor 0. Then it's blue/white for sensor 1 (outside the house for ambient outside temperature), green/white for sensor 2 (zone A), orange/white for sensor 3 (zone B), and brown for sensor 4 (zone C). Tin the ends of the wires; you could solder each wire to header pins at this stage for easy insertion into the sensor board but consider how you're going to thread the cable through the building first.
2. Set the XBee firmware for the sensor board to ROUTER/AT END DEVICE using X-CTU on a Windows PC with the radio chip mounted on the Sparkfun Explorer board; make sure you set the PAN identifier to a number unique to your new network (I chose "254").
3. Set the XBee firmware for the monitor board to "COORDINATOR AT" and set the PAN identifier to match the ID chosen for the other XBee.
3. With the sensor Arduino board disconnected from the XBee Shield, download code to read each sensor ,average the values, and print them using the Serial library with a delay of 1000 milliseconds between each set of readings. Example source for monitoring temperature and writing values to the serial port (which the ZigBee relays data from) is available from a number of helpful Arduino suppliers. I chose to start with http://oomlout.com/TMP36/TMP36-Guide.pdf, which contains a link to an easily adapted source code listing.
4. Attach the XBee shield and ROUTER/AT END DEVICE XBee chip to the Arduino sensor board, connect it to your computer, and use the Arduino IDE Serial Monitor function to check for messages from the sensor program running on the Arduino.
5. I'm working out the details of the monitor board software as I write this, update due when I've cracked it.


Labels: