{"id":19125418,"url":"https://github.com/milind220/ball-balance","last_synced_at":"2026-05-05T22:35:48.614Z","repository":{"id":159632576,"uuid":"421900074","full_name":"Milind220/ball-balance","owner":"Milind220","description":"A PID algorithm controlled ball balance that returns a ball to a set point when it's pushed around. My first real robotics project! ","archived":false,"fork":false,"pushed_at":"2021-11-29T09:10:31.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-03T09:44:53.802Z","etag":null,"topics":["arduino","ball-balancing-pid","ball-balancing-platform","control-theory","cpp","pid-control","robotics"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Milind220.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-27T16:49:47.000Z","updated_at":"2023-03-04T09:22:56.000Z","dependencies_parsed_at":"2023-07-09T12:47:42.833Z","dependency_job_id":null,"html_url":"https://github.com/Milind220/ball-balance","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"2fcb4e3c10988e24b23e185074f265bb331a5edc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milind220%2Fball-balance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milind220%2Fball-balance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milind220%2Fball-balance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Milind220%2Fball-balance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Milind220","download_url":"https://codeload.github.com/Milind220/ball-balance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240190909,"owners_count":19762591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","ball-balancing-pid","ball-balancing-platform","control-theory","cpp","pid-control","robotics"],"created_at":"2024-11-09T05:35:42.707Z","updated_at":"2026-05-05T22:35:48.557Z","avatar_url":"https://github.com/Milind220.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PID Algorithm Ball Balance\n\nThis is a project that I made to better understand and apply the concept of PID control algorithms. The basic idea of this project is that a ball or a toy car is placed on the see-saw part of the balance, which actively tries to keep the object in the center. If the ball/toy car is externally disturbed, the balance/see-saw tilts in the opposite direction to negate the movement of the object.\n\nIn my project, the control algorithm I used was a simple PID (proportional-integral-derivative) control.\n\nYou can find complete videos of the project [here](https://drive.google.com/drive/folders/1BQwBAJkQs052C5EKD3FMkhIT8mthKC8j?usp=sharing)\n\n## How it works\n\nAn ultrasonic distance sensor (HC-SR04) mounted on one end of the see-saw measures the error (the distance between the set point, and the position of the object). It does this ~ 50 times/second, and feeds these readings into an Arduino Uno mounted on the base. The loop function in the Arduino contains the PID algorithm. With every run through the loop, it generates a total 'feedback value' based on the P, I and D gain values set. This is then mapped to a range of values which in turn control a servo motor (MG-996R) attached to the see-saw/balance. \nThis completes the closed loop control system.\n\n##  Gain Values\n\nI set the gain values through trial and error. To begin with, I set the I and D gain values to 0, and tuned the P value until the balance returned the ball/toy car to the set point with only slight oscillation.\n\nI then zeroed the P value as well, and tuned the D gain in isolation until the balance was effectively able to negate the velocity of the moving car/ball. At this point, with some additional minor tuning, the P-D controller was already very effective at returning the object to the set point and stopping its motion there. \n\nFor the I gain, I experimented with very small values and limited its max value to prevent oscillation. I also set a limitation that ensures that I gain is only considered when the object is within a very short distance of the set point.\n\nP gain: 5.3\n\nI gain: 0.07\n\nD gain: 1800\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilind220%2Fball-balance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilind220%2Fball-balance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilind220%2Fball-balance/lists"}