# Servo not working with Arduino

I've connected a servo(AS-18 acoms) to my arduino and I've uploaded the sweep example onto it. But nothing happens . Here's a pic. I've connected the positive terminal of the servo to 5V on the board, negative to ground and the pulse wire to digital pin 9. Is that right?

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
{                                  // in steps of 1 degree
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(15);                       // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
{
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(15);                       // waits 15ms for the servo to reach the position
}
}

• Does it work if you power the arduino from a wall wart? (using the DC jack?) – Jon May 13 '13 at 19:23
• Not tried. How about powering the servo externally? – Ghost May 13 '13 at 19:37
• I don't know much about Arduino, so I can't check the code, but I would suggest trying to light an LED (with series resistor) from the Arduino pulse pin to ground. Servos work on pulse of 20ms (50Hz) with the "on time" of 500 to 2500us controlling the rotation angle. If the pin is pulsing correctly, you should see the LED get brighter/ dimmer as the pulse width changes. The higher the "on time" the brighter the LED should be. – Kurt E. Clothier May 13 '13 at 22:10
• Can you put a scope or logic analyzer on digital pin 9 after detaching the servo? You should see a PWM style waveform. If you see PWM, then the problem is in the servo side. If not, in the software. – walrii May 14 '13 at 1:33

The AS-18 generates 6.5 kg-cm (0.6374 N-m) torque, and rotates at about 180 degrees per second, unloaded. This works out to an estimated power rating of 2 Watts (from calculator here).

Assuming 75% efficiency under no load, the power consumption at start of motion (when it is overcoming inertia) is thus around 2.67 Watts.

At 5 Volts and 2.67 Watts, current required is 534 Milliamps. This is above the current an Arduino's 5 Volt line can provide. It appears from the question that the Arduino's power source is USB: The USB port limitations of 500 mA reduce the available current to the servo, as the Arduino board itself will consume some of the available 500 mA.

Ideally, the power pin of the servo needs to be supplied by a separate 5 (or 6) Volt DC supply, with the ground of this external supply tied to the Arduino ground. 4 AA alkaline cells should suffice.

If this is not viable, then one could try to power the Arduino board with an external 7 to 12 Volt 1 Ampere or better DC supply, through the DC-in barrel jack on the board.

Do note, though, that the Arduino has a 500 mA resettable fuse on board. While the fuse should not blow on a momentary 500 mA load such as when the servo begins to rotate, if the servo is used to drive a significant load, the sustained current required may exceed the fuse trip point. Hence such an arrangement is marginal at best.

This brings us back to the recommendation of externally powering the servo.

• While this is a good thing to keep in mind, a simple (though not fully conclusive) test if this is the actual problem is to have the Arduino output serial debug messages while driving the servo, and monitor them; typically if there's a power problem the arduino will keep resetting and restarting it's messages. – Chris Stratton Jun 13 '13 at 20:52

Are you sure the upload to the Arduino is successfull? To make sure the code is running, you could put some serial prints in the code and then open the serial monitor to see it. For example, you could print every step by adding the line Serial.println(pos, DEC); right after myservo.write(pos). Don't forget Serial.begin(9600); in setup()