Beginning Arduino.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
TECHNOLOGY IN ACTION™ Beginning Arduino Arduino 50 ARDUINO PROJECTS WITH STEP-BY-STEP INSTRUCTIONS AND EASY-TO-FOLLOW DIAGRAMS LEARN HOW TO WORK WITH MOTORS, SENSORS, DISPLAYS, AND NETWORKING CREATE SIMPLE BUT PRACTICAL PROJECTS SUCH AS A RANGEFINDER, AN RFID READER, AND AN INTERNET WEATHER DISPLAY NO PROGRAMMING OR ELECTRONICS EXPERIENCE NEEDED McRoberts Michael McRoberts Download from Wow! eBook <www.wowebook.com> Beginning Arduino ■ ■ ■ Michael McRoberts Beginning Arduino Copyright © 2010 by Michael McRoberts All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-3240-7 ISBN-13 (electronic): 978-1-4302-3241-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Michelle Lowman Technical Reviewer: Josh Adams Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Jennifer L. Blackwell Copy Editor: Mary Behr Production Support: Patrick Cunningham Indexer: Julie Grady Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress 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 this work. The source code for this book is available to readers at www.apress.com. I would like to dedicate this book to my mother for her encouragement throughout the book process and for being the best Mum anyone could ask for, and to my grandfather, Reginald Godfrey, for igniting the spark for science and electronics in me at a young age. Without all those kits from Radio Shack at Christmas I may never have reached the point where I ended up writing a book about microcontrollers and electronics. Thank you both. Contents at a Glance About the Author .................................................................................................... xvii About the Technical Reviewer ............................................................................... xviii Acknowledgments ................................................................................................... xix Introduction .............................................................................................................. xx ■Chapter 1: Introduction ........................................................................................... 1 ■Chapter 2: Light ’Em Up ......................................................................................... 21 ■Chapter 3: LED Effects ........................................................................................... 51 ■Chapter 4: Simple Sounders and Sensors ............................................................. 81 ■Chapter 5: Driving a DC Motor ............................................................................... 99 ■Chapter 6: Binary Counters ................................................................................. 111 ■Chapter 7: LED Displays ....................................................................................... 129 ■Chapter 8: Liquid Crystal Displays ....................................................................... 171 ■Chapter 9: Servos ................................................................................................ 191 ■Chapter 10: Steppers and Robots ........................................................................ 207 ■Chapter 11: Pressure Sensors ............................................................................. 231 ■Chapter 12: Touch Screens .................................................................................. 259 ■Chapter 13: Temperature Sensors ....................................................................... 279 ■Chapter 14: Ultrasonic Rangefinders ................................................................... 293 ■Chapter 15: Reading and Writing to an SD Card ................................................. 317 ■Chapter 16: Making an RFID Reader .................................................................... 343 ■Chapter 17: Communicating over Ethernet.......................................................... 359 Index ....................................................................................................................... 417 iv Contents About the Author .................................................................................................... xvii About the Technical Reviewer ............................................................................... xviii Acknowledgments ................................................................................................... xix Introduction .............................................................................................................. xx ■Chapter 1: Introduction ........................................................................................... 1 How to Use This Book ........................................................................................................ 1 What You Will Need ........................................................................................................... 2 What Exactly is an Arduino? .............................................................................................. 3 Getting Started ................................................................................................................... 6 Windows XP Installation ........................................................................................................................... 7 Windows 7 & Vista Installation ................................................................................................................. 7 Mac OSX Installation ................................................................................................................................. 7 Board and Port Selection .......................................................................................................................... 8 Upload Your First Sketch ................................................................................................. 10 The Arduino IDE ............................................................................................................... 12 ■Chapter 2: Light ’Em Up ......................................................................................... 21 Project 1 – LED Flasher ................................................................................................... 21 Parts Required ........................................................................................................................................ 21 Connecting Everything ............................................................................................................................ 22 Enter the Code ........................................................................................................................................ 23 v ■ CONTENTS Project 1 – LED Flasher – Code Overview .............................................................................................. 23 Project 1 – LED Flasher – Hardware Overview ....................................................................................... 27 Project 2 – S.O.S. Morse Code Signaler ........................................................................... 31 Project 2 – S.O.S. Morse Code Signaler – Code Overview ..................................................................... 33 Project 3 – Traffic Lights ................................................................................................. 34 Parts Required ........................................................................................................................................ 35 Connect