Servo Chatter

When I initialize my robot, the starboard (right-hand) servo chatters at the neutral position. As you can see from the video, for some reason this affects only the starboard servo and not the port (left-hand) servo. I think the reason has something to do with the manual adjustment not being centered.

Anyhow, rather than carefully tweak the servos manually, there is another way to avoid needless chattering. And that is to modify the servo attachment commands in the Arduino sketch.

What I was doing before was placing the servo attachment commands in the setup function, like so:

void setup(){



The solution is to place the servo attachment commands in the loop() function just before the action function and then place servo detach commands immediately thereafter, like so:

void loop(){

if (rmode == 1) {
rmode = 0;

. . . where servo_on() attaches the servos as before and servo_off detaches like so:

void servo_off(){



By attaching the servos just before they’re used and detaching them immediately thereafter, I am minimizing the time the servos can chatter. In other words, servos can only chatter when they’re attached.

Note that when using the servo detach() command, the pin number is not expressed. That’s because the servo object remembers which pin it was assigned to by the attach() command. If you put a pin number in the detach() parens, you won’t just be making extra work for yourself, you’ll generate a compiler error message (as I learned to my puzzlement for several minutes).

About engineerzero

Once and future engineer.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s