Page 185 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 185

Chapter 6    Options for Creating and Controlling Motion          163




               P   roject 6-7: Use Software PWM to Control Speed


               We will re-create the hardware PWM project in software so you can get a feel for
               what the Arduino can do. This example assumes you’ve downloaded the software,
               installed the drivers for your PC or Mac, and identified the port your Arduino is
               plugged into. Refer to the “Arduino Primer” section in the appendix for how to set up
               the Arduino to communicate with your computer.
               Unfortunately, you usually can’t plug motors directly into the Arduino. The Arduino
               can source up to only 40mA on each of the input/output pins, and up to 500mA
               through the power pins when connected through USB. A lot of motors you’ll use
               need more current than this. We get around this issue by using the Arduino to give
               the motor instructions through a transistor, and giving the motor a separate power
               supply. This is similar to Project 6-6, except we’ll replace the 555 timer with an
               Arduino.

               In this project, we’ll create a sketch that listens for input from the stuff you have plugged
               in (switches, sensors, and so on) and then talks to components you want to control
               (such as motors). We’ll build the circuit first, and then go over how to turn a motor
               on and off through a transistor with code from the Arduino, and finally use PWM for
               speed control through the Arduino. (You can find plenty of well-documented example
               sketches of using the Arduino to talk to motors and other components. For example,
               see http://arduino.cc/en/Tutorial/HomePage for basic sketches. In most cases. you can
               just start with these examples and modify them as you see fit.)

               Shopping List:

                   • Arduino with USB cable

                   • DC toy motor with wire leads
                   • Corresponding battery (9V used here) and snap or holder with wire leads (like
                     RadioShack 270-324)
                   • Breadboard (like All Electronics PB-400)

                   • Jumper wires (like SparkFun PRT-00124) or hook-up wire to make your own
                     (see Project 6-4)
   180   181   182   183   184   185   186   187   188   189   190