Why is my servo moving back and forth after servo.attach() ?

Hi all,

I’m trying to use servo library with simple example like the one below. Theoretically after attach() servo should go to the position defined by default pulse set in servo library. What is happening in my case is that servo goes to specific position, but hen slowly (about 3 sec) moves in one direction (about 90 degree) and then coming back faster (about 1sec). This movement repeats about 9-11 times and servo stops for another 10-15 sec after which everything starts all over again. Can someone explain to me why is this happening?

I’m using PowerHD LF-20MG-270 servo.
Servo is powered from separate 4xAA pack grounded to arduino ground

#include <Arduino.h>
#include <Servo.h>

Servo myservo;

void setup() {
    // put your setup code here, to run once:
    myservo.attach(9);
  //  myservo.writeMicroseconds(1500);  // set servo to mid-point
}

void loop() {
    // put your main code here, to run repeatedly:

}

Is your Arduino restarting?

AWOL:
Is your Arduino restarting?

No, it's not. I ended up using lots of attach() and detach() functions, and this is giving me the bests results so fat. But, this is just a workaround and way to far from the solution I'm looking for.

Double check your wiring

AWOL:
Double check your wiring

I did and all seems to be absolutely fine. Here is short video showing the servo.

At this point, I'd be reaching for my scope probes, or binning the processor

The battery pack may be inadequate. The stall current for that servo is 2.7 Amperes, which fresh alkaline AA batteries can't supply without severe voltage drop.

wzbart:
No, it's not. I ended up using lots of attach() and detach() functions, and this is giving me the bests results so fat. But, this is just a workaround and way to far from the solution I'm looking for.

I do not see your lots of attach/detach. Have you modified the code? Can you post that code?

Can you post a diagram of your wiring? Pencil, paper and a camera are good enough.

vinceherman:
I do not see your lots of attach/detach. Have you modified the code? Can you post that code?

See this thread.

jremington:
The battery pack may be inadequate. The stall current for that servo is 2.7 Amperes, which fresh alkaline AA batteries can't supply without severe voltage drop.

Interesting. That might be it. I will check with 10A power supply and will let you know.

Sorry I'm coming back to you so late but I wasn't really able to test until now. I have used a power supply to power up that big servo and all seems to be absolutely fine. I guess I will need to by 2s lipo and test it again.