Environmental Monitoring with Arduino
Emily Gertz
Patrick Di Justo
Dedication
To all our nieces and nephews, who we hope will make a more understandable world.
Special Upgrade Offer
If you purchased this ebook directly from oreilly.com, you have the following benefits:
DRM-free ebooksuse your ebooks across devices without restrictions or limitations
Multiple formatsuse on your laptop, tablet, or phone
Lifetime access, with free updates
Dropbox syncingyour files, anywhere
If you purchased this ebook from another retailer, you can upgrade your ebook to take advantage of all these benefits for just $4.99. to access your ebook upgrade.
Please note that upgrade offers are not available from sample content.
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.
Granted, some swaps dont seem to make much sense: it might be rather odd to build a thermometer with an audio output. But give it a try if you want to. Who knows what youll come up with?Heres our own favorite mashup so far: If you combine the audio output of the electromagnetic field detector with the Geiger counter input, and then tweak the code just right, you can make an old-fashioned click-click-click radiation detector, just like in the movies.So mix and match! Have fun! Be bold!
Ask for help
There is absolutely zero shame in asking for help, and there is less than zero shame in asking for help with an Arduino project. The entire Arduino ecosystem is built on a philosophy of open access to knowledge. Some people may know more about building circuits or writing code than you know. You might know more than someone else.
But to a certain extent, no one is an expert, because no one has made Arduino do everything it can do.Whether online or face-to-face, people will be happy to help you learn if youre respectful, gracious, and willing to share. We guarantee that after weeks of feeling like all you ever do is ask questions, there is nothing like the thrill youll get the first time youre able to help someone else solve a problem.
Here are some resources for connecting with fellow Arduino users:
- http://www.arduino.cc: The online home of Arduino features user forums and more.