Table Of Contentwww.allitebooks.com
No Starch preSS
e arly acceSS progr am:
Feedback welcome!
Welcome to the Early Access edition of the as yet unpublished Arduino
Playground by Warren Andrews! As a prepublication title, this book may
be incomplete and some chapters may not have been proofread.
Our goal is always to make the best books possible, and we look forward
to hearing your thoughts. If you have any comments or questions, email us
at earlyaccess@nostarch.com. If you have specific feedback for us, please
include the page number, book title, and edition date in your note, and
we’ll be sure to review it. We appreciate your help and support!
We’ll email you as new chapters become available. In the meantime,
enjoy!
www.allitebooks.com
arduiNo p l aygrouNd
warreN aNdrewS
Early Access edition, 9/8/16
Copyright © 2016 by Warren Andrews.
ISBN-10: 1-59327-744-X
ISBN-13: 978-1-59327-744-4
Publisher: William Pollock
Production Editor: Laurel Chun
Cover Illustration: Josh Ellingson
Developmental Editor: Jennifer Griffith-Delgado
Technical Reviewer: Scott Collier
Copyeditor: Julie Jigour
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 trade-
marked 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.
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 informa-
tion storage or retrieval system, without the prior written permission of the copyright owner
and the publisher.
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 author 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.
www.allitebooks.com
Brief Contents
Chapter 1: The Reaction-Time Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2: An Automated Agitator for PCB Etching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Chapter 3: The Regulated Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Chapter 4: A Watch Winder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Chapter 5: The Garage Sentry Parking Assistant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Chapter 6: The Battery Saver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Chapter 7: A Custom pH Meter
Chapter 8: The Ballistic Chronograph
Chapter 9: The Square Wave Generator
Chapter 10: The Rainbow Thermometer
Appendix
www.allitebooks.com
www.allitebooks.com
Contents in De tail
1
The ReacTion-Time machine 1
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Reaction vs . Reflex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
How Does the Game Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Measuring Time with the Arduino Nano . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Expected Speed Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Arduino Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Customized Reaction Commentary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
What Happens in the Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Preparing a Sturdy Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Mounting the Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Ideas for Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2
an auTomaTed agiTaToR foR PcB eTching 17
Special Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
How Automatic Motor Reversal Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Determining the Reversal Threshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Using an H-Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
PCB Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Shield Design Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Limit Wires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
The Crank Bushing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Packaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
The Etching Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3
The RegulaTed PoweR SuPPly 45
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Required Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
A Flexible Voltage Regulator Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
How the Circuit Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
www.allitebooks.com
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Preparing the Arduino Pro Mini and LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Building the Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
The Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Preparing the Enclosure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Mounting the Circuit Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4
a waTch windeR 65
Why a Watch Winder? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Required Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Acrylic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Other Hardware and Circuit Components . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Basic Watch Winder Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Using an Arduino to Control Winder Revolutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Using a Hall Effect Sensor to Monitor Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
The Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
The Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Overview of the Motor Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Preparing the Motor Plate and Bearing Box Acrylic . . . . . . . . . . . . . . . . . . . . 87
Bonding the Acrylic for the Bearing Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The Stand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Preparing the Motor and the Driveshaft . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Making the Watch Basket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Adding the LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Leaving the Components on Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Keeping the Watches in the Basket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Design Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Total Rotation Adjustment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
How Many LEDs to Use and Where to Put Them . . . . . . . . . . . . . . . . . . . . . 101
Motor Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
How Many Rotations Does the Watch Winder Make? . . . . . . . . . . . . . . . . . 102
Closing Thoughts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5
The gaRage SenTRy PaRking aSSiSTanT 105
Required Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Optional Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Basics of Calculating Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
How the Garage Sentry Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
iv Chapter
www.allitebooks.com
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
The Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Inside the setup() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Inside the loop() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Determining Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Triggering the Alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Drilling Holes for the Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Mounting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Soldering the Transistors and Current-Limiting Resistors . . . . . . . . . . . . . . . . 123
Wiring the Pieces Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
The Deluxe Garage Sentry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
The Deluxe Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
A Bigger Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
The Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Sketch for the Deluxe Garage Sentry . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6
The BaTTeRy SaveR 133
Boats, Tractors, and Other Vehicles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Special Tool Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
The Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
How the Battery Saver Prevents Draining . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Arduino to the Rescue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
The Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
The Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The Shield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
The PCB Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Preparing the Shield and Pro Mini Controller . . . . . . . . . . . . . . . . . . . . . . . 148
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Preparing the Enclosure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
The Contact Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Preparing the Copper Contact Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Mounting Supplies for the Solenoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Preparing the Release Rod, Springs, and E-Clip . . . . . . . . . . . . . . . . . . . . . 153
Making the Release Lever and Pylon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Assembling All the Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Installing the Battery Saver into a Vehicle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Operating the Battery Saver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Normal Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Setting the Threshold Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Protection from the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Applying Cool Amp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Contents in Detail v
www.allitebooks.com
www.allitebooks.com
Arduino Playground (Early Access), © 2016 by Warren Andrews
1
th e re aCtion-time maChine
In this chapter, I will show you how to
build a time machine—that is, a Reaction-
Time Machine. I’d love to say that this
project will bring you “back to the future,”
but alas, it won’t. The “time” it’s looking at is the time
it takes you to react to a stimulus, which makes for a
fun game. This project is designed to accurately mea-
sure an individual’s reaction time and provide an area
for comments on the level of the individual’s perfor-
mance (see Figure 1-1). There is also plenty of room
to personalize the game to make it even more fun for
you, your friends, and your family.
www.allitebooks.com