O'Reilly logo

Building Wireless Sensor Networks by Robert Faludi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required


Building Wireless Sensor Networks is an essential guide for anyone interested in wireless communications for sensor networks, home networking, or device hacking. It is a first step in becoming proficient in making these systems. It is not a textbook on protocols or a complete guide to networking theory. No engineering or computer science background is expected or required. Those who have fooled around a bit with electronics or programming will certainly have a leg up, but in general, this book is aimed at hobbyists, students, makers, hardware hackers, designers, artists, and prototypers. In the chapters to come, you will scaffold your way up toward greater comfort and proficiency with hardware, software, radio, and communications. I’ll explain everything necessary to get started, at least briefly. We’ll create examples using accessible environments, such as Arduino for hardware and Processing for displays. And I’ll provide a full range of resources, including helpful references to outside works for the electronics and networking novice. Whether you are a young inventor or an experienced engineer, this book focuses on getting your projects up and running as efficiently as possible.

All the projects you’ll create in this book use radio signals that pass invisibly through the air. This “wirelessness” is essential whenever you want to place sensors where no cables can be installed, or where such tethering is undesirable. With radio, you can employ sensing and actuation in pristine natural settings, minimalist building interiors, or complex urban environments. Mobile devices like children’s toys can benefit greatly by being communicative without being chained to the wall or to each other. Sensors can be attached to people or animals in a humane manner that doesn’t hinder their movement. In short, lots of data can move freely from where it is gathered to where it can do the most good. That’s why wireless is worth it.

The ZigBee protocol is a very popular way of creating radio sensor networks for a number of reasons. Wireless networks and connected devices in general tend to be used in situations where power is hard to come by and must be conserved. Many times the communications these networks send are small in nature, compared to systems that transfer huge files such as videos. Often, each device in the network transmits or receives unique information, so a robust system of individual addressing is extremely helpful. Security and design flexibility are frequently indispensable. That’s why this book focuses on ZigBee, the protocol defined by various industry players who together form the ZigBee Alliance. In the past few years, ZigBee has found its way into commercial systems for home automation, smart energy systems, consumer electronics, industrial sensing, and health care. It features full addressing, many power-saving options, optimizations for efficiency in low-bandwidth applications, and a layered approach to communications design and security. Most importantly, ZigBee automatically forms entire networks that can heal themselves, routing around problem areas without manual intervention. Designers, hackers, inventors, artists, and engineers are currently making use of this popular wireless protocol to create the systems that inform, enable, and delight their various users.

We will make a new project in almost every chapter of this book to demonstrate how everyday people, not just electrical engineers and computer scientists, can develop these systems. A number of full sensor networks, an array of doorbells, a two-way lighting detector, a household control system, and several types of Internet-connected contraptions will be demonstrated step by step for you to build. After reading this book you’ll have a solid understanding of what it takes to create scalable sensor and device networks because you’ll have brought a variety of them into being with your own hands. This book’s website makes even more resources available to you.

You may wonder what drives humans to create reactive sensor systems and connected devices. Since before written history, there have been people and cultures that believed every object in the world was imbued with spirits—that even rocks are alive. This worldview, termed animism by modern scholars, isn’t something validated by science. And yet the tacit belief that objects are in some way alive seems to resonate as a fundamentally human way of thinking. “That mixer doesn’t like it when the batter is too thick.” “The DVD player doesn’t want to eject that disk.” “My computer hates me!” We seem to want our things to be alive and frequently consider them willful—though, on an intellectual level we know they aren’t. This book isn’t about animism, of course; it’s about making networks using ZigBee radios. However, one reason we do this—our motivation for making systems that are sensitive, active, reactive, and communicative—could just be some inherent desire to create the world we believe should exist: one where everything is imbued with a willful spirit and works together to help us live more richly. If so, this book is offered as a practical step in the right direction. I hope it will help you bring your own creations to life.

How This Book Is Organized

The chapters in this book are organized as follows:

Chapter 1, Getting Ready

This chapter offers a shopping guide and an introduction to all the major components we’ll be using. We focus on just what you need to get up and running, including XBee radios, adapters, breakout boards, terminal programs, and software.

Chapter 2, Up and Running

Right at the start of the book, you’ll go from a bag of parts to a working ZigBee network in one chapter, taking the simplest path to early success. Radios, ZigBee, networks, and addressing are introduced, and then you’ll configure your components to achieve a simple chat session.

Chapter 3, Build a Better Doorbell

This section focuses on creating something practical using the Arduino microcontroller system, which is briefly introduced. After getting up to speed on basic serial concepts and simple protocols, you’ll execute a series of doorbell projects that increase in creative complexity as you gain skill.

Chapter 4, Ins and Outs

Here you’ll take a closer look at the unique features of the XBee-brand ZigBee radios so we can start building fully scalable sensor networks. You’ll begin with input/output concepts and commands, then immediately put these to use in a small set of progressively intricate projects.

Chapter 5, API and a Sensor Network

At this point you have everything you need to conquer the XBee’s application programming interface. We start by laying a foundation of ideas and scaffold you up to a full understanding of the structured API communication frames. You are then ready to create a fully scalable sensor network of your own, using the complete example at the end of this chapter.

Chapter 6, Sleeping, Then Changing the World

We ease the development pace a bit here to address some nuances of ZigBee mesh networking, including sleep mode, end devices, and power management. Then it’s time to change things in the physical world using direct actuation. This chapter features a powerful control project you can use to automate your home or turn just about anything on and off remotely.

Chapter 7, Over the Borders

In this chapter you learn to make gateways that connect ZigBee with neighboring networks, including a remarkably easy path to the Internet. You’ll see full examples, showing how to allow anything to talk to everything everywhere—plus there’s a special project for starry-eyed celebrity fans.

Chapter 8, More to Love

The final chapter is really a broader introduction. We explore advanced ZigBee techniques, demonstrate how to publish and share your data online, and then wrap things up with a peek at where ZigBee is headed.

Appendix A

To ensure that the book remains useful even after you have read it, we’ve included links to online resources and other texts for learning more about Arduino, Processing, Python, and ZigBee, along with a handy troubleshooting guide to get you unstuck from common mistakes. There are also tables to use as a fast daily reference to Digi radios, other brands of ZigBee modules, network analyzers, packet sniffers, connectors, shields, hexadecimals, binary numbers, ASCII codes, and finally a complete guide to XBee AT commands.

About the Title

You will notice that for a book called Building Wireless Sensor Networks, we spend quite a bit of time talking about actuation: outputs that make things happen in the physical world. The source of this is a deep-seated point of view that is backed up by some long-standing cognitive science.

“Thinking is for doing” is a phrase popularized by social psychologist Susan Fiske. Her point (and William James’ when he commented similarly a century earlier) is that our brains exist first and last for creating physical actions. In fact, the brain is just the midpoint of the perception-action chain. The real action starts with our sensory systems. We see, smell, and feel, then we process those sensations for the purpose of choosing and executing our next move. Sensing never happens in a vacuum for its own sake. There’s always a physical purpose. This is as true for wireless networks as it is for living organisms. The data we collect is always aimed at an action of some kind. Alarm systems trigger an immediate police response, while environmental sensing studies often have a much longer cycle that results in policies to guide real-world development. In both cases there’s a purpose to the sensing that ends up, sooner or later, creating changes in the physical world. This book takes a comprehensive approach to cover both the input and output stages of the information-action cycle—sensing and actuation. In doing so, we hope to encourage projects to do more with data than simply collect it, hopefully enabling implementations that use their sensory input to create the rich physical experiences that humans crave.

About the Examples

All of the example circuits and code in this book are designed with clarity in mind. Astute electrical engineers will certainly notice that some corners have been cut. For example, we draw close to the rated output for the 3.3-volt pin on the Arduino board in some projects, and we rely on the microcontroller to throttle the current going to LEDs where we can. While that wouldn’t be advisable in a commercial product, it does produce working circuits that are very simple for the beginner to build and understand. The same is true for the example code. Production-quality programming usually includes much more error correction and thriftier memory management than we offer here. Our purpose is to strip the code down to the basics as much as possible so that it can serve as a transparent tool for learning.

If you prefer to enhance the circuits and code to make them more robust, by all means do so! Feel free to share your suggestions or enhancements on the forums, and by sending them to us at . Feedback and community participation is always welcome!

Additional code and circuit diagrams that are made available in the future will be linked from this book’s website.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords

Constant width bold

Shows commands or other text that should be typed literally by the user

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context


This icon signifies a tip, suggestion, or general note.


This icon signifies a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation, and the projects as a foundation for creations of your own. You do not need to contact us for permission unless you’re reproducing a significant portion of the code or schematics. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Building Wireless Sensor Networks by Robert Faludi. Copyright 2011 Robert Faludi, 978-0-596-80773-3.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

Safari® Books Online


Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:


To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our website at:



This book was strongly affected by my tag team of editors Brian Jepson and Tom Sgouros. Brian’s fractured wit paired with his expert strategies constantly guided my hand, while Tom’s attention to details and scientific discipline provided the rigor any technical book demands. Even when process and schedule left me breathless, I never lost appreciation for the wisdom and craft they supplied. I’m grateful for all their help.

My technical editors imparted a level of feedback that went well beyond their respective calls of duty. Kate Hartman, who encouraged this book from the get-go, spent many hours combing the text for confusing constructions and omitted explanations. Her project assessments and clarity of voice are felt throughout. Jordan Husney cheerfully reviewed many of these chapters from his perch at 35,000 feet. His deep knowledge of the ZigBee protocol is matched only by his competence as a wordsmith. Thanks to both for their efforts and uncommon friendships.

Building Wireless Sensor Networks is loosely structured around the Sociable Objects class I created at NYU’s ITP graduate program in media and technology. There, Tom Igoe loaned me my first ZigBee radio, encouraged my projects, mentored my development as a teacher, and continues to be a seemingly bottomless well of excellent advice and terrible puns. This book almost certainly could not have happened without him. Clay Shirky, Nancy Hechinger, Marianne Petit, Dan Shiffman, Danny Rozen, and Dan O’Sullivan are but a few of the instructors who provided invaluable inspiration. George Agudow and the sensational staff at ITP have granted support to my work at every turn. My fellow resident researchers Jeff, John, Jenny, Kate, Gabe, and Demetrie influenced my ideas and enriched my experience during the year we were all lucky enough to work together. Almost all the concepts in this book were trialed by my Sociable Objects students and I am grateful for their feedback, which is incorporated throughout. Everyone in the ITP community owes a debt toward longtime Chair and perpetual guiding star Red Burns. Her steely stare, firm love, and rare brilliance continue to illuminate us all.

This book would have been immeasurably more difficult without Paul Cole’s flexibility, generous spirit, and unflagging support. I am thankful for the grand company of my entire day job crew at GroundedPower, especially longtime collaborators Terence Arjo, Mike Bukhin, and Demetrie Tyler. They caught my bullets on countless occasions when I needed extra concentration for penning these pages. At SVA’s MFA program in Interaction Design, Liz Danzico’s words of wisdom and my graduate students’ insightful creations brought depth to my thinking and clarity to my explanations.

My mother and father taught me to craft with words, wood, and wires—priceless skills that I am honored to share in some small measure here. I am lucky to come from two people with such talent, creative motivation, and quick-witted humor. My sister, Susan, and her partner, Russ, tirelessly guided me through the tricks of the writing trade. When enthusiasm flagged, Sue and Russ assured me that my writerly doldrums were distinctly underwhelming, cannily undermining my laments and restoring my cheer. I’m phenomenally lucky to have them in my life. Liz Arum bestowed suggestions, solace, affection, and perpetual patience as I alternately plodded and sprinted through the birthing of this book. Her family has pampered me with their hospitality, and her middle school students effortlessly completed several of the book’s projects, just as she knew they could. I’m grateful to all of them, and to Liz especially.

One more thing: John Dobson’s telescope-building class and indomitable spirit continue to be an inspiration in my work. If you ever get a chance to build your own sidewalk telescope, don’t hesitate for a minute. Everyone deserves to meet the universe in person.


The connection diagrams in this book were created with Fritzing, an open source tool for documenting, sharing, teaching, and designing interactive electronic projects. For more information, see their website.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required