What's a Microcontroller?
Total Page:16
File Type:pdf, Size:1020Kb
What’s a Microcontroller? Student Guide VERSION 3.0 Page 2 · What’s a Microcontroller? WARRANTY Parallax warrants its products against defects in materials and workmanship for a period of 90 days from receipt of product. If you discover a defect, Parallax will, at its option, repair or replace the merchandise, or refund the purchase price. Before returning the product to Parallax, call for a Return Merchandise Authorization (RMA) number. Write the RMA number on the outside of the box used to return the merchandise to Parallax. Please enclose the following along with the returned merchandise: your name, telephone number, shipping address, and a description of the problem. Parallax will return your product or its replacement using the same shipping method used to ship the product to Parallax. 14-DAY MONEY BACK GUARANTEE If, within 14 days of having received your product, you find that it does not suit your needs, you may return it for a full refund. Parallax will refund the purchase price of the product, excluding shipping/handling costs. This guarantee is void if the product has been altered or damaged. See the Warranty section above for instructions on returning a product to Parallax. COPYRIGHTS AND TRADEMARKS This documentation is Copyright 2003-2009 by Parallax Inc. By downloading or obtaining a printed copy of this documentation or software you agree that it is to be used exclusively with Parallax products. Any other uses are not permitted and may represent a violation of Parallax copyrights, legally punishable according to Federal copyright or intellectual property laws. Any duplication of this documentation for commercial uses is expressly prohibited by Parallax Inc. Duplication for educational use, in whole or in part, is permitted subject to the following conditions: the material is to be used solely in conjunction with Parallax products, and the user may recover from the student only the cost of duplication. Check with Parallax for approval prior to duplicating any of our documentation in part or whole for any other use. BASIC Stamp, Board of Education, Boe-Bot, Stamps in Class, and SumoBot are registered trademarks of Parallax Inc. HomeWork Board, PING))), Parallax, the Parallax logo, Propeller, and Spin are trademarks of Parallax Inc. If you decide to use any of these words on your electronic or printed material, you must state that “(trademark) is a (registered) trademark of Parallax Inc.” upon the first use of the trademark name. Other brand and product names herein are trademarks or registered trademarks of their respective holders. ISBN 9781928982524 3.0.0-09.12.09-HKTP DISCLAIMER OF LIABILITY Parallax Inc. is not responsible for special, incidental, or consequential damages resulting from any breach of warranty, or under any legal theory, including lost profits, downtime, goodwill, damage to or replacement of equipment or property, or any costs of recovering, reprogramming, or reproducing any data stored in or used with Parallax products. Parallax is also not responsible for any personal damage, including that to life and health, resulting from use of any of our products. You take full responsibility for your BASIC Stamp application, no matter how life- threatening it may be. ERRATA While great effort is made to assure the accuracy of our texts, errors may still exist. Occasionally an errata sheet with a list of known errors and corrections for a given text will be posted on the related product page at www.parallax.com. If you find an error, please send an email to [email protected]. Table of Contents Preface.........................................................................................................................7 About Version 3.0 ...........................................................................................................7 Audience.........................................................................................................................8 Support Forums ..............................................................................................................8 Resources for Educators ................................................................................................9 Foreign Translations .....................................................................................................10 About the Author...........................................................................................................10 Special Contributors .....................................................................................................10 Chapter 1 : Getting Started......................................................................................11 How Many Microcontrollers Did You Use Today? ........................................................11 The BASIC Stamp 2 – Your New Microcontroller Module ............................................11 Amazing Inventions with BASIC Stamp Microcontrollers .............................................12 Hardware and Software ................................................................................................15 Activity #1 : Getting the Software..................................................................................15 Activity #2 : Using the Help File for Hardware Setup....................................................21 Summary ......................................................................................................................23 Chapter 2 : Lights On – Lights Off..........................................................................27 Indicator Lights .............................................................................................................27 Making a Light-Emitting Diode (LED) Emit Light ..........................................................27 Activity #1 : Building and Testing the LED Circuit.........................................................28 Activity #2 : On/Off Control with the BASIC Stamp.......................................................37 Activity #3 : Counting and Repeating............................................................................43 Activity #4 : Building and Testing a Second LED Circuit ..............................................46 Activity #5 : Using Current Direction to Control a Bicolor LED .....................................50 Summary ......................................................................................................................57 Chapter 3 : Digital Input – Pushbuttons.................................................................61 Found on Calculators, Handheld Games, and Applicances .........................................61 Receiving vs. Sending High and Low Signals ..............................................................61 Activity #1 : Testing a Pushbutton with an LED Circuit.................................................61 Activity #2 : Reading a Pushbutton with the BASIC Stamp ..........................................65 Activity #3 : Pushbutton Control of an LED Circuit .......................................................70 Activity #4 : Two Pushbuttons Controlling Two LED Circuits........................................73 Activity #5 : Reaction Timer Test ..................................................................................79 Summary ......................................................................................................................87 Chapter 4 : Controlling Motion................................................................................93 Microcontrolled Motion..................................................................................................93 On/Off Signals and Motor Motion .................................................................................93 Introducing the Servo....................................................................................................93 Page 4 · What’s a Microcontroller? Activity #1 : Connecting and Testing the Servo............................................................95 Activity #2 : Servo Control Test Program....................................................................102 Activity #3 : Control Servo Hold Time.........................................................................112 Activity #4 : Controlling Position with your Computer .................................................118 Activity #5 : Converting Position to Motion .................................................................126 Activity #6 : Pushbutton-Controlled Servo ..................................................................129 Summary ....................................................................................................................134 Chapter 5 : Measuring Rotation............................................................................ 139 Adjusting Dials and Monitoring Machines...................................................................139 The Variable Resistor Under the Dial – a Potentiometer............................................139 Activity #1 : Building and Testing the Potentiometer Circuit .......................................141 Activity #2 : Measuring Resistance by Measuring Time .............................................143 Activity #3 : Reading the Dial with the BASIC Stamp .................................................150 Activity #4 : Controlling a Servo with a Potentiometer................................................156 Summary ....................................................................................................................164