Servos are ideal for embedded electronics applications because they do one thing very well that motors cannot – they can move to a position accurately. By varying the pulse width of the output voltage to a servo, you can move a servo to a specific position. For example, a pulse of 1.5 milliseconds will move the servo 90 degrees. In this circuit, you’ll learn how to use PWM (pulse width modulation) to control and rotate a servo.
MicroView Arduino Code
What you should seeYou should see your servo motor move to various locations at several speeds. If the motor doesn't move, check your connections and make sure you have verified and uploaded the code, or see the troubleshooting tips below.
Code to Note
#include is a special "preprocessor" command that inserts a library (or any other file) into your sketch. You can type this command yourself, or choose an installed library from the "sketch / import library" menu.
The servo library adds new commands that let you control a servo. To prepare the Arduino to control a servo, you must first create a Servo "object" for each servo (here we've named it "servo"), and then "attach" it to a digital pin (here we're using digital pin 6).
Servo servo; servo.attach(6);
The servo in this kit doesn't spin all the way around, but they can be commanded to move to a specific position. We use the servo library's write() command to move a servo to a specified number of degrees(0 to 160). Remember that the servo requires time to move, so give it a short
delay() if necessary.
Servo Not Twisting
Even with colored wires it is still shockingly easy to plug a servo in backward. This might be the case.
Still Not Working
A mistake we made a time or two was simply forgetting to connect the power (red and brown wires) to +5 volts and ground.
Fits and Starts
If the servo begins moving then twitches, and there's a flashing light on your MicroView, the power supply you are using is not quite up to the challenge. Try using a USB adaptor that provides more current.
Still No Success?
A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: email@example.com