Restricting Servo Boot Up Movement

I have an application where, on a circuit boot-up, servo should stand still at its last position. Circuit is pretty darn basic, just Arduino Mega and RC Servo signal wire connected to the PWM pin #9. Servo gets power from its own battery.

What I am getting is, each time I boot up the Arduino servo moves. Usually it goes all the way to 0 and than back to middle. But it can be just 20-30 degrees to left and than right, followed with a rest.

Is there a way to 'freeze' the movement of Servo on start up?

Is there a way to 'freeze' the movement of Servo on start up?

The servo goes to some position when the Servo::attach() function is called. Which position? The last one written to it. So, if you want the servo to go to a specific position on start up, call Servo::write() before Servo::attach().

Is there a way to 'freeze' the movement of Servo on start up?

Actually it is harder then my first appear. As an arduino on power up or reset has no way to know where the servo was last positioned unless you were to have saved the position value in EEPROM memory prior to powering down or resetting the arduino, and use that in your start-up code. Not hard to have the servo commanded to some specific position on start-up, but that is not the same as where the servo may have last been positioned prior to power cycling or resetting the arduino.

Lefty

servo should stand still at its last position.

Your problem to solve is how to have the arduino remember the last position.

Does the Arduino send anything other than noise to the servo on startup? Is this just noise that occurs before the code is running? Might try a relay in the power circuit to the servo and turn it on at the end of the setup routine. You might still get some jump as the amplifiers and motor bridge in the servo come alive. Some servos are worse than others as to how they will twitch when they are powered up.

Does the Arduino send anything other than noise to the servo on startup?

The servo library has the start-up servo position value in the Servo.h file:

#define DEFAULT_PULSE_WIDTH  1500     // default pulse width when servo is attached

That could be changed to any desired starting position command. However that has nothing to do with where the servo may have been positioned prior to it being reset or powered down.

1 Like

Hey guys, What I like about you, you always come up with usefull stuff.

This will help a lot.

1 Like