cover.eps

Arduino® Projects For Dummies®

Visit www.dummies.com/cheatsheet/arduinoprojects to view this book's cheat sheet.

Table of Contents

Introduction

Why Arduino?

Foolish Assumptions

Safety and Arduino Projects

How This Book Is Organized

Part I: Getting Started with Arduino Projects

Part II: Basic Arduino Projects

Part III: The Interactive Home and Garden

Part IV: Advanced Arduino Projects

Part V: The Part of Tens

The Companion Website

Icons Used in This Book

Part I: Getting Started with Arduino Projects

Chapter 1: Exploring the World of Arduino

About Arduino

Discovering Who Uses Arduino

Arduino in education

Arduino in the corporate world

Making and hacking communities

Understanding Microcontrollers

Using tiny computers to do useful stuff

Getting Started

Chapter 2: Setting Up Your Workspace and Tools

Preparing to Build

Setting up your workspace

Selecting Basic Tools

Selecting and using your multimeter

Selecting and using a power supply

Understanding electricity and safety

Working with breadboards, stripboards, and perfboards

Choosing Your Soldering Iron and Accessories

Selecting Project Boxes and Housings

Choosing Your Arduino or Arduino Kit

Getting to know Arduino shields

Setting Up Your Arduino on Your Computer

Installing the Arduino IDE

Installing drivers on Windows computers

Installing Arduino drivers on Linux

Chapter 3: Understanding the Basics

Understanding Key Concepts

Connecting your Arduino

Programming your Arduino using the IDE

Extending your reach with libraries

Powering your Arduino

Understanding Basic Electronics

Voltage (V)

Current (I)

Resistance (R)

Ohm’s Law

So what?

Identifying Electronic Components

Reading schematic diagrams

Reading parts placement diagrams

Understanding Sensing and Actuating

Reading datasheets

Understanding and using sensors

Understanding and using actuators

Making Projects Work

Moving from your breadboard to your project box

Learning soldering basics

Part II: Basic Arduino Projects

Chapter 4: The All-Seeing Eye

Selecting Your Parts

Building the Circuit

Understanding How the Code Works

All in good time

Setting up the code

The main event

Stepping up and stepping down

Understanding How the Hardware Works

The Potential of a Potentiometer

Chapter 5: Making a Light Pet

Selecting Your Parts

Building the Circuit

Understanding How the Code Works

Making moods

Cranking out the code

Blending light

Fooling your eyes with pulse-width modulation

Testing the code

Upload and go

Tweaking it!

Understanding How the Hardware Works

Chapter 6: Making a Scrolling Sign

Selecting Parts

Building the Circuit

Understanding How the Code Works

Summoning a sprite

Animating sprites

Displaying scrolling text

Understanding How the Hardware Works

Troubleshooting

Getting creative

Chapter 7: Building an Arduino Clock

It’s About Time!

Selecting and Preparing Your Parts

Assembling your RTC module

Adding and testing your LCD display

Displaying the time

Adding your input buttons and a switch

Adding your alarm

Part III: The Interactive Home and Garden

Chapter 8: Building a Keypad Entry System

Selecting and Preparing Your Parts

Selecting an electric lock mechanism

Prototyping your keypad and display

Coding and testing your keypad

Adding and testing your relay

Assembling and Installing Your System

Chapter 9: Building an RFID Tag Reader

Understanding RFID

About passive RFID

About active RFID

RFID frequencies and protocols

Building an ID-Innovations RFID Reader

Selecting your parts

Assembling your RFID reader

Programming your RFID reader

Testing and Setting Your RFID Reader

Chapter 10: Building an Automated Garden

Creating a Watering System

Selecting Your Parts

Building Your System

Building your moisture sensor

Building your reservoir

Running the water supply

Building the breadboard circuit

Coding, Calibrating, and Testing

Defining the setup

Running the main loop

Calibrating the sensor and flow rate

Adding more valves

Chapter 11 : Building a Tweeting Pet Door

Selecting Your Parts

Testing Your Circuit

Preparing Your Twitter Account

Crafting Your Code

Specifying your tweets

Adding libraries for Ethernet and Twitter

Adding your program logic

Modifying Your Pet Door

Chapter 12: Building a Home Sensing Station

Building Your Sensor Probes

Selecting your parts

Building and testing your circuit

Building your sensor probes

Building your sensor shield

Creating a Xively Account

Programming Your Sensing Station

Understanding the code

Understanding the main loop

Making sense of your sensor readings

Part IV: Advanced Arduino Projects

Chapter 13: Building a GPS Data Logger

Understanding GPS

Selecting Your Parts

Building Your Project

Assembling and testing the GPS shield

Programming your data logger

Testing your data logger

Making the enclosure

Collecting and Plotting GPS Data

Tracking your path

Plotting your data

Chapter 14: Building a Remote-Controlled Car

Selecting and Preparing Your Parts

Building Your Detector and Drive

Building your circuit on the breadboard

Coding the detector

Reading your remote control codes

Coding the drive motors

Testing the drive motors

Building Your Chassis

Chapter 15: Building an LED Cube

Selecting Your Parts

Building Your Cube

Assembling the LED matrix

Fabricating the enclosure

Programming Your Cube

Variable declarations

Setup

The main loop

Using the LED Cube Pattern Designer

Part V: The Part of Tens

Chapter 16: Ten Great Arduino Resources

Websites

Arduino.cc and related forums

Fritzing

Hack-a-day

Instructables

Learn.adafruit.com

Make:

element14

YouTube

Books and eBooks

Arduino For Dummies

The Arduino Cookbook

Making Things Talk

Chapter 17: Ten Troubleshooting Tips

Troubleshooting Your Hardware

Checking Your Connections

Confirming Your Power Is Correct

Hunting for Odors and Hot Components

Test Your Outputs on External Devices

Testing Your Digital Pins

Troubleshooting Your Software

Checking Your Syntax

Using the Serial Monitor

Checking Your Inputs and Outputs

Using a Simulator or an Emulator

When All Else Fails . . .

Cheat Sheet

About the Author

Brock Craft is a Lecturer in the Department of Computing at Goldsmiths, University of London. He is also a Senior Tutor at the Royal College of Art. He is a specialist in physical computing, data visualization, and the Internet of Things. Brock’s background is in the field of human-computer interaction, and he has over a decade of experience making interactive things that people can use, explore, and play with. He was a co-director of the design consultancy Tinker London, along with Alexandra Deschamps-Sonsino and Massimo Banzi, one of the founders of the Arduino Project. He has taught hundreds of people to create things with Arduinos.

When he is not teaching and learning, Brock likes to make interactive stuff and digital art.

Dedication

For Barbara, who has supported me steadfastly on this most incredible journey, and without whom this book would not have been possible. She has put at least as much work into this effort as I have. I also dedicate this book to my mother, Lea Gaydos, who taught me that I can do anything I put my mind to. I would like to acknowledge and dedicate this book to the memory of Craig Veal, the best teacher I ever had.

And most especially, this book is for Eleanor, who I hope will grow up to make everything in her world come alive with creativity.

Author’s Acknowledgments

First and foremost, I’d like to thank Massimo Banzi and the entire Arduino crew. Their foresight has opened up the joy of programming and electronics to millions of people and revitalized my own teaching and learning.

Writing this book has been a rewarding and challenging process, which would not have been possible without the support of my many colleagues and friends. I’d like to extend special thanks to Alexandra Deschamps-Sonsino, without whose insight this book wouldn’t have been undertaken. I’d also like to extend my gratitude to all the members of the TinkerLondon crew, the extraordinary Nick Weldin, and also to Peter Knight, from whom I learned so much during our extraordinary work together.

My father’s mechanical acumen is, no doubt, where I got my own, and I thank him for many rewarding hours of thinking and tinkering together. I also appreciate the contributions and support of my friends Jason Geistweidt, James Larsson, Patrick Burkart, and Carl Wiedemann, whose probing questions inspired me to think a bit harder about my readers. Many of my students have made useful suggestions too, which were very helpful in deciding what should go into these pages.

Particular thanks go to my technical editor and TinkerLondon compatriot, Daniel Soltis, who spent many hours building the projects from scratch and finding errata. He has made many useful suggestions for improving both the projects and the code. Daniel’s excellent insights into how people build projects, along with his edits and tweaks, have been a hugely positive contribution.

I also extend my gratitude to the team at Wiley, including the patient and supportive Craig Smith, and to Beth Taylor for her excellent editorial recommendations.

Publisher’s Acknowledgments

We're proud of this book; please send us your comments at http://dummies.custhelp.com. For other comments, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

Some of the people who helped bring this book to market include the following:

Acquisitions, Editorial

Project Editor: Beth Taylor

Executive Commissioning Editor: Craig Smith

Associate Commissioning Editor: Ellie Scott

Copy Editor: Beth Taylor

Technical Editor: Daniel Soltis

Editorial Manager: Jodi Jensen

Senior Project Editor: Sara Shlaer

Editorial Assistant: Annie Sullivan

Cover Photo: Brock Craft

Marketing

Associate Marketing Director: Louise Breinholt

Marketing Manager: Lorna Mein

Composition Services

Senior Project Coordinator: Kristie Rees

Layout and Graphics: Jennifer Creasey, Joyce Haughey

Proofreaders: Debbye Butler, Jessica Kramer, Linda Seifert

Indexer: BIM Indexing and Proofreading Services

UK Tech Publishing

Michelle Leete, VP Consumer and Technology Publishing Director

Martin Tribe, Associate Director–Book Content Management

Chris Webb, Associate Publisher

Publishing and Editorial for Technology Dummies

Richard Swadley, Vice President and Executive Group Publisher

Andy Cummings, Vice President and Publisher

Mary Bednarek, Executive Acquisitions Director

Mary C. Corder, Editorial Director

Publishing for Consumer Dummies

Kathleen Nebenhaus, Vice President and Executive Publisher

Composition Services

Debbie Stailey, Director of Composition Services

Introduction

Have you heard a lot about Arduinos and wanted to get to know how they work a little bit better? Maybe you have a friend who’s used an Arduino to build some crazy project or interactive gizmo. Perhaps you have an Arduino lying around that you always thought you’d get working but never had the time to do it. It’s time to blow the dust off!

Maybe you just want some inspiration and fun projects to do in your spare time or on the weekends. If so, this is exactly the book for you. The projects here show off some of the amazing capabilities of an Arduino, and they can all be completed without any prior expertise or experience. It’s also a great companion to other Arduino books that you may have bought or skimmed through.

Arduino Projects For Dummies is an inspiring collection of fun and interesting things you can do with an Arduino. I’ve packed in a wide range of cool ideas for things you can do. Best of all, I selected them so that after you’ve done a few of them, you’ll have most of the technical knowledge you’ll need to come up with your own amazing gadgets, widgets, and interactive stuff. Whether you are an Arduino newbie or a seasoned pro, these projects are super fun to build and help you to really get your creative ideas flowing.

Why Arduino?

It’s no secret that Arduino has been making a lot of news lately, especially among makers, tinkerers, and hobbyists. All kinds of people are getting into the powerful and interactive things you can do with an Arduino — from school kids to university researchers, to artists and designers. One thing that sets apart Arduino from a lot of other platforms is that anyone can write new programs to use with it and share them online. Even more powerfully, special code collections called libraries extend the things Arduino can do by allowing you to connect cameras, motors, printers, scanners, remote controls — you name it. Because anyone can create code for Arduino and share it online, the community is really growing fast. It’s been instrumental in renewing interest in electronics and new hacker spaces all over the country where people build cool things, such as autonomous robots, 3D printers, and interactive artwork.

Foolish Assumptions

I’m assuming in this book that you have an idea of what an Arduino is and maybe have played around with one a bit. You also may have done some basic electronics, either in a school physics class or on your own, but you may not be aware of or remember much about the basic principles of electronics. That’s no problem, because I’ll go over what you need to know and explain a bit about how the electronic circuits in this book work, mainly what you need to know to get the projects going.

I also figure you’ve tried your hand at writing a little code before. But whether you have written any code at all, I explain how all of the programs in this book work in fine detail. That way you can learn how to program your Arduino to do not just the things in this book but the things you want to do.

I’m also assuming you want to get your Arduino to do its thing on its own and without having to rely on a computer for power or a data connection. So all of the projects in this book can operate just fine without the need for keeping your Arduino connected to your desktop or laptop.

Which brings me to another assumption — that you have a computer you can work on consistently and that you’re pretty familiar with how to operate it, move and save files, and generally keep your system organized. I’m also assuming you are familiar with downloading zipped files from the Internet and extracting them.

Safety and Arduino Projects

When working with electricity, safety is paramount. If you connect something incorrectly, you can easily fry your hardware or yourself, especially if you do anything with household power. That’s why none of the projects in this book are connected directly to the main power. All of the projects use low voltage, direct current components. It’s simply a safer way to operate.

However, it is still possible to fry something if you aren’t careful. So you should pay particular attention that you are wiring things up according to the diagrams provided. There are warning icons in the margins for steps that are particularly hairy, so keep an eye out for them. And speaking of your eyes, some of the projects require a little light fabrication, so you should use those safety goggles. Also, if you do any soldering, you have to be careful about the hot soldering iron. Make sure you set up your workbench to be a safe and productive environment.

How This Book Is Organized

In general, I’ve organized the book with the easier projects toward the beginning and the harder ones toward the end. But if you see a project you really want to get going on, dive right in.

Check out the table of contents to see what you might want to tackle first, and if you need to look something up, the index is a handy reference.

The parts in this book are divided into chapters, so you can find what you need quickly and easily.

Part I: Getting Started with Arduino Projects

You should check out Part I before you get started, to make sure you are ready to go and your project building workspace has everything you’ll need to get your work done. I discuss the basics of setting up your workbench and getting the right project building supplies and tools in Chapter 2, and I cover setting up your Arduino on your computer.

tip.eps I also describe the most popular kinds of Arduino boards and suggest which ones are good for different applications, although all of the projects in the book can be built with the basic Arduino Uno.

I also cover setting up your Arduino and provide some tips on “packaging up” your project. A lot of Arduino project guides online neglect the part about building a good enclosure, so there are some creative tips in this section.

Chapter 3 describes the basics of writing Arduino code and the basics of physically building your projects. If you know nothing about writing code for Arduino, you should definitely read this chapter. Pretty much everyone who has used an Arduino has made an LED blink, and that’s what you do in Chapter 3, when you set up your Arduino. I also describe the kinds of things you can do with your Arduino — sensing things in the environment and actuating things. I give an overview of the kinds of electronic components you will find out there on the market and provide some tips on soldering and building your projects.

Part II: Basic Arduino Projects

Part II is all about lights and timing. Chapter 4 takes LEDs bit further, describing how to make lots of LEDs blink in what I call an All-Seeing Eye — think Battlestar Galactica. Chapter 5 describes how to make LEDs pulsate so you can create a light pet with a personality. Chapter 6 takes LEDs to a more functional application – writing with light, in which timing is a key factor. Chapter 7 rounds things off with another timing application — building an alarm clock. This is the most advanced project in Part II, so if you are just getting your feet wet, save it for last.

Part III: The Interactive Home and Garden

Turn to Part III if you are fascinated by sensors and home automation. People have been automating their homes and apartments since the 1980s, at least — but with Arduino, you can take things to a whole new level! Chapter 8 shows you how to build a keypad entry system for your door — very James Bond. When you’ve completed it, you can extend its capabilities with the keycard reader in Chapter 9. Only someone with a properly registered keycard will be able to gain access.

Once you’ve made it easier to come and go, you can build the plant irrigation system in Chapter 10. That way, when you’ve gone out for a long trip, you can make sure your houseplant or even a whole indoor garden stays healthy and happy.

While you are smartening up your home, you can give your pets a new voice as well. The tweeting pet door in Chapter 11 helps give your dog or cat a voice online. You’ll be able to tell whenever they are coming and going by wiring up your pet door to the Internet — with no computer required, once it’s set up!

The last project in Part III takes this one step further and shows you how to connect live data feeds from your house to a data tracking system online. In Chapter 12, you build your own home sensing station that posts regular information about temperature and light levels around your house — accessible from anywhere you can get an Internet connection. You can even embed data charts into your own website. Once you’ve got a handle on how the code works, you can hook up just about any sensor to the Internet — whether in your home, garden, or treehouse.

Part IV: Advanced Arduino Projects

I’ve saved some of my favorite and trickiest projects for last, in Part IV. Chapter 13 shows you how to build a GPS data logger. You don’t have to settle for the GPS in your car or on your phone. You can use it just about anywhere and log the data to a standard SD data card. There are all kinds of clever uses for this, including tracking vehicles, packages, pets, and logging your own explorations in the city or country.

No electronics-related project book would be complete without a remote- controlled device of some kind. Chapter 14 shows you how to build your own remote-controlled car out of a few easily found supplies and some potato chip cans. The clever part is that you use any old remote control around your house to control the car. By the time you finish this project, you’ll not only have a pretty cool vehicle, but you’ll also understand the basics of using servo motors and how to use an Arduino to make just about anything remote controllable.

Chapter 15 gets back to playing around with light. LED cubes are getting really popular and if you haven’t seen them already, you will. This chapter shows you how to make and program your own. There’s also an online tool for building your own animated lighting patterns. Both the code and the physical construction are pretty challenging, but the results are really cool. If, like me, you are mesmerized by blinking lights, you’re gonna love this one.

Part V: The Part of Tens

Every book in the For Dummies series has a “top ten” style list where you can find further information quickly. This part is where I get to share some of my favorite Arduino resources and some handy tips and tricks with you.

Chapter 16 describes the best suppliers and Arduino resources for the stuff you’ll need to build the projects and take things even further. I also get to brag about my favorite suppliers — and friends — in the Arduino world. Every projects book should help you out with troubleshooting as much as possible. Chapter 17 provides tips for solving problems. This can be tricky, since the problems could arise from your software or your hardware — or both! I hope that the tips in this chapter will help you figure out why your project might not be working.

The Companion Website

This book has a companion website that offers some additional projects and a tool for creating patterns for the LED cube you build in Chapter 15. Go to www.dummies.com/go/arduinoprojectsfordummies and look on the Downloads tab. You can also find schematics and full-color parts placement diagrams here to help you build the projects in this book.

tip.eps Several of the projects require additional code libraries to make them work. You can find these libraries in a .zip file on the Downloads tab of the companion website. Later, if updates become available for this book, you can also find them on the Downloads tab.

Besides this book's companion website on dummies.com, you can also go to my personal website at www.brockcraft.com. Everyone I've ever met who tinkers with Arduino is happy to help out other folks in improving their code and their projects. So, if you have any suggestions for enhancing or improving these projects, please let me know!

Icons Used in This Book

I can’t highlight the most important passages in this book with my trusty Sharpie or yellow highlighter, so I’ve used icons to draw your attention to the important parts.

tip.eps Tips highlight information that can save you time or money or just make things easier to do. You’ll have a lot more fun if you keep the tips in mind as you go along, and they can help you with your own projects, too.

warning_bomb.eps Building projects can be tricky or hazardous or both. I’ve placed warnings to highlight areas where it’s easy to make a mistake or fry something or generally get something messed up. The warnings are there so that you don’t have to learn the hard way — because I probably already did that for you!

remember.eps Sometimes there are important points that you really need to keep in mind when you are working on a project or writing code. I’ve use this icon to highlight these important points. That way, you can easily find them when you are reviewing a project or building a new one of your own.

technicalstuff.eps This is a pretty technical book, but sometimes there are extremely geeky topics that are either interesting or useful to know. I’ve identified these with this icon. You can skip this stuff because it’s not essential to know in order to build the projects, but I’ve included it here in case you want to understand a little better how things work.

Part I

Getting Started with Arduino Projects

9781118551479-pp01.eps

pt_webextra_bw.TIF For Dummies can help you get started with lots of subjects. Visit www.dummies.com/extras/arduinoprojects to learn more and do more with For Dummies.

In this part . . .

check.png Learn how to set up your Arduino workspace

check.png Find out about the many different kinds of Arduino boards

check.png Get to know the basics of Arduino code

check.png Learn about electronics components and soldering techniques

Chapter 1

Exploring the World of Arduino

In This Chapter

arrow Discovering Arduino

arrow Understanding who uses Arduino

arrow Understanding microcontrollers

arrow Understanding Arduino capabilities

You probably wouldn’t have picked up this book if you hadn’t already heard about the “World of Arduino.” You’re probably already a part of it. I think of it as being made up of a community of creative people who are interested in making inanimate stuff do interesting and clever things with computers, programming, and computational thinking — which is just a fancy way of saying “writing recipes.”

Computational thinking means considering problems and their potential solutions and trying to determine the best way to get to those solutions. Usually, it means deciding the best steps to take — and in what order — as well as keeping track of important decisions along the way, or getting the right information you need to make a decision. This could be doing something simple like baking cookies, in which case you probably don’t need a computer. But you can use a little bit of computing power to carry out a simple sequence of steps and decisions to come up with something really creative.

Maybe you want to know when your cat is coming and going from your house. Perhaps you want to know when your houseplants need a little more water and then give it to them automatically. Or suppose that you want to be able to open your front door with a code or card, instead of a physical key. Each of these involves just a little bit of sensing what’s going on in the real world, combined with decision making, and then performing some kind of action.

In the case of watering your plants, it’s something a human might be prone to forgetting or something you just don’t want to pay attention to all the time. Sounds like the perfect job for a computer. That’s where Arduino comes to the rescue.

About Arduino

The Arduino Uno (see Figure 1-1) is a general purpose microcontroller programming and prototyping platform that you can easily program to react to things going on in the real world. You can also link between the real world and the virtual world by connecting up your Arduino to the Internet, either sending data to the Internet or responding to data on the Internet, or both.

You can use it to sense almost anything you can find an electronic sensor for, including light, temperature, pressure, sound, even smell — if you consider environmental pollution to be a smell. You can even build your own sensors. How your Arduino reacts depends on how you program it. You can use its output capabilities to sound alarms, open doors and windows, activate lights or motors — the possibilities are almost endless.

Arduino is used for prototyping ideas — getting them half built and then trying out what works. Prototyping means testing alternatives to come up with creative solutions to problems (see Figure 1-1). You try out part of a project to see how your sensors respond and then change how your Arduino program functions, depending on what works best for you. Although the projects in this book are like little recipes, they are just a starting point. You could — and should — use any of them to build much more elaborate ideas and projects.

9781118551479-fg0101.tif

Figure 1-1: The general purpose Arduino Uno prototyping board.

Discovering Who Uses Arduino

The Arduino family is used by makers, hackers, designers, artists, architects, and even professional engineers to quickly and easily try out interactive design ideas. The Arduino Uno is inexpensive and easy to use, with a big community of supporters, tinkerers, and developers who are constantly coming up with new ways to use it and improve it. In the next sections, I go over a few of the kinds of people and communities that are using Arduinos every day.

Arduino in education

Arduino provides a really simple way to learn how to program microcontrollers to sense and react to events in the real world and even online. Because it was conceived as a way to support designers and artists — people who are not typically computer programmers — it is very easy to get started and easy to use. I have taught hundreds of people — from little kids to retirees — to get started programming with Arduino. They have gotten simple programs up and running in as little as a half-hour and built their skills to develop their own sophisticated projects in a weekend. As you see from the projects in this book, it doesn’t take long to get your Arduino doing some pretty interesting stuff. And the more time you put into using it, the more you can get out of it.

Art and design schools use Arduino to design new interactive product prototypes, interactive artwork, performances, and even clothing. High schools and secondary schools teach core concepts in computer programming. University students in engineering and computer science departments use Arduino to create interactive models and prototypes as well as learn sophisticated computer-controlled engineering techniques.

Arduino in the corporate world

A growing community of industry professionals in the corporate world use Arduinos to make interactive stuff in their work. Design firms use them to develop interactive product prototypes. Software engineering companies use them to test software systems that interact with the physical world. Ad agencies use them to come up with new and creative interactive campaigns. Arduinos are used to control interactive exhibits and conferences and trade shows in both the industry and in digital media sectors. They are used as management-consulting tools to help teams coordinate problem solving and improve collaboration.

Making and hacking communities

In little pockets all over the world, a new community of tinkerers, makers, and hackers has emerged. Arduino has been a fuel for this creative fire and continues to be one of the key hardware prototyping platforms that people create projects with, talk about, and share with one another.

What are they about?

There have been small electronics and hardware clubs since the early days of the twentieth century, when teenage boys were encouraged to build their own “cat’s whisker” radios to listen to the new local radio stations that were popping up all across the United States. Over the decades, a large community of radio buffs grew, especially among fans of the shortwave radio frequencies. These “ham” radio aficionados set up their own transmitters and spent long hours listening to the radio waves for new and far-flung transmissions from friends and strangers. By the 1970s, the stage was set for a whole new generation of electronics fans who started clubs around not just radios but also the newly available home computers. Lots of midnight oil was burned as tinkerers and hobbyists stayed up hacking code and trading ideas on electronic bulletin board systems. This was the breeding ground for some of today’s giants, including Apple. Then the Internet exploded onto the scene and changed everything.

At about the same time Arduino was created in 2005, a small subculture emerged that was sort of an extension of the computer clubs and do-it-yourself groups and clubs. Fueled by the Internet, there was sort of a renaissance of computer clubs and do-it-yourself groups, as it became easier to use computers and electronics to make interesting interactive stuff. Some people even call it a “maker movement.” The Arduino fits right in with DIY groups, makers, tinkerers, and hackers. There are now hundreds of makerspaces (also called hackspaces) around the world. If you live in a big or medium-size city, there is probably one near you. Makerspaces are community-operated physical space where people with common interests (like Arduino!) can meet, get ideas, collaborate, and share accomplishments. Check for a makerspace in your area. These are the best places to learn how to build even more cool stuff with your Arduino.

The open source world

The term open source is thrown around a lot these days. If you haven’t come across it, you will, because the Arduino is one aspect of the open source world. Open source refers to both a philosophy and a software development approach that advocates for complete transparency in all the points of authorship of software. That lets anyone see how a program is built and potentially contribute to its development. The open source movement is a reaction to the tight control that software companies have had over their products. Their code is intellectual property, and they want to keep control of it both to prevent others from stealing their ideas and to maintain the quality of their products. However, the downside is that consumers are disempowered from making changes and can sometimes be locked in to buying upgrades they may not want. In principle, anyone with a little know-how can pitch in and contribute to the software development of open source projects, because the code is all online and freely downloadable. The Linux operating system, Google’s Android operating system for mobile phones, and Mozilla’s Firefox Web Browser are popular examples of open source software.

Thinking about computer hardware as being open source is a relatively new idea, and Arduino is at the forefront. It was conceived as a tool that anyone can build and use to do his own prototyping, using the ATmega328 microcontroller. All the plans to produce your own Arduino are freely available online, and you can put one together without paying anyone else to do so. In practice, it’s usually cheaper to buy one, but the principle still holds that the plans are freely available and redistributable.

Contributing to the Arduino project

In the spirit of collaborative development, people are also invited to contribute to the development of the Arduino platform and a thriving community of enthusiasts has contributed to both the hardware development and to the many software libraries that extend Arduino’s capabilities. If you want to jump in on the action, all you have to do is join the conversation in the Arduino developer discussion boards and consider writing some libraries of your own. If you are really eager, you may even be able to contribute to the development of the next Arduino board.

Understanding Microcontrollers

The heart of an Arduino is a microcontroller, a little computer that performs menial decision-making tasks that might be tedious, too fast, too slow, or otherwise irritating for a human to do. You can make it sense events in the real world and then react to them by doing something. This little guy is perfectly happy to wait for days until the houseplant dries out and then give it a little drink. You simply need to tell him what to wait for and what actions to take. And he’s really very little.

Because it’s a microcontroller, it’s very small, so it doesn’t need much power and can be put into tiny spaces like a project box. How small are microcontrollers? Physically, the one on the Arduino is about as large as they come, about half the size of a pack of gum, as you can see in Figure 1-2. The microcontroller is the rectangular integrated circuit (IC) on the blue printed circuit board (PCB). It’s that size because it’s easy to handle with your fingers, so you can replace the microcontroller on your Arduino if it croaks for some reason. But microcontrollers start about this large and go down from there, all the way to the microscopic level. The main factors that determine their size are their capabilities and cost. In fact, the actual processor core on your Arduino chip is much, much smaller than the exterior IC chip itself.

9781118551479-fg0102.tif

Figure 1-2: The Arduino’s brain, an ATmega328 microcontroller.

Along with the processor core, which processes the instructions you give it, the silicon chip has a small memory area for storing your commands, called program memory and random-access memory (RAM), which is used to keep track of things while the program is running. It also has input and output peripherals to handle sending and receiving data, either in the real world or to other computers, and with the correct code, to the Internet.

Microcontrollers were invented in the early 1970s to do all sorts of everyday automation tasks for industry. Your Arduino uses the single-chip ATmega328 microcontroller, which is part of the AVR family of products from the chipmaker Atmel and was originally developed in the mid-1990s.

The best part about microcontrollers is that they are inexpensive, unlike their big brothers, the microprocessors in your computer, laptop, tablet, or phone. Microcontrollers are inexpensive because they have limited capabilities (see Figure 1-2). They are mainly designed to control things or otherwise respond to sensory input, and are called embedded systems. Bigger computers have more general capabilities and need more power and therefore, cost more, and use general purpose microprocessors.

Because they are inexpensive, you can use them for all kinds of small computing tasks that don’t need a full-size computer, like opening your front door with a code. The microcontroller on your Arduino costs less than a couple of bucks. The rest of the cost of an Arduino comes from all the convenient things that are onboard that help you to send programs to it and interact with the world.

Using tiny computers to do useful stuff

Microcontrollers are the unseen helping hands that are all around us, working tirelessly all the time to make modern life convenient and pleasant. They open doors for us (literally), keep us entertained, and can make a pretty decent cup of coffee. They also ensure that we get from Point A to Point B safely, being embedded in planes, trains, and yes, automobiles. Here are a few examples of what we use them for and similar projects in this book. It’s not an exhaustive list, but it should give you an idea of what microcontrollers are used for and how ubiquitous they are!

Toys and games

If you walk into a toy store these days, you come across hundreds of devices that walk, talk, blink, flash, and even respond to how you position their parts or speak to them. Even very inexpensive interactive toys have embedded microcontrollers that perform the same functions as an Arduino. They are usually very tiny and specially designed for mass production and are often hidden under a dab of epoxy on the printed circuit board (PCB) inside the toy, as shown in Figure 1-3. In fact, some products may even use a microcontroller from the same Atmel family. They are programmed at the factory to respond to input and actuate lights, sounds, and movements.

Although it’s not interactive, the light pet in Chapter 5 is a simple, preprogrammed toy like many you might see in a store. It’s not interactive, but by the time you finish a few projects in this book, you’ll be able to make it respond interactively to light, touch, temperature, or other kinds of input.

Home appliances

Your kitchen is almost literally a digital mission control center. A major proportion of the electronic appliances you use to whip up a meal have a microcontroller in them. The microwave has a timer to control power changes and timing. The oven has similar capabilities. A coffee machine also has a timing function and different programs for brewing different cups of java. Advanced food processors sense the consistency of the food mixture and have safety shutoffs. All of these capabilities are done with embedded microcontrollers that sense and respond to the world.

The Arduino Clock in Chapter 7 gives you a taste of what’s possible and describes how to build a programmable alarm. With a little further research, you could even hook up its alarm to kick off your own cup of brew!

9781118551479-fg0103.tif

Figure 1-3: A close-up view of a toy’s microcontroller hidden under epoxy.

Automated manufacture

If you are building lots of components into a single product, automation is essential and microcontrollers assist with the process. Whether it’s a child’s toy car or a real car, microcontrollers embedded into the assembly line ensure the precise placement of parts, test for errors in manufacture, adjust the feed of subcomponents, track inventory, and perform other useful functions. Their core capability of sensing the environment and responding quickly, and according to a fixed program, ensures that manufactured products are consistently built and product inventories carefully managed.

The radio frequency ID (RFID) reader in Chapter 9 uses the same RFID technology that many inventory tracking systems use to manage raw materials, parts, and inventory warehouses.

Field sensing and response

Microcontrollers can be placed into conditions where it is simply impractical or downright dangerous to place a human. Imagine you want to ensure that a leak in a gas pipeline doesn’t progress into a full-scale explosion. A microcontroller embedded in the line can ensure that the supply is switched off if a pressure leak is detected. Similarly, you wouldn’t want to pay someone to monitor moisture levels in a greenhouse. A microcontroller can activate a spray of water at a fixed interval or according to measured environmental conditions.

The automated plant irrigator in Chapter 10 is a household version of this very useful capability.

Building automation

You are familiar with building security systems to keep out intruders. Along with this, many buildings are now using sensors to detect the internal climate and energy efficiency conditions. Architects now design many modern structures with a “nervous system” of embedded sensors that can adjust heating and cooling automatically, in specific zones or individual rooms, and with the use of energy-efficient heating, cooling, and air handling.

The home sensing project in Chapter 12 is a mini-sized version of a sensor network that you can build in your own home.

Process control

Microcontrollers are used in industry for things such as assembly line control and sensing. For example, microcontrollers can test to find out if all bottles in a line have been filled to the correct level. Microcontrollers attached to sensors can quickly and easily detect problems and either report the fill problem to a central computer or actuate a system to remove the bottle from the line. This can be done much faster than any human could do it. Many product manufacturing processes use microcontrollers because they are cheap and reliable. Similarly, mixing up the raw materials for batches of bread, candy, petroleum products, or concrete can be precisely monitored and controlled with microcontrollers like the one on an Arduino.

Although none of the projects in this book does quite this kind of thing, after you’ve built a few of them you can figure out how to modify, prototype, and pick and choose from the features you want to build into a project to control many different kinds of processes or activities.

Getting Started

If you haven’t already jumped into the middle of the book to check out what you can do, stop now and take a peek. I wrote this book to get you going with some cool Arduino projects so that you can make something amazing that nobody has dreamed up yet. I hope these projects inspire you. Poking around online may provide additional fuel for your creative fire.

Before you get going, though, it’s a good idea to assemble a few tools that will make your Arduino adventures a bit easier. All the projects in this book require some basic tools — and an Arduino. If you are going to dive right in, more power to you. But do take a minute to peruse Chapter 2 to get together a few of the tools you’ll need. If you have never used an Arduino before, check out Chapter 3, which covers some of the basics you need to know before you dive into a project.

So what are you waiting for? Take the plunge and get going!