Ball Balancing Arduino-Style

If you have a good sense of balance, you can ride a unicycle or get on TV doing tricks with ladders. We don’t know if [Hanna Yatco] has a good sense of balance or not, but we do know her Arduino does. Her build uses the ubiquitous HC-SR04 SONAR sensor and a servo.

This is a great use for a servo since a standard servo motor without modifications only moves through part of a circle, and that’s all that’s needed for this project. A PID algorithm measures the distance to the ball and raises or lowers a beam to try to get the ball to the center.

Servos like this usually operate in radio control vehicles and they are very easy to drive. A pot coupled to the shaft generates a pulse that the servo internally compares to a pulse from the microcontroller. If the pulse is wider than the reference pulse, the motor drives in one direction. If the pulse is narrower than the reference, the motor operates in the other direction. Just how much it drives depends on how much difference there is between the two pulses. When the pulses match, the servo motor stops moving. This pulse arrangement is very simple to drive from a logic output on an Arduino or other microcontrollers.

The build details are a bit sparse, but you can see in the video the general layout, and she links to a similar project that inspired this one if you are looking for more details.

You can do the same trick in two dimensions if you prefer. Or perhaps you’d like to try using a time of flight sensor, instead.

17 thoughts on “Ball Balancing Arduino-Style

      1. It keeps happening so it is plural, more than one osculation event, therefore osculations.

        There is a term for people like you, “idiot”, and you are also a liar because you do not hate to be “that guy”, you enjoy it, well you did before I pointed out that “that guy is a self inflicted euphemism for “idiot”.

        1. *ahem*
          I love to be “that guy”, but

          Oscillation, noun, number of ‘u’s present: 0.
          I actually learned the word osculating in multivariable calc. You could say the sonar sensor and the ball osculate in the beginning of the video (when they touch), but we all understand what you meant.
          Words are neat!

  1. I prefer the ‘ol ping pong ball-in-a-clear tube controller. A 12v blower at the bottom of the tube and an ultrasonic sensor at the top. Use your PID and other control algorithms to hold the ball at a set-point. Very challenging and visually interesting.

  2. Re siluxmedia: Most ultrasonic sensors have a blind spot in front of them where the sensor reports that an object is farther away than it really is, I was using an ultrasonic sensor for a LEGO NXT that had a blind spot about 5 cm in front of it where it reported that a ping-pong ball was 20 cm away, and it was one of the better sensors in the entire class IIRC.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.