This tutorial was featured on the official Arduino blog on 3/9/2011
This week, we’ll finally be using the Arduino to control some motors! First up, we’ll control a standard DC motor running off a 9V battery with the help of an NPN transistor and a PWM (Pulse Width Modulated) signal from the Arduino. Next, it’s onto 180 degree servo motors, which we will power on an independent 5V rail using a voltage regulator. We’ll control the servo using a PWM signal from the arduino, and I’ll show you how you can turn analog distance readings into precise angles for the servo to turn to!
If you want to learn more about analog input filtering in software, check out this example code.