ZigBee/XBee Garage Door Opener

by February 23, 2012 10:47 AM

I mentioned in my last post that I have three xbee radios that need to be used (played with!) and that we only have one garage door opener between the two of us - I am not the keeper of said opener. Here I present version one of our new networked garage door opener!

The Old Garage Door Switch

Garage Door Opener

The black box you see with the duck tape is a keyless entry system that was here when we bought the house. I'm the only one who used it (being the one without a remote) so I decided to unplug it and steal the wires that run from the garage door opener. The wires are already run and it's conveniently near a wall outlet so it seemed the right thing to do.

In case you don't know (I didn't at first), the wires that run from your garage door opener (the real one attached to the door) to your standard wall switch works by merely closing the circuit between the two wires temporarily. So your wall switch is just a mechanical switch with two electrical contacts that, when the button is pushed, close the circuit. Releasing the button re-opens the circuit, or breaks the connection between the two wires.

With the knowledge of just how simple it is to activate a garage door opener, all I needed was a way to electronically close the circuit between the two wires. That is exactly what a relay is for.

The XBee Garage Door Switch


What this is, is the remote temperature sensor I had already created plus one additional component (and a few wires).

So the stuff at the bottom of the breadboard is still the power management componentry. It takes the 9 volts coming in from the power supply and regulates it down to exactly 3.3 volts for the xbee. Plus a couple of capacitors to smooth out the current.

Above that is the temperature sensor (tiny black thing) and a few resistors used to get the sensor's reading down to a level the xbee can read. And then there's the xbee itself with the temperature sensor still connected to AD0 (pin 20).

The new piece is the light blue component at the very top. That is a Compact 5VDC/1A SPST Reed Relay. I just connected the two wires from the garage door opener to each side of the relay and then ran a wire from AD1 (pin 19) on the xbee through the relay to ground. To trigger the relay, I just have to turn on AD1. So recalling what I said about the garage door switch, I just turn on the pin, closing the circuit with the relay, and then turn it right back off to re-open the circuit. Just like pushing a button switch :)

Tying Everything Together


I left the temperature sensor on the circuit and I left the xbee configured exactly as-is. This means the console app that I used before still works like a champ. I connected the coordinator xbee to my PC, plugged in the above breadboard, ran the application, and I immediately started getting temperature readings from my garage. All I needed then was to be able to send a command to the remote xbee telling it turn on AD1 and then again to turn it back off.

Digi made this really easy with the xbee API. All I need to do is send it a remote AT command configuring AD1. Specifically, I send a Remote AT Command Request to the address of the remote xbee passing the AT command D1 (configure analog/digital pin 1) with the parameter of 5 to turn on high digital output (3.3 volts). I sleep for half a second and then send the same command again with a parameter of 0 turning the pin back off.

Of course, I needed a way to tell my console application to send those commands. For now I just listen for incoming connections on a named pipe. I created a single ASPX page sitting on my local IIS that, on button click, would open a connection to that named pipe and send it the message "Garage Door". The console app triggers the garage door every time it gets this message.  Sweet!

To get to that from my phone, I opened up HTTP traffic in my firewall to private network traffic and gave my PC a static IP address. So as soon as my phone connects to my wireless router, I can open and close the door with my phone. In fact, anyone who knows the password to my router and knows the IP address of my PC can now open and close the door. Unlimited remotes!!

Awesome, But Not Finished Yet

So now everyone who has access to my router can open and close the garage door. That's cool and all, but I'm not done yet. There are several things I don't like about the situation...

First, I want to be able to tell whether or not the door is currently open. No brainer! Not cool if the opening and closing is automated, but I still have to leave my lazy boy to see whether or not I need to close it at the end of the day.

Next, having a breadboard and exposed components dangling on the wall of my garage isn't cool. It's also not good for the circuit being exposed to dust and whatnot. Mostly it isn't cool though.

More importantly are the implementation details. Currently everything is had coded in a very brittle way. First I assume that any message received at the coordinator is going to be a temperature reading on AD0. Second is the garage door opener. Its address is hard coded to that exact xbee module. The pin is hard coded to AD1. And finally, I'm using named pipes to communicate with a console application from a .net application.

Oh, and I'm not logging the temperature readings, so no cool graphs. Not that there would be many readings coming in yet. Still have to solve the cost problem of creating dozens or remote sensors.

I'm definitely excited about what I have so far. And excited about the fact that I can open and close the door from my truck of course. But I have a lot of work (can I even call it that?) ahead of me.

Tags: , ,

ZigBee Simple Sensor Network Part 2 - Never Mind

by February 18, 2012 04:06 AM

In my last post I left off with saying that I planned to continue in the book with the second piece of the Simple Sensor Network project - switching the remote sensors to end devices and using batteries instead of the 9v plugs. I also thought I'd create my own PCB instead of using the breadboards. Didn't happen...

I really dig the idea of having one of these temperature sensors in literally every room in the house. Maybe one out front and one out back as well. I can picture having rich graphs showing me the temperature rise and fall from all around my house. Ideally all of the internal sensors would rise and fall in sync as the central air kicks on and off. If one of the rooms fell lower in the winter or rose higher in the summer in between heating/cooling cycles, that would tell me that particular room isn't insulated as well as the rest. Or it would tell me someone left a window cracked, or a varmint decided to make their own entry. All good information to have and at the very least I'd have those cool graphs to show off to oldsters who visit :)

The problem with the XBee-based sensor though, is the cost. The radio itself is roughly $20 and then there are the rest of the components. So we're talking close to 30 bucks per sensor. Not cool if I want to buy more than a dozen (every room - not just bedrooms, outside, attic, etc.). If I plan to implement this idea of a zigbee network of temperature sensors, I need to find a much cheaper solution for end devices.

So I'm done with the book Building Wireless Sensor Networks. Even though I don't think I'll continue using xbee radios everywhere, I am so glad I got the book. It has introduced me to all sorts of fun and coolness that I've never played with before. And I can see using those radios in spots (like the controller or more extravagant devices that use more of the module's functionality), so I'm sure it will be a great reference in the future. It's an excellent addition to my library.

What's Next

I am left with the three xbee radios I've already purchased. I was thinking about what I might do with them as I was leaving to take the kids to school the other morning. As I pulled out of the garage and lamented once again that I still haven't gotten a second remote for the door (the wife has our one remote in her car of course), the idea of creating my own formed. I've read of others doing it with arduinos and netduinos so there's plenty out there on the subject. My next post will show how I accomplished it with a couple of my left over xbee radios. Good times!

Tags: , ,

ZigBee Simple Sensor Network

by January 30, 2012 04:40 AM

This is the project I mentioned in Configuring My First XBee Radios where I'm going to setup the sensor network from chapter 5 in Building Wireless Sensor Networks. I'm going to end up with two remote temperature sensors that are mesh-networked together to stream their data to a base station radio connected to my PC.

Preparing the radios


This is a simple matter of connecting to the xbee with X-CTU and switching its mode from AT to API (along with ATAP = 2). I also went ahead and zeroed out ATDH and ATDL since the coordinator will be receiving data only.


These stay in AT mode, but need the following settings:

  • ATID - set to the same PAN ID as the coordinator
  • ATDH - 0 (forces the radio to use 16-bit addressing)
  • ATDL - 0 (destination is the coordinator for both routers)
  • ATJV - 1 (rejoin network on restart)
  • ATD0 - 2 (puts pin 0 in analog mode)
  • ATIR - 3E8 (sample rate of 1,000 milliseconds - polls for the temperature once a second)

Something that might be worth noting here. When I first unplugged the coordinator and plugged in the first router, my computer's USB completely stopped working. Yep, I lost both my mouse and keyboard and no amount of unplugging and plugging them in helped. I tried every USB port on my computer. I eventually had to do a hard restart (and luckily only lost a little progress on this post - I save often). I did notice I had left X-CTU running when I did the switch. This time I closed X-CTU in between configuring the two routers and everything worked fine. Don't know for sure if that was the problem since I don't care to reproduce it, but wanted to put it out there just in case you run into the same thing.

Preparing the sensor boards

Sensor Board

This was an experience for me. It seems like I have a vague memory of having soldered before, but we might as well say I've never done it. I'm proud to say I finished with only one burn (right index finger). The solder jobs themselves look horrible.

Working with all the parts was interesting as well (transistors, resistors, etc.). Very neat and I'd say rather satisfying when the end product is a physical thing instead of software. Good times!

This is a picture of the first one I put together (the second looks identical). The little black thing poking up right below (in the picture) the XBee is the actual temperature sensor. The mess of stuff near the bottom is the voltage regulator (from 9-volt to 3.3-volt) and the capacitors (to get rid of noise in the power supply). Prototyping on those breadboards is super easy.

Capturing the sensor data

The book actually supplies a program ready to use that will allow you to visually see on your computer all the data being sent from your remote sensors. It's a Processing program that uses some Java libraries to communicate with the XBee radio over the COM port. I could have used that I suppose...

Sensor Network App

Being the developer that I am though, I wrote my own in .net. I put the code out on github in a project called XBee (real stretch for a project name, I know). You can see the library I wrote along with the project specific to this example at https://github.com/rtennys/XBee. The format of the messages sent from the XBee radios in API mode are very easy to work with. It was a fun little exercise for sure.

What's Next

I think I'm going to do two things next. I'm going to kind of stick with the book moving on to creating temperature sensors that are configured as end devices instead of routers. This allows them to be much more conservative on the energy they consume thus allowing me to use a battery power supply instead of having to plug them in. In addition to what the book shows though, I'm going to create my own PCB instead of using the breadboard.

Tags: , ,

Configuring My First XBee Radios

by January 25, 2012 05:36 AM

XBee Radios

These are my first three XBee radios. Two of them are already connected to SparkFun XBee Explorers and the one in the middle is tagged with a note to remind me which one is configured as the coordinator (I did the connecting and tagging of course - they don't come like that).

If you don't know already, a ZigBee network consists of exactly one coordinator and any number of routers and end devices. Get the book or read about it on Wikipedia if you want the full story - my aim isn't to reveal everything the book has to offer, but rather document my personal journey into embedded devices.


The first step according to the book is to use a program called X-CTU (free from Digi) to ensure the firmware is up to date. So one at a time, I used the xbee explorer to connect the radios to my computer via USB. All three were already configured with the latest firmware so that was easy.

Time to configure and do the first test

X-CTU Configuration

The next step is to choose a terminal program that I can use to connect to the radios and issue AT commands to configure them. Since Windows no longer ships with a terminal program, I chose to just use the terminal tab in X-CTU. The author suggested picking a stand alone terminal program for various good reasons, but I just wanted to get to the good stuff.

The idea for the initial configuration and test is to set up two of the radios such that they can talk to each other wirelessly. This means putting both radios on the same network, or setting the PAN address (PAN = Personal Area Network), and then setting each radio's destination address as the other radio. The PAN is a number between 0 and 0xFFFF that you arbitrarily pick. A radio's address however is globally unique and printed directly on the xbee (or you can type ATSH/ATSL to get the high and low parts of the address from within the terminal program).

In the image you can see my configuration for the coordinator. I had already configured the router (using the information from ATSH and ATSL in the screenshot). The "+++" is how you enter into command mode where you can issue AT commands. Outside of that everything you type is sent directly to the radio and transmitted wirelessly. Notice how I had to type ATDL twice? That's because I took too long between issuing the ATDH command and issuing the first ATDL command. Basically the radio times out after 10 seconds and returns to transparent mode where it transmits everything typed instead of looking for commands. I knew it had timed out on me when it didn't return the red "OK". So I typed "+++" again and then reissued the ATDL command followed by the ATWR command to save the configuration permanently.

After that I waited until it timed out and then typed that last line. And sure enough, when I turned around and looked at my laptop (where the router was plugged in), there was the sentence that I had typed on my PC. Super basic and easy but still very cool!

What's Next

Like I said in my first post, I've already devoured the book. Instead of following along in order, I'm going to skip the doorbell and romantic lighting projects and jump to something I find more interesting: Simple Sensor Network (remote temperature sensors). I currently have three radios, so I'll have one connected to my PC as the coordinator and will put the other two at various points around the house. Exciting stuff!

Tags: , , ,

Building Wireless Sensor Networks

by January 24, 2012 06:51 AM

Building Wireless Sensor NetworksI decided to dip my toes in an area where I have no experience: embedded systems development. Basically, I want to create real, physical things that I can point to, hold, hand to a family member, and maybe even sell.

I can't remember exactly why I picked Building Wireless Sensor Networks to get me started on this adventure. I believe I was reading a review of some other book where the individual said something about not particularly getting much out of the book and suggested this one because we'll get the same content plus so much more (working with the radios). I assumed I would get something .NET related so I could stay within my comfort zone, but at some point I pushed Buy and the deed was done.

I'm glad I did, because it has opened up excitement that I haven't felt in a long time. When the book first arrived I devoured it. As soon as I knew the parts I needed, I ordered a slew of components and tools and have since spent hours and hours reading about everything from home automation to hobbyist robotics nuts. All very cool and I couldn't wait to get started.

The Plan

I thought I'd try to document this journey. As anyone who blogs knows, having to write down your thoughts forces clarity like nothing else. Also, I hinted above about creating something I can sell as a product. I want to capture what I learn about that process because the little I've looked into it so far hasn't been very helpful. In fact, I have no freaking idea how I'm going to go from playground to my first sale. Maybe what I figure out will help someone else.

The Book

Building Wireless Sensor Networks is about just that - building networks of "sensors", or devices with sensors connected to them, that communicate with each other wirelessly. The networking part of the equation uses the ZigBee protocol, and the wireless components the author focuses on are XBee radios. The examples that require a microcontroller use the Arduino. In addition to the specific "how to" sections, I personally think the author did an excellent job of explaining just enough theory and the "why" of things to satisfy my curiosity without putting me to sleep with too much information. Even where I needed more, he explained it well enough for me to google intelligently and get all the detail I could possibly want.

What's Next

I'm going to use this post as a table of contents for this journey so I'll keep it updated with links to each related post. The very next step is to configure my first XBee radios (they're in!). Stay tuned...

  1. Configuring My First XBee Radios
  2. ZigBee Simple Sensor Network
  3. ZigBee Simple Sensor Network Part 2 - Never Mind (end of series)

Tags: , , ,