The Arduino Inventor's Guide (2 page)

BOOK: The Arduino Inventor's Guide
10.76Mb size Format: txt, pdf, ePub
THE ARDUINO INDENTOR’S GUIDE

LEARN ELECTRONICS BY MAKING 10 AWESOME PROJECTS

BRIAN HUANG

DEREK RUNBERG

SAN FRANCISCO

THE ARDUINO INVENTOR’S GUIDE.
Copyright © 2017 by SparkFun Electronics.

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN-10: 1-59327-652-4
ISBN-13: 978-1-59327-652-2

Publisher: William Pollock
Production Editors: Alison Law and Riley Hoffman
Cover Illustration: Brian Cook
Interior Design: Beth Middleworth
Photographer: Juan Peña
Illustrations: Pete Holm
Developmental Editors: Jennifer Griffith-Delgado and Liz Chadwick
Technical Reviewer: Daniel Hienzsch
Copyeditor: Rachel Monaghan
Compositors: Susan Glinert Stevens and Riley Hoffman
Proofreader: Lisa Devoto Farrell

The following image is reproduced with permission:
Figure 8-1
© Richard Hall.
Circuit diagrams and schematics were created using Fritzing (
http://fritzing.org/
).

For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:

No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900;
[email protected]
www.nostarch.com

Library of Congress Cataloging-in-Publication Data

Names: Huang, Brian, author. | Runberg, Derek, author.

Title: The Arduino inventor's guide: learn electronics by making 10 awesome

   projects / Brian Huang and Derek Runberg.

Description: San Francisco : No Starch Press, Inc., [2017]

Identifiers: LCCN 2017005801 (print) | LCCN 2017023025 (ebook) | ISBN

   9781593278397 (epub) | ISBN 159327839X (epub) | ISBN 9781593278403 (mobi)

   | ISBN 1593278403 (mobi) | ISBN 9781593276522 (pbk.) | ISBN 1593276524

   (pbk.)

Subjects: LCSH: Arduino (Programmable controller) | Electronics--Amateurs'

   manuals.

Classification: LCC TJ223.P76 (ebook) | LCC TJ223.P76 R86 2017 (print) | DDC

   006.2/2--dc23

LC record available at
https://lccn.loc.gov/2017005801

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the authors nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.

TO LINDSAY DIAMOND, FOR YOUR AMAZING LEADERSHIP AND GUIDANCE; TO THE ENTIRE TEAM AT SPARKFUN; AND TO ALL THE FUTURE TINKERERS AND INVENTORS WE INSPIRE!

About Sparkfun Electronics

SparkFun is an online retailer that produces and sells the widgets and parts that end up in a lot of maker projects, prototypes, and even the International Space Station. Nathan Seidle started the company after blowing a circuit board in 2003, while he was an undergraduate at the University of Colorado Boulder. At the time, circuit boards were really hard to get; you had to fax your credit card to another country and hope that you got your hardware in six to eight weeks. Nathan felt he could do better, and he did. SparkFun. com was born, and it now sells over 3,000 different parts of all shapes and sizes for your digital electronic needs. From a basic Arduino to GPS modules, you can find them and all of the documentation you need to get up and running at SparkFun.

SparkFun’s Department of Education develops curricula and runs professional development programs for educators of all kinds. The department is at the forefront of a number of computer science and maker initiatives that are making headway in the classroom. You can learn more about SparkFun and the Department of Education at
https://www.sparkfun.com/
and
http://www.sparkfuneducation.com/
.

About the Authors

Brian Huang and Derek Runberg were both teachers at one point. Brian was a high school physics teacher with an affinity for robots, and Derek was a middle school technology teacher obsessed with pushing the limits of middle school students. They’ve taken very different paths to get where they are now, including how they learned programming and electronics, their teaching philosophies, and their viewpoints on how students learn, so they are a bit of an odd couple. They hope that this book will serve you well as you set off on your adventure into the world of inventing.

About the Technical Reviewer

Daniel Hienzsch is the founder of Rheingold Heavy, which delivers educational content and materials to electronics enthusiasts and students. He previously worked in IT for 20 years, including 10 years as the IT director for an investment bank. Dan is passionate about education, and Rheingold Heavy is his effort to provide the maker community with materials he wished he had when he was first getting started in electronics and technology. He is also a certified scuba instructor.

A Note from Brian

Although I am a formally trained engineer (I went to school to study electrical engineering), my education focused a lot on theory, simulations, and modeling, and I was never taught how to solder, machine, or really build things. After graduating from college, I worked as an engineer during the week, and found myself volunteering at the Science Museum of Minnesota on the weekends. It was at the museum where I discovered my love of teaching. I was given the opportunity to inspire children to be curious, ask questions, and wonder about the world. My experiences in the museum set me on a course to change careers, pursue a master’s in education, and become a high school physics teacher.

Derek and I complement each other’s experience and background. This book is a culmination of both of our experiences in teaching and in learning how best to use Arduino in the classroom. As Derek puts it, the Arduino is simply another material that we use in our projects. The faculty and students at NYU’s Integrated Telecommunications Program (ITP) have long known this. The way you interact with electronics changes immediately when you enclose or cover them. Even something as simple as using a ping-pong ball to diffuse an LED immediately affects your interaction with the project. The way the light diffuses and blends through materials teases your emotions in a way that you wouldn’t get with just an LED in a breadboard.

We’ve put a lot of thought into how to make learning electronics and programming accessible for anyone. We hope that these projects will help to unleash your inner inventor!

A Note from Derek

Unlike Brian, I have no formal background in electronics or computer programming; I am completely self-taught. I learned Arduino so that I could give my students access to a technology they could control and build with. I was a middle school technology teacher asked to dream up a shop class for the 21st century. Electronics was part of that vision, and over a three-year process, Arduino (and, later, the Processing language) took center stage in my classroom. I learned electronics and programming so that I could teach it in my class.

Many of these projects come directly from my classroom experience teaching Arduino. My students learned computer science and electronics out of necessity, in order to develop their ideas rather than have a teacher telling them “because you need to.” I hope that my contribution to this book honors my students and puts electronics and programming into a format that sparks your imagination.

Contents in Detail

Introduction

What is This Book About?

Why Arduino?

How is This Book Different from Others?

Materials

Required Tools

Required Computer

What’s in This Book?

Online Resources

Spread the Word: Sharing Your Work

Electronics Primer

Electricity, Conductivity, and Basic Terms

What Is Electricity?

Types of Electricity

What Is a Circuit?

Ohm’s Law

Visualizing Electricity as Water in a Pipe

Schematics, Circuit Blueprints, and Wiring Diagrams

Prototyping Circuits

Discrete Components vs. Breakout Boards

Analog vs. Digital

What Is A Microcontroller?

Project 1
Getting Started with Arduino

Materials to Gather

About the Arduino

An Accessible Hardware Platform

About the SparkFun RedBoard

Installing the Arduino IDE and Drivers

Installing on Windows

Installing on OS X

Installing on Linux

A Brief IDE Tour

Changing the Default Preferences

Test Drive: Plugging in the Arduino for the First Time

Choosing Your Board in the IDE

Selecting the Communication Port

An Arduino “Hello, World!”

Basic Arduino Troubleshooting

Anatomy of an Arduino Sketch

Key Sketch Elements

The setup() Function

The loop() Function

Your First Piece of Hardware

Going Further

Hack

Modify

Saving Your Sketch

Project 2
A Stoplight for Your House

Materials to Gather

Electronic Parts

Other Materials and Tools

New Component: The Resistor

Build the Stoplight Prototype

Connect the Red LED to the Breadboard

Add Power to the Breadboard

Add the Yellow and Green LEDs

Program the Stoplight

Confirm Your IDE Settings

Create Placeholders for Pin Numbers

Write the setup() Function

Write the loop() Function

Upload the Sketch

Make the Stoplight Portable

Build the Stoplight Enclosure

Cardboard Construction

Make the Stoplight Lenses

Make the Shades

Mount the LEDs and Arduino

Going Further

Hack

Modify

Project 3
The Nine-Pixel Animation Machine

Materials to Gather

Electronic Parts

Other Materials and Tools

Build the Nine-Pixel Animation Machine Prototype

Program the Nine-Pixel Animation Machine

What Are Custom Functions?

Design Your Artwork

The Test Sketch

Build the Nine-Pixel Animation Machine Enclosure

Cardboard Construction

Connect the Electronics

Create an Led Animation

Plan the Animation Sequence

Write Custom Functions

Tweak Your loop() Function

Going Further

Hack

Modify

Project 4
Reaction Timer

Materials to Gather

Electronic Parts

Other Materials and Tools

New Component: The Push Button

How Push Buttons Work

Using Resistors with Push Buttons

Build the Reaction Timer Prototype

Program the Reaction Timer

Write the setup() Function

Write the loop() Function

Test the Reaction Timer Sketch

Play Again?

Add a Game Element

Upload the Complete Code for the Reaction Timer

Build the Reaction Timer Enclosure

Cut Out the Cardboard

Assemble the Electronics

Spice Up Your Game Enclosure

Going Further

Hack

Modify

Project 5
A Color-Mixing Night-Light

Materials to Gather

Electronic Parts

Other Materials and Tools

New Components

The RGB LED

The Photoresistor

Build the Night-Light Prototype

Wire the Voltage Divider

Wire the RGB LED

Test the Night-Light with Basic Color Mixing

Program the Night-Light

Prepare to Check the Light Level

Control the Night-Light Based on the Light Level

Prevent False Alarms

Recalibrate the Night-Light

Create More Colors with Analogwrite()

Create Analog Signals with PWM

Mix Colors with analogWrite()

Find RGB Values with Color Picker

The Custom-Color Night-Light Code

Build the Night-Light Enclosure

Cardstock Construction

Put the Electronics Inside

Let It Glow!

Going Further

Hack

Modify

Project 6
Balance Beam

Materials to Gather

Electronic Parts

Other Materials and Tools

New Components

The Potentiometer

The Servo Motor

Build the Balance Beam Prototype

Program the Balance Beam

Test the Servo

Complete the Balance Beam Sketch

Build the Balance Beam

Cut Out the Parts

Build the Beam

Build the Base and Attach the Servo

Final Assembly

Going Further

Hack

Modify

Project 7
Tiny Desktop Greenhouse

Materials to Gather

Electronic Parts

Other Materials and Tools

New Components

TMP36 Temperature Sensor

Standard Hobby Motor

NPN Transistor

Taking a Systems Approach

Build the Temperature Monitor

Measure Temperature with the TMP36

Connect the Temperature Sensor

Program the Temperature Sensor

Build the Servo Motor Autovent

Program the Autovent

Build the Fan Motor

Program the Fan Motor

Isolate the Motor Effect

Build the Tiny Desktop Greenhouse Enclosure

Add the Autovent Window Servo

Create the Paper Clip Linkage

Add the Roof

Build the Fan-Motor Box

Connect It Up

Going Further

Hack

Modify

Project 8
Drawbot, The Robotic Artist

Materials to Gather

Electronic Parts

Other Materials and Tools

New Components

The H-Bridge Motor Driver Integrated Circuit

Geared Hobby Motor

Build the Drawbot Prototype

Program the Drawbot

Create a Custom Function

Clean Up the Code

Wire the Second Motor

Drive Both Motors

Build the Drawbot Chassis

Test and Troubleshoot

Turn and Make Patterns: A Robot Square Dance

Going Further

Hack

Modify

Bonus

Project 9
Drag Race Timer

Materials to Gather

Electronic Parts

Other Materials and Tools

New Component: The 16 × 2 Character LCD

Drag Race Timer Operation

Build the LCD Circuit

Power the LCD

Control the Contrast

Connect the Data and Control Wiring

Test the LCD

Add the Rest of the Electronics

Program the Drag Race Timer

A Quick Test

Build the Drag Race Track

Build the Starting Tower

Assemble the Starting Gate

Build Your Own Track

Add the Photoresistor

Test and Troubleshoot

Going Further

Hack

Modify

Project 10
Tiny Electric Piano

Materials to Gather

Electronic Parts

Other Materials and Tools

New Components

The SoftPot Membrane Potentiometer

The Piezo Buzzer

Build the Circuit

Program the Tiny Electric Piano

Test the Buzzer

Create Specific Notes

Generate Sound with the SoftPot

Play a Song

Build the Piano

Going Further

Hack

Modify

Bonus Project: Binary Trumpet

Appendix
More Electronics Know-How

Measuring Electricity with a Multimeter

Parts of a Multimeter

Measuring Continuity

Measuring Resistance

Measuring Voltage

Measuring Current

How to Solder

Heating the Iron

Perfecting Your Soldering Technique

Cleaning the Iron

Soldering Tips

Additional Soldering Tools

Third Hand

Flux Pen

Solder Wick

Solder Vacuum

Resistors and Bands

Afterword

Additional Resources

Acknowledgments

Other books

EHuman Dawn by Anderson, Nicole Sallak
Something Of A Kind by Wheeler, Miranda
Survival Instinct by Kay Glass
When A Plan Comes Together by Jerry D. Young
Old Habits by Melissa Marr
Caribbean by James A. Michener
Romance of a Lifetime by Carole Mortimer
The Chocolate Thief by Laura Florand
Broken Wings by L-J Baker