9781449360665 Preview Datasheet by O'Reilly Media

View All Related Products | Download PDF Datasheet
BASIC ”new nnnnnnn
Technology & Engineering / Electronics
Basic Arduino Projects
By building and experimenting with the 26 projects
outlined in this book, you will learn how to:
Written for new makers,
Basic Arduino Projects
is a practical guide
containing 26 projects that you can start on immediately. Learn to
build electronic circuits that change their behavior, a light-sensitive
switch, and LED projects like the pocket stage light. Youll learn
how to control servo motors (the building blocks of robots) and to
create audio projects like a theremin, electronic cricket, and
metronome. The only restriction is your imagination.
This book is the perfect companion to the Make: Getting Started
with Arduino-Deluxe Kit which contains 100+ piecesfrom the
basics, like the Arduino board, breadboards, resistors, capacitors
LEDs, and jumper wires, to the fun stuff like servos, switches,
sensors, buttons, motors, LCD screen—and more! The kit will
jump-start your projects!
» Use the Arduino as a programmable computer brain
» Create electronic controllers for LEDs and servo motors
» Draw colors on your computer screen by pushing a button
» Detect changes in temperature and notify your computer
» Use an LCD display to show text and special characters
» Control a motor’s movements with a tilt sensor
» Build four projects that combine Arduino with the Processing
visual programming language
» Make your own ohmmeter and logic testers
Make:
makezine.com
Don Wilcher
US $19.99 CAN $20.99
ISBN: 978-1-4493-6066-5
Basic Arduino Projects
Start making today. 26 Experiments with
Microcontrollers and Electronics
Don Wilcher
Make:
BASIC
Arduino
Projects
D
e
l
u
x
e
K
i
t
C
o
m
p
a
n
i
o
n
t
o
t
h
e
Make:
Getting
Started
with Arduino
MEDIA SEBASTOPOL, CA
Make: Basic
Arduino
Projects
26 Experiments with Microcontrollers
and Electronics
Don Wilcher
Make: Basic Arduino Projects
by Don Wilcher
Copyright © 2014 Don Wilcher. All rights reserved.
Printed in the United States of America.
Published by Maker Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
Maker Media books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safaribooksonline.com). For more in-
formation, contact O’Reilly Media’s corporate/institutional sales department:
800-998-9938 or corporate@oreilly.com.
Editor: Patrick Di Justo
Production Editor: Kara Ebrahim
Copyeditor: Charles Roumeliotis
Proofreader: Jasmine Kwityn
Indexer: Ellen Troutman
Cover Designer: Juliann Brown
Interior Designer: David Futato
Illustrator: Rebecca Demarest
Photographers: Frank Teng and Don Wilcher
February 2014: First Edition
Revision History for the First Edition:
2014-02-05: First release
2014-03-07: Second release
2015-10-23: Third release
See http://oreilly.com/catalog/errata.csp?isbn=9781449360665 for release details.
The Make logo and Maker Media logo are registered trademarks of Maker Media, Inc. Make:
Basic Arduino Projects and related trade dress are trademarks of Maker 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 Maker Media,
Inc., was aware of a trademark claim, the designations have been printed in caps or initial
caps.
While every precaution has been taken in the preparation of this book, the publisher and
author assume no responsibility for errors or omissions, or for damages resulting from the
use of the information contained herein.
ISBN: 978-1-449-36066-5
[LSI]
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1. The Trick Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Let’s Build a Trick Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Trick Switch with On/Off Indicators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2. Sunrise-Sunset Light Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Let’s Build a Sunrise-Sunset Light Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Sunrise-Sunset Detector with Serial Monitor. . . . . . . . . . . . . . . . . . . . . . . . . 14
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3. Tilt Sensing Servo Motor Controller. . . . . . . . . . . . . . . . . . . . . . . . . . 19
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Let’s Build a Tilt Sensing Servo Motor Controller. . . . . . . . . . . . . . . . . . . . . . 20
Upload the Tilt Sensor Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
A Simple Animatronic Controller Using the Serial Monitor. . . . . . . . . . . . . 24
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4. Twin LEDs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
iii
Contents
Twin LED Flasher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Build the Adjustable Twin LED Flasher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Its Alive! Build a FrankenBot Toy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5. The Opposite Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
The Opposite Switch (aka the NOT Logic Gate). . . . . . . . . . . . . . . . . . . . . . . 45
Build an Arduino NOT Logic Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Upload the Arduino NOT Logic Gate Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . 46
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
6. The AND Logic Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
The Arduino AND Logic Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Upload the Arduino AND Logic Gate Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . 57
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7. The OR Logic Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
The Arduino OR Logic Gate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Upload the Arduino OR Logic Gate Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8. Tilt Flasher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Up-Down Sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9. Multicolor RGB Flasher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The RGB Flasher. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
iv Contents
10. The Magic Light Bulb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Let’s Build a Magic Light Bulb. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Upload the Magic Light Bulb Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
11. Metal Checker: The Electronic Switch. . . . . . . . . . . . . . . . . . . . . . . . 95
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Let’s Build a Metal Checker. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Upload the Metal Checker Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
12. The Theremin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Let’s Build a Theremin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Upload the Theremin Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
13. An Arduino Ohmmeter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Let’s Build an Arduino Ohmmeter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Upload the Arduino Ohmmeter Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
14. The LCD News Reader. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Let’s Build the LCD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Upload the LCD News Reader Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
15. A Logic Tester (with an RGB LED). . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Let’s Build a Logic Tester. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Contents v
Upload the Logic Tester Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
16. A Logic Tester (with an LCD). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Let’s Build a Logic Tester. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Upload the Logic Tester Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Circuit Theory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
17. The Amazing Pushbutton (with Processing). . . . . . . . . . . . . . . . . 143
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Let’s Build an Amazing Pushbutton. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Upload the Amazing Pushbutton Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Download and Install Processing Notes. . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Let’s Visualize Digital Data with Processing. . . . . . . . . . . . . . . . . . . . . . . . . . 148
Troubleshooting Tips for Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
18. The Terrific Tilt Switch (with Processing). . . . . . . . . . . . . . . . . . . . 157
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Let’s Build a Terrific Tilt Switch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Upload the Terrific Tilt Switch Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Let’s Visualize Digital Data with Processing. . . . . . . . . . . . . . . . . . . . . . . . . . 162
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
19. The Rocket Launching Game (with Processing). . . . . . . . . . . . . . 169
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Let’s Build a Rocket Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Upload the MultiDigital4 Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
The Rocket Launcher with Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
20. Temperature Indicator (with Processing). . . . . . . . . . . . . . . . . . . . 183
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Let’s Build a Temperature Indicator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Upload the Temperature Indicator Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . 185
vi Contents
The Negative Temperature Coefficient (NTC) Sensor with Processing. . . 188
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
21. Sweeping Servo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Let’s Build a Servo Motor Tester. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Upload the Sweeping Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
22. Electronic Cricket. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Let’s Build an Electronic Cricket. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Upload the Electronic Cricket Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
23. A Pocket Stage Light. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Let’s Build a Pocket Stage Light. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Upload the Pocket Stage Light Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
24. Electronic Pixel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Let’s Build an Electronic Pixel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Upload the Electronic Pixel Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
25. The Metronome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Let’s Build a Metronome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Upload the Metronome Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
26. The Secret Word Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Parts List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Let’s Build a Secret Word Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Upload the Secret Word Game Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Rules for the Secret Word Game. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Something to Think About. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Contents vii
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
viii Contents
So, you’ve been playing around with Arduino, but are looking for some fun projects
to try out with it. Make: Basic Arduino Projects is here to help you! Its got a wealth of
cool devices and gadgets to build with Arduino and some common components.
The projects in the book explain the world of electronics using a fun and hands-on
approach.
The motivation behind writing this book is based on several conversations with
Brian Jepson (Make: books’ Publisher) and the need for a book that allows people
to explore Arduino and the universe of electronic parts that go along with it. The
Arduino is a very popular Maker platform that allows you to explore electronics with
an interactive approach. As awesome as a box of parts is, it’s difficult for people with
little electronics experience to begin making things with it. This book solves that
problem by letting you learn more about electronics while you make fun projects
with the parts in this kit. Basic Arduino Projects is a practical guide that illustrates
how a bunch of electronic parts, coupled with Arduino, can be transformed into
awesome devices and gadgets for education and play.
In addition, being an electrical engineer and educator, I’m very sensitive to deliver-
ing good instructional content to my students (adults and teenagers). This book was
written to attract young readers to the exciting world of electronics by building cool
and creative projects using Arduino. This book is also intended for Makers and novi-
ces who have heard about the Arduino but never experienced the fun and excite-
ment that comes from building cool electronic gadgets and devices with this open
hardware platform.
By building and experimenting with the projects in this book, young readers, Mak-
ers, and electronic novices will learn how to:
Read electronic circuit schematic and block diagrams.
Assemble electronic circuits using the MakerShield prototyping board.
ix
Preface
Build basic logic circuits using the Arduino as a programmable computer brain.
Use an LCD display for displaying text and special characters.
Create simple electronic controllers for LEDs and servo motors.
Last, you will learn how to create gadgets and devices for education and play using
imagination and some common electronic components. Enjoy the Maker adven-
ture!
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program
elements such as variable or function names, databases, data types, environ-
ment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values
determined by context.
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at
http://www.family-science.net/electro_arduino.htm.
This book is here to help you get your job done. In general, if example code is offered
with this book, you may use it in your programs and documentation. You do not
need to contact us for permission unless you’re reproducing a significant portion of
the code. For example, writing a program that uses several chunks of code from this
book does not require permission. Selling or distributing a CD-ROM of examples
from O’Reilly books does require permission. Answering a question by citing this
x Preface
Safari
book and quoting example code does not require permission. Incorporating a sig-
nificant amount of example code from this book into your product’s documentation
does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Make: Basic Arduino Projects by Don
Wilcher (Maker Media). Copyright 2014 Don Wilcher, 978-1-449-36066-5.
If you feel your use of code examples falls outside fair use or the permission given
here, feel free to contact us at bookpermissions@makermedia.com.
Safari® Books Online
Safari Books Online is an on-demand digital library that delivers
expert content in both book and video form from the world’s
leading authors in technology and business.
Technology professionals, software developers, web designers, and business and
creative professionals use Safari Books Online as their primary resource for research,
problem solving, learning, and certification training.
Safari Books Online offers a range of product mixes and pricing programs for or-
ganizations, government agencies, and individuals. Subscribers have access to
thousands of books, training videos, and prepublication manuscripts in one fully
searchable database from publishers like MAKE, O’Reilly Media, Prentice Hall Pro-
fessional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press,
Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Red-
books, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill,
Jones & Bartlett, Course Technology, and dozens more. For more information about
Safari Books Online, please visit us online.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
MAKE
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
MAKE unites, inspires, informs, and entertains a growing community of resourceful
people who undertake amazing projects in their backyards, basements, and
garages. MAKE celebrates your right to tweak, hack, and bend any technology to
your will. The MAKE audience continues to be a growing culture and community
that believes in bettering ourselves, our environment, our educational system—our
Preface xi
entire world. This is much more than an audience, it’s a worldwide movement that
Make is leading—we call it the Maker Movement.
For more information about MAKE, visit us online:
MAKE magazine: http://makezine.com/magazine/
Maker Faire: http://makerfaire.com
Makezine.com: http://makezine.com
Maker Shed: http://makershed.com/
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at http://oreil.ly/basic-arduino.
To comment or ask technical questions about this book, send email to bookques
tions@oreilly.com.
Acknowledgments
I would like to thank Brian Jepson (Publisher) for believing in the book concept and
allowing me to explore Arduino in creative ways. Also, I would like to thank Patrick
Di Justo (Editor) for pulling out the really cool projects from the original book pro-
posal and coaching me to present them in fun and entertaining ways for young
readers.
My final acknowledgment goes to my wife, Mattalene, who patiently worked with
me on editing this book, keeping me on task with the writing/project builds, and
reviewing the email revision messages from my editors. To my children, Tiana,
D’Vonn, and D’Mar, thanks for being great kids while I worked on the book during
family time.
xii Preface
Resistor-Capacitor Timing Basics
In electronics, sometimes we want to keep a device on for a certain amount of time
even when an electrical switch is turned off. Ordinary pushbuttons used to turn
electronic devices on and off can easily be operated by a timed delay switch. How
awesome would it be to create such a device to delay turning off a simple LED? Such
a gadget could be used to trick your friends, family, or even the local Makerspace
when they see the LED staying on after the pushbutton has been released. With a
few electronic components, you can make an LED (light-emitting diode) stay on for
a few extra seconds when a pushbutton switch is turned off. Figure 1-1 shows an
assembled Trick Switch. The electronic components required to build the Trick
Switch are shown in the Parts List.
Parts List
Arduino microcontroller
SW1: mini pushbutton
LED1: red LED
C1: 100 uF electrolytic capacitor
R1: 10K ohm resistor (brown, black, orange stripes)
R2: 330 ohm resistor (orange, orange, brown stripes)
Full-size clear breadboard
1
The Trick Switch 1
m n um 12 mmm um um Rm nan
Figure 1-1. Trick Switch circuit built on a full-size clear breadboard (both the 100 uF electrolytic
capacitor and red LED negative pins are wired to ground)
Tech Note
You can create your own electrical circuits and test them using dia-
grams with an online simulator called Circuit Lab.
Let’s Build a Trick Switch
When you press the pushbutton switch on this device, the LED turns on. The ca-
pacitor will begin storing electrical energy from the +5VDC power supply circuit of
the Arduino. Releasing the pushbutton switch cuts off the flow of electricity from
the source, but the energy stored in the capacitor keeps the Arduino running for a
few extra seconds. The Arduino keeps the LED lit until the capacitor’s stored energy
is empty. You can build the Trick Switch using the electronic components from the
Parts List and the Fritzing wiring diagram shown in Figure 1-2. Here are the steps
required to build the electronic device:
1. Place the required parts on your workbench or lab tabletop.
2. Wire the electronic parts using the Fritzing wiring diagram of Figure 1-2 or the
actual Trick Switch device shown in Figure 1-1.
3. Type the Pushbutton sketch shown in Example 1-1 into the Arduino text editor.
2 Make: Basic Arduino Projects
3‘ In MW mm Pmmn
4. Upload the Pushbutton sketch to the Arduino.
5. Press the mini pushbutton for a moment. The red LED turns on. After one to
two minutes, the red LED will turn off.
Figure 1-2. Trick Switch Fritzing diagram
Troubleshooting Tip
If the Trick Switch device doesn’t work, check for incorrect resistor
values, incorrect wiring, sketch typos, and improper orientation of
polarized electronic components (the LED and capacitor).
Example 1-1. Pushbutton sketch
/*
Pushbutton Sketch
Reads the capacitor voltage at digital pin 2 and turns on and off a light-
emitting diode (LED) connected to digital pin 12.
17 Nov 2012
by Don Wilcher
Chapter 1: The Trick Switch 3
*/
// constants won't change; they're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
// variables will change:
int buttonStatus = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the status of the pushbutton value:
buttonStatus = digitalRead(buttonPin);
// check if the pushbutton is pressed
// if it is, the buttonEvent is HIGH:
if (buttonStatus == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Tech Note
The ledPin value can be changed to 13 to operate the onboard LED.
Trick Switch with On/Off Indicators
In developing new products, electronics designers are always improving designs by
adding features and functions that excite the customer. The Trick Switch device you
built can be improved by adding an LED indicator. This LED indicates when the Trick
Switch timing cycle is done. Figure 1-3 shows you where to add a green LED to the
Trick Switch on the full-size clear breadboard.
4 Make: Basic Arduino Projects
Figure 1-3. Adding a green LED indicator to the Trick Switch circuit built on a full-size clear
breadboard
To complete the new product design, you need to make a few changes to the Push-
button sketch. Modify the sketch using the code changes shown in Example 1-2.
Example 1-2. Pushbutton sketch modified to include LED indicators
// constants won't change; they're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 12; // the number of the LED pin
const int ledPin13 = 13; // onboard LED
void setup() {
// initialize the LED pins as outputs:
pinMode(ledPin, OUTPUT);
pinMode(ledPin13, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
int buttonStatus;
buttonStatus = digitalRead(buttonPin);
// check if the pushbutton is pressed
// if it is, the buttonStatus is HIGH:
if (buttonStatus == HIGH) {
Chapter 1: The Trick Switch 5
Mmi Timed Pushbunan Delay (mun Nduina Red [ED
// turn LED on:
digitalWrite(ledPin, HIGH);
// turn off onboard LED:
digitalWrite(ledPin13,LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
// turn on onboard LED:
digitalWrite(ledPin13, HIGH);
}
}
After you’ve saved the sketch changes and uploaded them to the Arduino, the green
LED will turn on. When you press the mini pushbutton, the green LED will turn off,
and the red LED will turn on. Pretty awesome stuff. Enjoy!
The block diagram in Figure 1-4 shows the electronic component blocks and the
electrical signal flow for the Trick Switch. A Fritzing electronic circuit schematic di-
agram of the switch is shown in Figure 1-5. Electronic circuit schematic diagrams
are used by electrical/electronic engineers to design and build cool electronic prod-
ucts for society.
Figure 1-4. Trick Switch block diagram
Something to Think About
Try different resistor and capacitor values and see what happens. Can you detect
any patterns? How can a small piezo buzzer be used with the Trick Switch?
6 Make: Basic Arduino Projects
7—\ S‘ m uwN _w_m_w___m_m__m_ WI: mmmmmmmmummmmmmm Im gangs—Ema m, m mm m m N I" 5w 5.3.: mmwm wmnnMu I: :2: x mm a .: m. mmn Sx
Figure 1-5. Trick Switch circuit schematic diagram
Chapter 1: The Trick Switch 7

Products related to this Datasheet

MAKE: BASIC ARDUINO PROJECTS