Programming Your Home
Automate with Arduino, Android, and Your Computer
by Mike Riley
Version: P1.0 (February 2012)
Copyright 2012 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
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 The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
This book is dedicated to Bill, Eileen, and Josie.
Table of Contents
Copyright 2012, The Pragmatic Bookshelf.
Praise for Programming Your Home
Mike has a broad technology experience base that puts all the pieces of some remarkable projects together. Its amazing that he makes it all so easy and affordable. Dont miss all that can be learned from this gem.
Michael Bengtson, Consultant |
The Web-Enabled Light Switch project gave my family convenience and security options and enhanced my knowledge of RS-232 communications. It is nice to be able to switch on lights from my favorite chair. And the Tweeting Bird Feeder project has opened my eyes to the uses of radio communications around the home for things besides Wi-Fi, and it will help in my work to contribute to the preservation of bird species that are struggling for food and habitat.
Bob Cochran, Information Technology Specialist |
With this book, Mike Riley celebrates the Arduino microcontroller in a way that both beginning and advanced home automation hobbyists will enjoy.
Sven Davies, Vice President of Applications |
This is an outstanding reference that should be on the desk of every DIYer. In much the same way that software engineers mention The Gang of Four Patterns Book, I predict this text will eventually be referred to as The Riley Book of Home Automation.
Jon Kurz, President, Dycet, LLC |
Every technology is only as exciting as the things you do with it. Mike takes a few cheap electronics parts, an Arduino, and a bit of code and turns your home into a much more exciting and enjoyable place. His easy-to-follow instructions make every single one of these projects both fun and useful.
Maik Schmidt, Software Developer, Author of Arduino: A Quick-Start Guide |
Ive had more fun learning new languages, systems, and gadgets with this book than any other book Ive read!
James Schultz, Software Developer |
Home automation is great fun, and Programming Your Home by Mike Riley will get you started right away. By leveraging this book and the easily available free/inexpensive hardware and software, anyone can tackle some great projects.
Tony Williamitis, Senior Embedded Systems Engineer |
This is a fun and enthusiastic survey of electronic devices that can interact with the real world and that starts in your own home!
John Winans, Chief Software Architect |
Acknowledgments
I have been a lifelong tinkerer. My earliest recollection of dissecting my fathers broken tape recorder instilled an appreciation for the technology that drove it. From there, erector sets, model railroads, and programmable calculators led to personal computers, mobile devices, and microcontrollers. Over the years, this passion for learning not only how stuff works but also how technical concepts can be remixed with surprising, often highly satisfying results has been liberating. Thats why this book was such a joy for me to write.
Helping others to see whats possible by observing their surroundings and having the desire to take an active role in making their lives easier with technology while having fun is this books primary goal. Yet without others helping me distill my ideas into what you are reading now, this book would not have been possible. It is to them that I wish to express my deepest gratitude for their support.
A boatload of thanks goes to the books editor, Jackie Carter, who spent countless hours ensuring that my words were constructed with clarity and precision. Copy editor Molly McBeath did a fantastic job catching hidden (from my view anyway) typos and grammatical misconstructions. Big thanks to Susannah Pfalzer for her infectious enthusiasm and boundless boosts of encouragement and to Arduino expert and fellow Pragmatic author Maik Schmidt, whose own success helped pave the way for a book like this.
Many thanks also go to John Winans, tech wiz extraordinaire, who refactored the state machine code used in several of the projects, as well as to Sven Davies, Mike Bengtson, Jon Bearscove, Kevin Gisi, Michael Hunter, Jerry Kuch, Preston Patton, and Tony Williamitis for helping to make this book as technically accurate and complete as it is. Shout-outs also go to Jon Erikson and Jon Kurz for their enthusiastic encouragement. I also want to thank Bob Cochran and Jim Schultz for providing wonderfully helpful feedback during the books beta period. Thanks also go to Philip Aaberg for filling my ears with music to code by. And to the makers of and contributors to the Arduino and Fritzing projects, you people have changed the world for the better.
I am most grateful to my wife, Marinette, and my family for allowing me to tunnel away for months in my mythical man cave to complete this book. And I cant gush enough over the wonderful pencil illustrations that my daughter drew for the book. I am so proud of you, Marielle!
Finally, I am sincerely thankful to Dave Thomas and Andy Hunt for their passion and vision. Youre the best.
Mike Riley
Naperville, IL, December 2011
Copyright 2012, The Pragmatic Bookshelf.
Preface
Welcome to the exciting, empowering world of home automation! If you have ever wanted your home to do more than just protect you against the outside elements and want to interface it to the digital domain, this book will show you how. By demonstrating several easy-to-build projects, you will be able to take the skills you learned from this book and expand upon and apply them toward custom home automation projects of your own design.
The books primary objective is to get you excited about the broader possibilities for home automation and instill the confidence you need to ultimately build upon these and your own ideas. The projects also make great parent-child learning activities, as the finished products instill a great sense of accomplishment. And who knows? Your nifty home automation creations may even change the world and become a huge new business opportunity for other homeowners actively seeking an automation solution that saves them time and money.