Using Transistors and Driving Motors
This chapter covered the following concepts:
- DC motors use electromagnetic induction to create mechanical action from changes in current.
- Motors are inductive loads that must utilize proper protection and power circuitry to interface safely with your Arduino.
- DC motor speed and direction can be controlled with PWM and an H-bridge.
- Servo motors enable precise positioning and can be controlled using the Arduino Servo library.
- A linear regulator can be used to create a secondary 5V supply from a 9V battery.
- IR distance sensors return analog values representing distances detected by bouncing infrared light off objects.
- Code commenting is critical for easing debugging and sharing.
- Arduino Uno
- USB A-B Cable
- 9V Battery
- 9V Battery Clip
- 5V L4940V5 Linear Regulator
- 22uF Capacitor
- .1uF Capacitor
- 1uF Ceramic Capacitor
- Blue LEDs (x4)
- 1kΩ Resistors (x4)
- PN2222 NPN BJT Transistor
- Jumper Wires
- Sharp GP2Y0A41SK0F IR Distance Sensor with Cable
- Hot Glue or Tape
- Servo Motor
- DC Motor
- SN754410 H-Bridge IC
- 1N4004 Diode (mistakenly omitted from the parts list in the first edition print of the book)
- Arduino map() Function Reference
- Arduino constrain() Function Reference
- Arduino Servo Library Reference
- SN754410 H-Bridge Datasheet (PDF)
- PN2222 Datasheet (PDF)
- On page 73, in the “Creating Short Circuits with H-Bridges” excerpt, the book reads: “What would happen if both switches on the left or both switches on the right were opened?” It should read: “What would happen if both switches on the left or both switches on the right were closed?”
Color Wiring Diagrams
Follow along with this video for a visual tutorial on motors and transistors:
Watch a demo of the sweeping IR distance sensor created in the chapter:
All code is licensed via the GNU GPL v3. Code is maintained and updated on GitHub. The download zip linked above always contains the most recent version of the code examples that have been pushed to the GitHub Code Repository.
Taking it Further
With your skills from this chapter, combined with your knowledge of analog and digital inputs and outputs and your growing knowledge of the Arduino programming knowledge, you are already equipped to do a number of exciting projects. You can accomplish the following few things by using knowledge you already have. Try building one of these ideas or coming up with your own:
- A roving car with a scanning distance sensor that can avoid walls
- A motion-sensitive light
- A personal thermostat and fan (Fans are just DC motors with blades on them.)
- A code-activated lock box (Push debounced buttons in a certain order to disengage a servo motor.)
- A light-activated jack-in-the-box that uses a servo motor to pop up when you turn on the lights
References & Credits
- Figure 4-2: Transistor Symbol Credit: Public Domain from Wikipedia. (source)
- Figure 4-6: H-Bridge Datasheet excerpts Credit: Image used with permission courtesy of Texas Instruments, www.ti.com (source, PDF)
- Figure 4-9: Photo of Parallax servo Credit: Used with permission from Parallax Inc. Copyright © 2013 Parallax Inc. All rights reserved. Photo by Jeremy Blum.