Raspberry Pi Projects

DIY Balancing Robot (This Robot Doesn’t Let The Ball Fall Off)

A balancing robot is a great project for anyone interested in robotics. in this project, we will use a Raspberry Pi to control a computer vision system that will be used to balance a ball on a beam. A simple project using a Raspberry Pi and three servos.

Balancing Robot

This robot doesn’t let the ball fall off from interestingasfuck

Balancing Robot Parts list :

The rest of the parts are 3D printed.

The device consists of a camera, a processing unit, and a Servo motor. The motor is used to move the beam so that the ball is always in the middle of the camera’s field of view. A computer vision system is a powerful tool that can be used to perform various tasks, including object recognition, motion detection, and even balancing a ball on a beam.


The system is always adjusting the beam’s position to keep the ball from falling off. If the ball does fall off, the system will automatically restart the balancing process. The ball balancer is an example of how computer vision can be used to solve a real-world problem. It shows how a Raspberry Pi can be used to control a physical device.

The principles behind the project:

  1. A Raspberry Pi camera tracks the status of the ball, operating OpenCV. A show is first applied to separate the orange colour of the ball from the rest. The mask is then eroded double, blurred, and finally, a ‘smallest enclosing rotation’ command replaces the radius and the centre position.

  2. This detail is then filtered by radius. If it is part of the range of radii that the ball is expected to have, the program calculates the error between the position of the ball and the centre of the plate. Three errors total are calculated, one for each servos’ line of action.


The first step is to set up the Raspberry Pi and install the necessary software. We will need to install the Raspbian operating system and the OpenCV library.

  • Raspbian is a free operating system based on Debian that is optimized for the Raspberry Pi hardware.
  • OpenCV is a powerful open-source computer vision library that will allow us to perform the necessary image processing tasks.

Next, we need to connect the Raspberry Pi to the computer vision system. We will be using a USB webcam for this purpose. Once the connection is made, we can now start to write the code that will be used to control the system.

The code will firstly capture an image from the webcam and the camera is used to capture images of the ball as it rolls along the beam. The computer then analyzes the images and calculates the amount of force needed to keep the ball balanced. This image will then be processed to find the position of the ball. Once the position of the ball is known, the Raspberry Pi will then calculate the necessary amount of force that needs to be applied to the beam in order to balance the ball. we used computer vision to control the movement of a ball on a plate.

This force will be applied using a small servo motor. The complete code for this project can be found at the following link: https://github.com/nicohmje/PID-ballonplate/tree/main/Python

This robot doesn’t let the ball fall off from interestingasfuck

Source & Credit 

Leave a Reply

Your email address will not be published.

Related Articles

Back to top button