the tab book of arduino projects - professional · the tab book of arduino projects ... 19 network...

32
The TAB Book of Arduino Projects

Upload: vuongthien

Post on 26-May-2018

253 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

The TAB Book of Arduino Projects

Page 2: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock
Page 3: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

The TAB Book of Arduino Projects

36 Things to Make with Shields and Protoshields

Simon Monk

New York Chicago San Francisco Athens London Madrid

Mexico City Milan New Delhi Singapore Sydney Toronto

Page 4: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

McGraw-Hill Education books 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.

The TAB Book of Arduino Projects: 36 Things to Make with Shields and Protoshields

Copyright © 2015 by McGraw-Hill Education. All rights reserved. Printed in the United States of America. 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.

1 2 3 4 5 6 7 8 9 0 DOC/DOC 1 2 0 9 8 7 6 5 4

ISBN 978-0-07-179067-3 MHID 0-07-179067-5

This book is printed on acid-free paper.

Sponsoring EditorRoger Stewart

Editing SupervisorDonna Martone

Production SupervisorPamela A. Pelton

Acquisitions Coordinator Amy Stonebraker

Project ManagerPatricia Wallenburg, TypeWriting

Copy EditorJames K. Madru

ProofreaderClaire Splan

IndexerClaire Splan

Art Director, CoverJeff Weeks

CompositionTypeWriting

McGraw-Hill Education, the McGraw-Hill Education logo, TAB, and related trade dress are trademarks or registered trademarks of McGraw-Hill Education and/or its affiliates in the United States and other countries and may not be used without written permission. All other trademarks are the property of their respective owners. McGraw-Hill Education is not associated with any product or vendor mentioned in this book.

Information contained in this work has been obtained by McGraw-Hill Education from sources believed to be reliable. However, neither McGraw-Hill 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.

Page 5: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

To my son Matthew

Page 6: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock
Page 7: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

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.

Page 8: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock
Page 9: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

Contents

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiiArduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Arduino Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiiInstalling Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvMaking a Light-Emitting Diode (LED) Blink . . . . . . . . . . . . xxvi

Protoshields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviiComponents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxThe Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx

Part One Light and Color

1 Persistence-of-Vision Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 1: Put the Resistors in Place . . . . . . . . . . . . . . . . . . . . . 6Step 2: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 6Step 3: Solder the LEDs to the Resistors . . . . . . . . . . . . . . . . 6Step 4: Solder the LED Negative Leads . . . . . . . . . . . . . . . . . 7Step 5: Test the LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Step 6: Prepare the Tilt Sensor . . . . . . . . . . . . . . . . . . . . . . . 9Step 7: Solder the Tilt Sensor . . . . . . . . . . . . . . . . . . . . . . . . 11

Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2 LED Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

ix

Page 10: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

x C o n t e n t s

Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Step 1: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 20Step 2: Solder the Transistors and Jumpers . . . . . . . . . . . . . . 22Step 3: Prepare a Holder for the LEDs . . . . . . . . . . . . . . . . . 23Step 4: Make the First Layer of LEDs . . . . . . . . . . . . . . . . . . 25Step 5: Attach the Bottom Layer of LEDs . . . . . . . . . . . . . . . 27Step 6: The Second Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Step 7: The Top Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Using the LED Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3 High-Power LED Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

Step 1: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 34Step 2: Prepare the Header Sockets . . . . . . . . . . . . . . . . . . . . 37Step 3: Solder the Header Sockets . . . . . . . . . . . . . . . . . . . . . 38Step 4: Solder the MOSFETs . . . . . . . . . . . . . . . . . . . . . . . . . 38Step 5: Wire Up the Underside . . . . . . . . . . . . . . . . . . . . . . . 38

Using the LED Lighting Controller . . . . . . . . . . . . . . . . . . . . . . . 41Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4 Color Recognizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Part Two Security

5 RFID Door Lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Shield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

Step 1: Attach Header Pins to the Shield . . . . . . . . . . . . . . . . 53Step 2: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 54

Page 11: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

C o n t e n t s xi

Step 3: Solder the Remaining Components . . . . . . . . . . . . . . 54Step 4: Wire the Underside . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Installing and Using the Door Lock . . . . . . . . . . . . . . . . . . . . . . . 61Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

6 Keypad Door Lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Step 1: Attach Header Pins to Keypad . . . . . . . . . . . . . . . . . 67Step 2: Attach Header Pins to the Shield . . . . . . . . . . . . . . . . 67Step 3: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 69Step 4: Solder the Remaining Components . . . . . . . . . . . . . . 69Step 5: Wire the Underside . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Installing and Using the Door Lock . . . . . . . . . . . . . . . . . . . . . . . 75Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

7 Secret Knock Lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Step 1: Solder Resistor R5 and a Pair of Header Pins . . . . . . 80Step 2: Wire the Underside . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Installing and Using the Door Lock . . . . . . . . . . . . . . . . . . . . . . . 85Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

8 Fake Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Step 1: Solder the Header Pins to the Shield . . . . . . . . . . . . . 89Step 2: Attach the Push Button . . . . . . . . . . . . . . . . . . . . . . . 89Step 3: Attach the PIR Sensor . . . . . . . . . . . . . . . . . . . . . . . . 91Step 4: Install the MP3 Player Library . . . . . . . . . . . . . . . . . 91Step 5: Prepare a Micro SD Card . . . . . . . . . . . . . . . . . . . . . 92

Using the Fake Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Page 12: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xii C o n t e n t s

9 Person Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

Step 1. Attach Header Pins to the Protoshield . . . . . . . . . . . . 96Step 2. Solder the Components to the Protoshield . . . . . . . . . 97Step 3: Solder the Underside of the Protoshield . . . . . . . . . . . 97

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

10 Laser Alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

Step 1: Attach Header Pins to the Protoshield . . . . . . . . . . . . 106Step 2: Solder the Relay onto the Protoshield . . . . . . . . . . . . 107Step 3: Solder the Remaining Components to the Protoshield 107Step 4: Solder the Underside of the Protoshield . . . . . . . . . . . 109

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

Part Three Sound and Music

11 Theremin-Like Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

Step 1: Solder the Header Pins to the Protoshield . . . . . . . . . 118Step 2: Attach the 3.5-mm Socket . . . . . . . . . . . . . . . . . . . . . 120Step 3: Solder the Remaining Components . . . . . . . . . . . . . 121Step 4: Link the Components . . . . . . . . . . . . . . . . . . . . . . . . 121

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122Using the Instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

12 FM Radio Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Step 1: Solder the Header Pins to the Protoshield . . . . . . . . . 128Step 2: Assemble the TEA5767 Breakout PCB . . . . . . . . . . . 129

Page 13: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

C o n t e n t s xiii

Step 3: Attach the Audio Socket . . . . . . . . . . . . . . . . . . . . . . 131Step 4: Attach the Components . . . . . . . . . . . . . . . . . . . . . . . 131Step 5: Solder the Underside of the Board . . . . . . . . . . . . . . . 133Step 6: Make an Antenna . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

13 Pedal Board Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139Parts (Protoshield Version) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139Protoshield Layout (Protoshield Version) . . . . . . . . . . . . . . . . . . 141Construction (Protoshield Version) . . . . . . . . . . . . . . . . . . . . . . . 141

Step 1: Attach the Header Pins to the Protoshield . . . . . . . . . 141Step 2: Solder the Switches to the Protoshield . . . . . . . . . . . . 142Step 3. Solder the Underside of the Protoshield . . . . . . . . . . . 142

Parts (Screw-Shield Version) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144Construction (Screw-Shield Version) . . . . . . . . . . . . . . . . . . . . . . 145

Step 1: Prepare the Enclosure . . . . . . . . . . . . . . . . . . . . . . . . 145Step 2: Fit the Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Step 3: Solder the GND Wires to the Switches . . . . . . . . . . . 146Step 4: Solder the Separate Wires to the Switches . . . . . . . . . 146

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

14 Music Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Step 1: Solder Header Pins onto the Acceleration Module . . . 155Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

15 Spectrum Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

Step 1: Solder the Header Pins onto the Protoshield . . . . . . . 162Step 2: Solder the Resistor, Capacitors,

and Integrated Circuit Holder . . . . . . . . . . . . . . . . . . . . . 162Step 3: Solder the Screw Terminals and Header Pin Socket . . 163Step 4: Connect the Underside of the Board . . . . . . . . . . . . . 164

Page 14: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xiv C o n t e n t s

Step 5: Fit the Integrated Circuit and Display . . . . . . . . . . . . 165Step 6: Prepare the 3.5-mm Audio Lead . . . . . . . . . . . . . . . . 165

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

Part Four Internet

16 E-Mail Notifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

17 Weather Data Feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

18 Network-Controlled Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

19 Network Temperature and Humidity Sensor . . . . . . . . . . . . . . . . 197Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

20 Pingometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

Step 1: Attach the Leads to the Meter . . . . . . . . . . . . . . . . . . 205Step 2: Connect the Meter to the Ethernet Shield . . . . . . . . . 205

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

Page 15: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

C o n t e n t s xv

Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

Part Five Clocks

21 LED Matrix Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

Step 1: Assemble the RTC Module . . . . . . . . . . . . . . . . . . . . 214Step 2: Assemble the LED Matrix Module . . . . . . . . . . . . . . 214Step 3:. Solder the Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . 214Step 4: Solder the Header Sockets . . . . . . . . . . . . . . . . . . . . . 215Step 5: Wire the Underside of the Protoshield . . . . . . . . . . . 215

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

22 Binary Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221Binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Step 1: Assemble the RTC Module . . . . . . . . . . . . . . . . . . . . 224Step 2: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 224Step 2: Solder the LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227Step 3: Solder the Header Socket or RTC Module . . . . . . . . 227Step 4: Wire the Underside of the Protoshield . . . . . . . . . . . . 227

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

23 Seven-Segment LED Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235Protoshield Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

24 Hacked Analog Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242

Step 1: Remove the Clock Mechanism . . . . . . . . . . . . . . . . . 242

Page 16: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xvi C o n t e n t s

Step 2: Open the Mechanism Enclosure . . . . . . . . . . . . . . . . 243Step 3: Cut the PCB Tracks . . . . . . . . . . . . . . . . . . . . . . . . . . 245Step 4: Prepare the Lead . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245Step 5: Solder the Leads to the Clock Coil . . . . . . . . . . . . . . 246Step 6: Reassemble the Clock Mechanism Case . . . . . . . . . . 247

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

25 World Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

Step 1: Make Three Hacked Clock Mechanisms . . . . . . . . . . 254Step 2: Drill the Tray and Glue the Mechanisms in Place . . . 254Step 3: Print a Clock Face . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

Part Six Novelty

26 Larson Scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261Wiring Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

Step 1: Cut the Stripboard to Size . . . . . . . . . . . . . . . . . . . . . 264Step 2: Cut the Breaks in the Stripboard . . . . . . . . . . . . . . . . 264Step 3: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 264Step 4: Solder the LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Step 5: Prepare the Ribbon Cable . . . . . . . . . . . . . . . . . . . . . 265Step 6: Solder the Ribbon Cable to the Stripboard . . . . . . . . 266Step 7: Solder the Ribbon Cable to the Header Pins . . . . . . . 266

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

27 Conway’s Game of Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

Page 17: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

C o n t e n t s xvii

28 Singing Plant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

29 Ultrasonic Range Finder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

30 GPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290

31 Methane Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

Step 1: Solder the Pins to the Protoshield . . . . . . . . . . . . . . . 292Step 2: Attach Leads to the Methane Sensor . . . . . . . . . . . . . 292Step 3: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 292Step 4: Solder the Remaining Components . . . . . . . . . . . . . . 295Step 5:. Wire the Underside . . . . . . . . . . . . . . . . . . . . . . . . . . 295

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

Part Seven Home

32 Light-Level Logger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

Step 1: Attach the Header Pins to the Protoshield . . . . . . . . . 305Step 2: Solder the Resistors to the Protoshield . . . . . . . . . . . 306Step 3: Solder the Remaining Components to the Protoshield 306Step 4: Solder the Underside of the Protoshield . . . . . . . . . . . 306

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

Page 18: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xviii C o n t e n t s

Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312

33 Temperature and Light Logger . . . . . . . . . . . . . . . . . . . . . . . . . . 313Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

34 Timer-Controlled Lamp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328

35 Autoranging Capacitance Meter . . . . . . . . . . . . . . . . . . . . . . . . . 329Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330

Step 1: Cut the Stripboard to Size . . . . . . . . . . . . . . . . . . . . . 330Step 2: Solder the Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 332Step 3: Attach the Right-Angle Header . . . . . . . . . . . . . . . . . 332Step 4: Attach the Header Sockets . . . . . . . . . . . . . . . . . . . . 332Step 5: Putting It Together . . . . . . . . . . . . . . . . . . . . . . . . . . 334

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

36 Geiger Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

Step 1: Attach the Pins to the Protoshield . . . . . . . . . . . . . . . 342Step 2: Solder the Low Components . . . . . . . . . . . . . . . . . . . 342Step 3: Solder the Remaining Components . . . . . . . . . . . . . . 343Step 4: Solder the Underside of the Board . . . . . . . . . . . . . . . 343Step 5: Attach the Tube and Meter . . . . . . . . . . . . . . . . . . . . 345

Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345Using the Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

Page 19: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

C o n t e n t s xix

Appendix: Component Buying Guide . . . . . . . . . . . . . . . . . . . . . 349Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350Modules and Sheilds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352Semiconductors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354Other Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357

Page 20: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock
Page 21: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

Acknowledgments

I am very grateful to my son Stephen, the musician of the family, for his help with the “Sound and Music” section of the book.

xxi

Page 22: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock
Page 23: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

Introduction

This book contains 36 Arduino projects. Some are easy to make, whereas others require some expertise with a soldering iron. You do not need a strong grounding in electronics engineering to build these projects.

Although you will find some theoretical explanations, this is primarily a book that shows you in detail how to make the Arduino projects that it contains.

Some experience with a soldering iron will be helpful. The only tools you will need are screwdrivers, pliers, snips, and a soldering set.

Arduino

Arduino has become the most popular open-source hardware for building your own microcontroller projects. There are many reasons for this:

• Low cost ($25 or less)• Cross-platform (you can use it with PC, Mac, or Linux)• Simple to program• Ready-made plug-in shields that add hardware such as Ethernet, liquid-

crystal display (LCD) screens, and so on • Active and helpful community

Arduino Boards

Probably the two most common Arduino boards in use are the Arduino Uno and the Arduino Leonardo (Figures I-1 and I-2).

There are pros and cons for each board. The Leonardo is a little cheaper and can do some tricks, such as impersonating a USB keyboard or mouse, that the Uno is not capable of. However, the Leonardo is a newer device, and there are some

xxiii

Page 24: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xxiv I n t r o d u c t i o n

Figure i-1 Arduino Uno.

Figure i-2 Arduino Leonardo.

Page 25: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

I n t r o d u c t i o n xxv

computability problems with older shields and libraries. However, most of the projects in this book will work with the Leonardo. In fact, a few of the projects in this book will only work with the Leonardo because they use the USB keyboard impersonation feature. Refer to the start of each project to check for compatibility or otherwise with different Arduino boards.

The Arduino Uno is a more common board. It is more expensive, but it does have a removable processor chip, which gives the advantage that should you accidentally short an output pin and destroy the processor chip, you can buy a new one for a few dollars. If you do that to a Leonardo, you will need to buy a new Leonardo.

If you get advanced in your Arduino project making, you can take a programmed processor from an Arduino Uno and build it onto a custom printed circuit board (PCB) or stripboard and then replace the processor chip with a new one for the next project. Again, this is not possible with the Leonardo.

If you are buying an Arduino for this book and you have no older Arduino kit, then I would start with a Leonardo. You may find that you end up buying an Uno if you catch the bug!

This book uses the Arduino R3 and the Leonardo. Although older versions of the Arduino should work, versions prior to R3 have fewer sockets around the edge, so an Uno R3 or Leonardo is recommended.

As you can see from Figures I-1 and I-2, both Arduino boards have a similar layout with connector strips down each side and a USB socket at one end. The Uno has a big B-type USB connector, whereas the Leonardo has a micro-USB connector.

All the projects in this book require an Arduino board and a USB lead to connect the Arduino to your computer. For most projects, your Arduino board can be powered through the USB connector, either from your computer or from a power supply. The boards also can be powered using a direct-current (dc) adapter connected to the dc power socket on the same side as the USB socket.

The red button on both boards is the reset button. You will not need to press this much, if at all, with the Uno; however, if you use a Leonardo, you will need to press it sometimes when programming the board.

Installing Arduino

Before you can start making some of the projects in this book, you will need to set up your computer with the Arduino software so that you can program the Arduino from your laptop or desktop computer. The Arduino software is compatible with Windows, Mac, and Linux, although the installation instructions for each are

Page 26: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xxvi I n t r o d u c t i o n

different. For the latest up to date installation instructions for your platform, visit the official Arduino website (www.arduino.cc), where you will also be able to download the software and follow the installation instructions.

Making a Light-Emitting Diode (LED) Blink

Traditionally, the first thing that most books will teach you is how to make the built-in LED on the Arduino flash. This is a useful exercise for two reasons. First, it shows that everything is set up okay and that your computer can communicate with the Arduino to program it. Second, it is a nice simple example that uses the LED built onto the Arduino board, and therefore, you do not need anything except your Arduino, your computer, and a lead to connect the two.

Start the Arduino IDE software, and open the example “Blink” sketch (programs are called sketches in the Arduino world). You will find the sketch from the file menu, under “Examples” and then “Basic.” With the sketch opened, you should see something like Figure I-3.

Figure i-3 Blink sketch.

Page 27: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

I n t r o d u c t i o n xxvii

Before you can program the Arduino board with this sketch, you need to set the board type and serial port from the “Tools” menu. If all is well, when you press the “Upload” button (highlighted in Figure I-3), there should then be some flashing of the LEDs on the board, and then the LED marked “L” on the board should start to blink slowly.

Next, try changing 1,000 to 200 in the two delay commands. Upload the sketch again, and the LED will blink at a much faster rate.

Protoshields

Many of the projects in this book make use of a Protoshield (Figure I-4). A Protoshield is a plain circuit board designed to sit over the top of an Arduino. It has a large area to which you can attach your own components. Although ready-made Protoshields are quite expensive to buy, you can also just buy the bare boards for a few dollars and attach your own header pins.

The first project in Chapter 1 uses a Protoshield to create a persistence-of-vision display that appears to paint a message in the air when you wave it from side to side. Figure I-5 shows this project. As you can see in the figure, eight LEDs,

Figure i-4 Protoshield.

Page 28: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xxviii I n t r o d u c t i o n

eight resistors, and a small module (a tilt sensor) are attached to the board. The component leads are usually pushed through the holes in the top of the board and soldered to the pads underneath, and the leads of the components are soldered together, often with extra bridging wires, to make up the circuit. This first project explains in great detail exactly how to solder components to the Protoshield.

A number of different Protoshield designs are available on the market. The one used in this book is the official R3 Protoshield designed by the makers of Arduino. This is available from the Arduino store (http://store.arduino.cc/eu) for just €3 for a bare board. You will also find it for sale at many of Arduino’s distributers and on eBay.

To be able to plug the Protoshield into your Arduino, you will also need some lengths of header pins. See the Appendix for more details about where to obtain components.

Figure I-6 shows the easiest way to make sure that the header pins are soldered on straight. First, break of lengths of 10, 8, 8, and 6 pins each, and push the long ends into your Arduino. Then place the shield over the top of the holes, and make sure that it is the right way up (Figure I-6a). The Arduino board will keep the pins straight while they are being soldered. Solder each pin in turn (Figure I-6b). When all the pins are soldered, the shield should look like Figure 6c when you turn it over.

Figure 1-5 Protoshield from Chapter 1 (persistence of vision).

Page 29: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

I n t r o d u c t i o n xxix

Figure i-6 Soldering headers onto a Protoshield.

a

b

Page 30: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

xxx I n t r o d u c t i o n

There are holes on the protoshield to add a reset switch, but this is not really necessary because the “Reset” button on the Arduino is still accessible even with the Protoshield fitted.

Components

The Appendix contains a list of all the components that you will need for the projects in this book, along with various sources. You will often find that many of the components can be obtained very cheaply on eBay.

The Book

The remainder of this book is organized into chapters that deal with a particular theme, but within that theme, there is no real order to the projects. The only project that gets something in the way of special treatment is the first project in Chapter 1. This project is to build a persistence-of-vision (POV) display. The chapter explains how to us a Prototshield and construct the project in more detail than for most other projects. Thus, if you are new to this type of construction, read Chapter 1 first, even if you do not plan to make the project.

Figure i-6 Soldering headers onto a Protoshield (continued).

c

Page 31: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock

The TAB Book of Arduino Projects

Page 32: The TAB Book of Arduino Projects - Professional · The TAB Book of Arduino Projects ... 19 Network Temperature and Humidity Sensor ... 21 LED Matrix Clock