Jittering Servo Problem - a mind of it's own!

Hi All,

In testing a servo setup for my little rover, I wrote the below snippet of code to basically start the servo from the centre position (90), move to the extreme right/left, wait a second, move back to the centre, wait a second, then move back to the extreme right/left etc..

This was just a little test to check angles for sensor positions, but has shown some undesirable results! The servo seems to have a mind of it's own. It will run fine a couple of times in the loop, then flick back and fourth, continue and then do it again at random. At first I thought it might be a power issue running from USB whilst programming the board, but same thing happens on external power. It's an Acoms AS-17 Servo and the code is below. Am I mis-using the myservo.write command somehow?

Thanks in advance! :

#include <Servo.h>

Servo myservo;

void setup()
{
myservo.attach(11);
}

void loop()
{
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(0);
delay(1000);
}

What are you using for an external power source?

A brand new 9v PP3 battery (Energizer, so it's a decent one).

I've had another thought also. Both the 'Sweep' and 'Knob' examples work fine with this servo, but then it does move at a slower speed. My code snippet above moves the Servo at it's max speed. It could be upsetting the potentiometer inside the Servo (it's only a cheap one), making it think it's position is different to what it actually is, causing it to randomly move somewhere else.

With that in mind, is there an one line of code that makes the Servo move in increments like in the Sweep routine, or do I need to use the arguments: for(pos = 0; pos < 180; pos += 1) as in the Sweep example.

I was hoping on something like myservo.write(180, += 1) but no joy.

Did you connect the grounds?

Red lead of servo is connected to +5v on the Arduino, black to GND and the yellow lead to pin 11 (which I double checked is a PWM pin).

Surely there someway of controlling it's speed so it doesn't go to 0 or 180 degrees at full pelt!

The library has no speed control, you have to use a for loop with dealys or a state machine.

BTW it isn't PWM, it's PPM

What is the power supply for the servo - 9V is an unusual supply voltage for a servo

I'm powering the Arduino from a 9v battery and connecting the servo to the +5v on the Arduino, which should give the servo 5V right? Like i've stated previously, have had no problems with the sweep or knob examples using the same setup, so I leaning towards the fact that the servo is cheap and nasty and not liking moving so quickly.

I've wired the servo in the example tutorial for 'sweep'.

You should always use a separate supply for servos.
It sounds like your processor is browning out.
PP3s are not noted for their ability to provide lots of current, which is what servos draw when changing position rapidly

How would one power the servo externally?

I've tried connecting the red and black leads of the servo to + and - of a 5v external suppply (well, 4.8v - rechargables) with the yellow pin connected to the pin of the arduino... now it does nothing at all.

Sorry confused beginner here!

You need to connect the black lead from your battery pack to the servo and the Arduino's ground pin

So just to confirm that is:

Yellow -> digitial pin
Red -> battery pack
Black -> battery pack and Arduino ground pin?

Many thanks for all your help.

That's correct.

I shall give it a try and see how I get on! Thank AWOL.