Environmental Monitoring with Arduino
Emily Gertz
Patrick Di Justo
Copyright 2012 Emily Gertz and Patrick Di Justo, Patrick DiJusto and Emily Gertz
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. Environmental Monitoring with Arduino 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.
Important Message to Our Readers: The technologies discussed in this publication, the limitations on these technologies that technology and content owners seek to impose, and the laws actually limiting the use of these technologies are constantly changing. Thus, some of the projects described in this publication may not work, may cause unintended harm to systems on which they are used, or may not be consistent with current laws or applicable user agreements.
Your safety is your own responsibility, including proper use of equipment and safety gear, and determining whether you have adequate skill and experience. Electricity and other resources used for these projects are dangerous unless used properly and with adequate precautions, including safety gear. These projects are not intended for use by children. While every precaution has been taken in the preparation of this book, OReilly Media, Inc., and the authors assume no responsibility for errors or omissions. Use of the instructions and suggestions in Environmental Monitoring with Arduino is at your own risk. OReilly Media, Inc., and the authors disclaim all responsibility for any resulting damage, injury, or expense. It is your responsibility to make sure that your activities comply with applicable laws, including copyright.
Make
Preface
This book is all about making the invisible visible.
Each project introduces a particular environmental condition, and then teaches you step by step how to build a small, inexpensive electronic device that can monitor that condition, and communicate back what it finds.
When you start monitoring the environment, something happens: You start to understand the world around you in a new way.
Build a water quality tester, and a beautiful, clear-running stream may become a beautiful clear stream with a high particulate count (see ).
Build a gadget to measure temperature and humidity, and youll see for yourself that high noon is not the hottest part of the day; that actually comes around 3 p.m. (see ).
Build an electromagnetic field detector, and youll discover even a quiet room is buzzing with unseen, unheard electrical vibrations (see ).
We usually turn environmental monitoring over to the scientific experts at government agencies, universities, and corporations. They come armed with complicated and expensive equipment as well as specialized educations, and occasionally their own institutional agendas.
Since the natural environment is complex, even more so for all the stuff we human beings and our activities have added to the mix, this sort of expertise has an important role in our lives and in our communities. Scientific analysis and expertise are key to creating effective regulations that control the impacts human activities have on the environment and our health.
Monitoring the environment for ourselves, however, pulls the curtain back on what all those experts are doing. Understanding brings knowledge, and with knowledge comes the power to make decisions that can change our lives for the betterfrom lowering the electric bill, to holding polluters accountable, to helping scientists study the changing climate.
How to Use This Book
We suggest that you build the projects that follow in the given order, since they progress from easier to more complex.
If you already have some experience with Arduino, and want more challenges in making and using these gadgets, look for the Things to Try section at the end of each project chapter. We make suggestions for changing the build or the programming that will exercise your skills. We hope youll come up with your own ideas, too, and tell us about them.
One straightforward way to increase each projects difficulty, once you have built and tested a gadget, is to rebuild it in a more permanent way by soldering the components together. We also offer a few general suggestions for creating enclosureshandy and rugged cases for your gadgetsat the end of this book. You can make enclosures as simply or elaborately as you choose.
Finally: We do our best to describe how to build each gadget as clearly as possible. But as its almost inevitable that even a simple project will frustrate you now and then, here are some tips to keep things fun and interesting:
Break it down It may be difficult to get a gadget to work correctly the first time. But dont get discouraged! Most of these gadgets didnt work the first time for us, either. What weve found, and what we think will work for you, is to break every gadget down into separate components, typically input and output components. Dont skip the preliminaries Make sure each component works individually before connecting it with others. If its working on its own, it will be much more likely to work when combined into a gadget. Save. Back up. Document.
When it comes to coding, this is our mantra:
- Save: Save your code frequently as you work on it.
- Back up: Always back up your code to at least one location other than your hard drive, such as a peripheral drive, memory card, or flash drive.
- Document: As you write programming code, include comments (more on this in ) that explain what the code does; when you look at your code several days later, you might not remember. As you build a gadget, take notes about what you discover, so that you can refer to them later.
Do these three simple things consistently, and when your computer crashes, your laptop falls out of your bag and onto the concrete, or your cat walks across the keyboard, you will be calm in the knowledge that you always have a copy of your work safely stored somewhere else.
Change only one thing at a time
If you decide to make any changes to the code or the design of these gadgets (and we heartily encourage you to do so), we suggest that you change only one thing at a time, and test it before making another change.
This is important because your change may cause the gadget to stop working. If youve made only one change, it will be easy to undo it and return to a working version of the gadget. This allows you to move ahead with confidence, because you know that any glitch is easy to fix.
Mash it up
Weve done our best to design these gadgets in a modular fashion, so that with only a little tweaking, you can swap the the input and output components between them. Want to modify the temperature gadget to output to Pachube rather than a display? Go for it! The hardware should be easy to modify, and changing the code will usually be a simple matter of cutting and pasting from one gadgets code to the next.