Building Wireless Sensor Networks
Robert Faludi
Copyright 2010 Robert Faludi
This book uses RepKover, a durable and flexible lay-flat binding.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (.
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of OReilly Media, Inc. Building Wireless Sensor Networks , the image of dachshunds, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
O'Reilly Media
Preface
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. Ill explain everything necessary to get started, at least briefly. Well create examples using accessible environments, such as Arduino for hardware and Processing for displays. And Ill 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 youll 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 childrens 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 doesnt hinder their movement. In short, lots of data can move freely from where it is gathered to where it can do the most good. Thats 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. Thats 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 youll have a solid understanding of what it takes to create scalable sensor and device networks because youll have brought a variety of them into being with your own hands. This books 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 spiritsthat even rocks are alive. This worldview, termed animism by modern scholars, isnt 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 doesnt like it when the batter is too thick. The DVD player doesnt want to eject that disk. My computer hates me! We seem to want our things to be alive and frequently consider them willfulthough, on an intellectual level we know they arent. This book isnt about animism, of course; its 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:
This chapter offers a shopping guide and an introduction to all the major components well be using. We focus on just what you need to get up and running, including XBee radios, adapters, breakout boards, terminal programs, and software.
Right at the start of the book, youll 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 youll configure your components to achieve a simple chat session.
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, youll execute a series of doorbell projects that increase in creative complexity as you gain skill.
Here youll take a closer look at the unique features of the XBee-brand ZigBee radios so we can start building fully scalable sensor networks. Youll begin with input/output concepts and commands, then immediately put these to use in a small set of progressively intricate projects.
At this point you have everything you need to conquer the XBees 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.