SparkFun will be closed Nov 26th and 27th for the Thanksgiving holiday. Orders placed after 2:00pm MT on the 25th will ship out Monday the 30th.
Congratulations on your purchase of a SparkFun servo! Servos are motors that allow you to accurately control the rotation of the output shaft, opening up all kinds of possibilities for robotics and other projects.
Servo motors can be controlled with a multitude of microcontrollers and motor driver boards. However, for this guide you will find the following helpful:
Most motors will spin continuously when you apply power to them. That's OK for many purposes, but sometimes you want exact position control, such as "move to 180 degrees and stop." Doing this requires a feedback loop, which consists of a sensor on the motor shaft that measures what it is actually doing and something that can take that feedback and makes decisions based on that information. For example, if the motor is currently pointing at 10 o'clock, and you'd like it to point at 12 o'clock, then the decision-making circuitry would compare 10 o'clock and 12 o'clock and decide to move the motor clockwise until it's pointing at 12 o'clock.
You could spend a lot of time (and money) adding these parts and smarts to a motor, but the good news is that a servo has all these things built into it! Inside the tiny package is a DC motor, a gear train to trade fast speed for slower torque ("strength"), a potentiometer to measure the position of the output shaft and an "error amplifier" that compares the true position against the desired positions (the "error") and moves the motor so that the error is eliminated. Cool, huh?
Normal motors have two wires; you just apply voltage to them and off they go. For DC motors you can also reverse the polarity of the two wires and have it run in reverse. A servo is a little different. It has three wires, one for power, one for ground and one for commands. Commands? Let's talk about the power and ground first.
Hobby servos are designed for use in radio control (RC) aircraft, which typically use 4.8V batteries. Since they will work fine supplied with up to 6V, we usually run them at 5V, which is what many electronics systems use. The red wire goes to 5V, and the brown wire goes to ground. Unlike DC motors, you should NOT reverse the polarity to get the motor to run in reverse. Always give it 5V on the positive line, and the internal control circuitry will run it in reverse when required.
For the example in this guide, you will need to hook up a servo to an Arduino. There are numerous ways to accomplish this. You could simply attach a jumper wire between the female header on the servo and the headers on the Arduino. You could also cut and solder the ends of the servo to the controller. Another temporary approach is to solder two 3x1 male header pieces together so you can attach the servo to a breadboard.
Servos understand a simple electrical language based on Pulse-Width Modulation (PWM). This means you send it 5V pulses on the control wire, and the width of the pulse will tell the servo to move to a specific position. Don't worry if this sounds complicated; there's software and hardware available to do the hard work for you.
The servo's position is controlled by the width of the pulse you send to the servo. If you want the servo to move to its minimum position (0 degrees), you'd send it a pulse that's 1ms wide (ms is milliseconds, or one 1000th of a second). If you want the servo to move to its maximum position (180 degrees), you'd send it a pulse that's 2ms wide. Anything between 1.0ms and 2.0ms will correspond to all the positions between minimum and maximum. Servos like to be regularly updated, so you'll typically send these commands every 20ms or so (50 times per second), even if there's no change in the servo's position.
Various input pulses and resulting shaft positions
These are the standard values, but you can usually get a servo to turn further by sending it even narrower (or wider) pulses. Note that the servo cannot spin a full 360 degrees! If you try to make it go further than its allowed rotation, the shaft will hit internal stops (probably with a grinding noise), and the servo will draw quite a bit more power. (This shortens the life of the servo, so don't do this on purpose). There is a type of servo called "continuous rotation" that can spin 360 degrees, but you lose the positional control - in continuous rotation servos, the pulse width controls the rotation speed (forwards, backwards, and stopped at 1.5ms).
As is common with the Arduino, someone else has done the hard work for you. The Arduino IDE contains a built-in library, appropriately enough called Servo, that makes controlling servos quite easy. Follow this example from the Arduino website to sweep your servo from minimum to maximum position. If you need help installing the Arduino software or uploading the sketch, their website has all the information you need.
Enjoy your new servo! If you have questions, problems or want to show off your project, don't hesitate to contact us at email@example.com.