Copyright © 2015 by McGraw-Hill Education All rights reserved Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher ISBN: 978-0-07-179810-5 MHID: 0-07-179810-2 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-179067-3, MHID: 0-07-179067-5 eBook conversion by codeMantra Version 1.0 All trademarks are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs To contact a representative please visit the Contact Us page at www.mhprofessional.com Information contained in this work has been obtained by McGraw-Hill Education from sources believed to be reliable However, neither McGrawHill Education nor its authors guarantee the accuracy or completeness of any information published herein, and neither McGraw-Hill Education nor its authors shall be responsible for any errors, omissions, or damages arising out of use of this information This work is published with the understanding that McGraw-Hill Education and its authors are supplying information but are not attempting to render engineering or other professional services If such services are required, the assistance of an appropriate professional should be sought TERMS OF USE This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work Use of this work is subject to these terms Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Education’s prior consent You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited Your right to use the work may be terminated if you fail to comply with these terms THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE McGraw-Hill Education and its licensors not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom McGraw-Hill Education has no responsibility for the content of any information accessed through the work Under no circumstances shall McGraw-Hill Education and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise To my son Matthew About the Author Dr Simon Monk (Preston, UK) has a degree in cybernetics and computer science and a Ph.D in software engineering He spent several years as an academic before he returned to industry, co-founding the mobile software company Momote Ltd He has been an active electronics hobbyist since his early teens and is a full-time writer on hobby electronics and open-source hardware Dr Monk is the author of numerous electronics books, specializing in open-source hardware platforms, especially Arduino and Raspberry Pi He is also co-author with Paul Scherz of Practical Electronics for Inventors, Third Edition You can follow him on Twitter, where he is @simonmonk2 Contents Acknowledgments Introduction Arduino Arduino Boards Installing Arduino Making a Light-Emitting Diode (LED) Blink Protoshields Components The Book Part One Light and Color Persistence-of-Vision Display Parts Protoshield Layout Construction Step 1: Put the Resistors in Place Step 2: Solder the Resistors Step 3: Solder the LEDs to the Resistors Step 4: Solder the LED Negative Leads Step 5: Test the LEDs Step 6: Prepare the Tilt Sensor Step 7: Solder the Tilt Sensor Testing Software Summary LED Cube Parts Protoshield Layout Construction Step 1: Solder the Resistors Step 2: Solder the Transistors and Jumpers Step 3: Prepare a Holder for the LEDs Step 4: Make the First Layer of LEDs Step 5: Attach the Bottom Layer of LEDs Step 6: The Second Layer Step 7: The Top Layer Using the LED Cube Software Summary High-Power LED Controller Parts Protoshield Layout Construction Step 1: Solder the Resistors Step 2: Prepare the Header Sockets Step 3: Solder the Header Sockets Step 4: Solder the MOSFETs Step 5: Wire Up the Underside Using the LED Lighting Controller Software Summary Color Recognizer Parts Design Construction Software Summary Part Two Security RFID Door Lock Parts Shield Layout Construction Step 1: Attach Header Pins to the Shield Step 2: Solder the Resistors Step 3: Solder the Remaining Components Step 4: Wire the Underside Software Installing and Using the Door Lock Summary Keypad Door Lock Parts Protoshield Layout Construction Step 1: Attach Header Pins to Keypad Step 2: Attach Header Pins to the Shield Step 3: Solder the Resistors Step 4: Solder the Remaining Components Step 5: Wire the Underside Software Installing and Using the Door Lock Summary Secret Knock Lock Parts Protoshield Layout Construction Step 1: Solder Resistor R5 and a Pair of Header Pins Step 2: Wire the Underside Software Installing and Using the Door Lock Summary Fake Dog Parts Design Construction Step 1: Solder the Header Pins to the Shield Step 2: Attach the Push Button Step 3: Attach the PIR Sensor Step 4: Install the MP3 Player Library Step 5: Prepare a Micro SD Card Using the Fake Dog Software Summary Person Counter Parts Protoshield Layout Construction Step Attach Header Pins to the Protoshield Step Solder the Components to the Protoshield Step 3: Solder the Underside of the Protoshield Software Using the Project Other Components Index Please note that index links point to page beginnings from the print edition Locations are approximate in e-readers, and you may need to page down one or more times after clicking a link to get to the indexed material References to figures are in italics Ableton Live, 157–158 acceleration module, 153, 154 See also music controller Arduino buying guide, 350 fixing the IP address of, 195 audio spectrum display See spectrum display autoranging capacitance meter, 329 construction, 330–334 parts, 330 software, 334–337 stripboard layout, 331 using, 337 binary clock, 221 construction, 224–231 parts, 222 Protoshield layout, 223–224, 226 schematic diagram, 225 software, 231–234 wiring diagram, 228 binary numbers, 222 Boolean flag, 73 capacitors, buying guide, 355 charlieplexing, 223–224 See also binary clock clocks binary clock, 221–234 hacked analog clock, 241–251 LED matrix clock, 211–220 seven-segment LED clock, 235–240 world clock, 253–256 code See sketches color recognizer, 43 construction, 44–45 design, 44, 45 parts, 43 software, 45–47 comma-separated values (CSVs), 317 component buying guide, 349–355 See also parts Conway’s Game of Life, 269, 270 construction, 270 parts, 269 software, 270–274 door locks keypad door lock, 63–75 RFID door lock, 51–61 secret knock lock, 77–85 e-mail notifier, 173 construction, 175 parts, 174–175 software, 175–181 using, 181 EtherTen, 181 fake dog, 87 construction, 88–92 design, 88 parts, 88 software, 92–93 using, 92 wiring diagram, 89 FM radio receiver, 127–128 construction, 128–134 parts, 128 Protoshield layout, 129 software, 135–137 using, 137 wiring diagram, 133 Geiger counter, 339 construction, 340–345 parts, 340 Protoshield layout, 342 schematic diagram, 341 software, 345–347 using, 347 warning, 339–340 wiring diagram, 344 Geiger-Müller tube, 339–340 GPS, 285 construction, 286 parts, 286 software, 286–290 using, 290 hacked analog clock, 241, 242 construction, 242–247 parts, 241–242 software, 247–250 using, 250–251 hardware buying guide, 350 See also parts header sockets, 37–38 high-power LED controller, 33 construction, 34–41 parts, 34 Protoshield layout, 34 software, 41–42 using the LED lighting controller, 41 IP addresses, fixing the IP address of an Arduino, 195 Java Script Object Notation (JSON), 186–187 keypad door lock, 63 construction, 66–70, 71 installing and using, 75 parts, 63–64 Protoshield layout, 64–65 software, 70–75 keypads, matrix, 66 Larson scanner, 261, 262 construction, 262–266 parts, 261–262 software, 266–268 wiring diagram, 262, 263 laser alarm, 103 construction, 106–109 parts, 104 Protoshield layout, 104–105 software, 109–112 using, 113–114 warning, 104 LED cube, 17 construction, 19–29 parts, 17–18 Protoshield layout, 18–19 software, 30–32 using the LED cube, 29–30 LED matrix clock, 211, 212 construction, 212–216 parts, 211 Protoshield layout, 212, 213 software, 216–220 LEDs buying guide, 354 using as a light sensor, 105–106 light-level logger, 303, 304 construction, 305–308 parts, 303–305 Protoshield layout, 305 software, 308–311 using, 311–312 wiring diagram, 307 matrix keypads, 66 methane detector, 291 construction, 292–296 parts, 292 Protoshield layout, 293 software, 297–298 using, 298 wiring diagram, 296 modules buying guide, 351 See also parts MSGEQ7 integrated circuits, 161–162 music controller, 153, 154 construction, 155–156 parts, 153 software, 156–157 using, 157–158 warning, 155 National Marine Electronics Association (NMEA), 287–288 near-field communication (NFC) See RFID network temperature and humidity sensor, 197, 198 construction, 198–199 parts, 197–198 software, 199–202 using, 202 network-controlled switch, 189–190 construction, 191 parts, 191 software, 191–194 using, 194–195 NFC See RFID parts autoranging capacitance meter, 330 binary clock, 222 buying guide, 349–355 color recognizer, 43 Conway’s Game of Life, 269 e-mail notifier, 174–175 fake dog, 88 FM radio receiver, 128 Geiger counter, 340 GPS, 286 hacked analog clock, 241–242 hardware, 350 high-power LED controller, 34 keypad door lock, 63–64 Larson scanner, 261–262 laser alarm, 104 LED cube, 17–18 LED matrix clock, 211 LEDs, 354 light-level logger, 303–305 methane detector, 292 modules, 351 music controller, 153 network temperature and humidity sensor, 197–198 network-controlled switch, 191 pedal board controller, 139–140, 144 persistence-of-vision display, person counter, 95 pingometer, 203–204 resistors, 352–353 RFID door lock, 51–52 secret knock lock, 77–78 semiconductors, 354 seven-segment LED clock, 235 shields, 351 singing plant, 277 spectrum display, 160–161 temperature and light logger, 313 theremin-like instrument, 117–118 timer-controlled lamp, 322 ultrasonic range finder, 281 weather data feed, 184 world clock, 253 passive infrared (PIR) motion detector, 181 pedal board controller, 139 construction, 141–143, 145–147 parts, 139–140, 144 Protoshield layout, 141 Protoshield version, 139–143 screw-shield version, 140, 144–147 software, 147–150 using, 150–151 wiring diagram, 146 persistence-of-vision display, construction, 5–11 parts, Protoshield layout, software, 12–15 testing, 11–12 person counter, 95, 96 construction, 96–99 parts, 95 Protoshield layout, 96, 97 software, 99–101 using, 101–102 photoresistors, 304 ping value, 203 pingometer, 203, 204 construction, 204–205 parts, 203–204 software, 206–207 using, 208 POV display See persistence-of-vision display Power Over Ethernet (PoE), 181 PowerSwitch Tail, 189–190 See also network-controlled switch radiofrequency identification See RFID range finder See ultrasonic range finder relay, 113 resistors buying guide, 352 stripes, 352–353 See also parts RFID readers, 51 See also RFID door lock RFID door lock, 51 construction, 52–56 installing and using, 61 parts, 51–52 shield layout, 52, 53 software, 57–61 secret knock lock, 77 construction, 79–80 installing and using, 85 parts, 77–78 Protoshield layout, 79 software, 80–84 semiconductors buying guide, 354 See also parts seven-segment LED clock, 235, 236 construction, 237 parts, 235 Protoshield layout, 237 software, 237–240 shields buying guide, 351 See also parts Signal Generator, 160 Simple Mail Transfer Protocol (SMTP) service, 175–177 singing plant, 277, 278 construction, 278–280 parts, 277 Protoshield layout, 279 software, 280 See also theremin-like instrument sketches autoranging capacitance meter, 334–337 binary clock, 231–234 color recognizer, 45–47 Conway’s Game of Life, 270–274 e-mail notifier, 175–181 fake dog, 92–93 FM radio receiver, 135–137 Geiger counter, 345–347 GPS, 286–290 hacked analog clock, 247–250 high-power LED controller, 41–42 Larson scanner, 266–268 laser alarm, 109–112 LED cube, 30–32 LED matrix clock, 216–220 light-level logger, 308–311 methane detector, 297–298 music controller, 156–157 network temperature and humidity sensor, 199–202 network-controlled switch, 191–194 persistence-of-vision display, 12–15 person counter, 99–101 pingometer, 206–207 RFID door lock, 57–61 secret knock lock, 80–84 seven-segment LED clock, 237–240 singing plant, 280 spectrum display, 166–170 temperature and light logger, 314–317 theremin-like instrument, 122–125 timer-controlled lamp, 324–327 weather data feed, 184–188 smtp2go, 176–177 software See sketches spectrum display, 159–160 construction, 161–166 parts, 160–161 software, 166–170 using, 170 wiring diagram, 164 state machine, 326 stripboard, 264 suppliers, 349 switches, buying guide, 355 temperature and light logger, 313, 314 construction, 314 parts, 313 Protoshield layout, 315 software, 314–317 using, 317–319 testing, persistence-of-vision display, 11–12 Theremin, Léon, 117 theremin-like instrument, 117 construction, 118–122 parts, 117–118 software, 122–125 using, 125 See also singing plant tilt sensors, 9–11 timer-controlled lamp, 321–322 construction, 322–323 parts, 322 software, 324–327 using, 327 warning, 322 wiring diagram, 324 ultrasonic range finder, 281, 282 construction, 281 parts, 281 software, 282–284 weather data feed, 183 construction, 184, 185 parts, 184 software, 184–188 using, 188 world clock, 253, 254 construction, 254–255 parts, 253 software, 255–256 using, 256 ... Pins to the Protoshield Step 2: Solder the Resistors to the Protoshield Step 3: Solder the Remaining Components to the Protoshield Step 4: Solder the Underside of the Protoshield Software Using the. .. Pins to the Protoshield Step 2: Solder the Relay onto the Protoshield Step 3: Solder the Remaining Components to the Protoshield Step 4: Solder the Underside of the Protoshield Software Using the. .. Header Pins to the Protoshield Step Solder the Components to the Protoshield Step 3: Solder the Underside of the Protoshield Software Using the Project Summary 10 Laser Alarm Parts Protoshield Layout