3
\$\begingroup\$

I have a small Arduino Uno powered robot I'm entering in a competition, and it uses some small servos to position sensors and other actuators. According to the rules, it can't move until a pre-determined signal is received, at which point the robot is manually switched on. However, when it starts up, the Arduino will actuate the servos to random positions, causing a "jitter" that would immediately disqualify the robot.

How do you wire/code the Arduino so that, when initially switched on, any attached servos will remain at their current position and will not "jitter" at all?

The servos are connected to the standard DIO pins using the built-in servo library.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ What does your power supply look like, how have you wired the various parts to it and did you add any extra components to it except servos and the controller? \$\endgroup\$
    – jippie
    Commented Mar 3, 2015 at 7:44
  • \$\begingroup\$ I'm only using an Arduino. The servo is a micro-servo HXT900, which is small enough to be powered directly from the Arduino's 5V pin. \$\endgroup\$
    – Cerin
    Commented Mar 3, 2015 at 18:14
  • \$\begingroup\$ Arduino is not a power station, don't use it as such. I doubt the jitter is solved by the accepted answer, but I am obviously wrong on that part. \$\endgroup\$
    – jippie
    Commented Mar 3, 2015 at 19:18
  • \$\begingroup\$ @jippie, Just tested it and it solved the problem. \$\endgroup\$
    – Cerin
    Commented Mar 4, 2015 at 4:42

2 Answers 2

2
\$\begingroup\$

When powering on an Arduino obviously you won't have the Servo positions (as you say), so you need to determining the position of the servo after turn-on. This is not easy. It would involve additional rotational position sensors.

If you really need the Arduino to power up from being completely powered off then I would "park" the servos to a certain position before power-off. Then during initialisation after power-on return the servos to the parked position, and so clearly they would not move.

Alternatively, you could consider a sleep mode for your robot where the Arduino does not truly power off and therefore the variables containing the servo positions are not cleared.

\$\endgroup\$
1
  • \$\begingroup\$ Yeah, that's also what this forum post recommends. Fortunately for my application, I'm easily able to "park" the servos. \$\endgroup\$
    – Cerin
    Commented Mar 3, 2015 at 18:20
2
\$\begingroup\$

Although @akellyril's answer solved it partially, I was still seeing a little jitter. To completely solve it, I wired an NPN transistor to allow cutting off the servo 5V line via an Arduino pin, as described here.

Another minor issue I ran into was that, even when the servo was in the correct position and under no load, it would "whine" and make a lot of noise even with the 5V line cut. I found that calling the servo's detach() method fixes this.

To summarize, my pseudo-code looks like:

  1. Set servo power control pin to output and set low to turn off.
  2. Set servo to "parked" position.
  3. Attach servo.
  4. Set servo power control pin to high to turn on servo.
  5. Move servo for application.
  6. Set servo to parked position.
  7. Detach servo.
  8. Set servo power control pin to low to turn off.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.