Self Balancing Gyroscope V3 Using Arduino and Pot for Tilt Sensor




Introduction: Self Balancing Gyroscope V3 Using Arduino and Pot for Tilt Sensor

About: I am an American teaching English at Shangluo University, Shaanxi. I like making machines that do interesting but fairly useless things - I call them Quixotic Machines.

Here is the continuing saga of my gyroscope - in this version I use an Arduino Uno and a potentiometer to swing a counter weight to balance a precessing gyroscope so that it will balance indefinitely on two chopsticks.
Now that it is balancing itself I guess I will add back the wheels and take it for a spin.

Photo 1: shows the Arduino Uno connected to pc and to servo and to a 10k potentiometer which measures the tilt of the gyroscope rotor. The program tries to keep the rotor level which will in turn keep the gyro balancing on the two chopsticks.
Note: for a gyroscope to balance on the chopsticks the Center of Mass (COM) must be about a centimeter above the rotor - a point that took me a while to discover.
Photo 2:  shows a closeup of the potentiometer connected to the gimbal axis of the gyroscope. It works very well and is an accurate indicator of the angle of the rotor.
Photo 3:  is a closeup of the servo counter weight mechanism.
Photo 4:  is a university gyro that gave me an idea of how to make mine.

Here is the full program:
Servo signal is connected to pin 9 and the pot middle terminal is connected to A2. Also you must connect servo power and ground and the two outer pot pins to 5volt and grnd on the Arduino. 
The gyro motor is powered separately to prevent interference with the Arduino though it could probably be powered by the PWM of the Arduino.
Servo servo1;
int servangle = 0; // servo angle variable
int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the value coming from the sensor
int valInc = 4;
int currAngle = 0;
int newAngle = 0;
int delayTime = 0;

void myServo(int curAngle,int newAngle,int angleInc,int incDelay) {
  if (curAngle < newAngle) {
   for(int angle=curAngle;angle < newAngle;angle += angleInc) {
        delay(incDelay);   }
   else if (curAngle > newAngle) {
      for(int angle=curAngle;angle > newAngle;angle -= angleInc) {
        delay(incDelay);   }
void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT

void loop() {
  val = analogRead(potPin);    // read the value from the pot sensor
  delayTime = 10;

  if (val >= 420 && val <= 435)   digitalWrite(ledPin, HIGH);  // turn the ledPin on
  else digitalWrite(ledPin, LOW);   // turn the ledPin off

  if (val >= 420 && val <= 435)     { newAngle = 90; delayTime = 40;}
  else if (val >= 300 && val < 410) { newAngle = 50; delayTime = 1000; }//force back down
  else if (val > 445 && val < 500) { newAngle = 130; delayTime = 1000;}// force front up
  //Serial.print(val); Serial.print(" ang: "); Serial.println(newAngle);
  if (newAngle != currAngle) {
     Serial.print(val); Serial.print(" ang: "); Serial.println(newAngle);
     currAngle = newAngle;

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Sensors Contest

Participated in the
Sensors Contest

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020

    6 Discussions

    sáng tạov
    sáng tạov

    3 years ago

    if you have free time, the closer your guide is not it

    I am Vietnamese

    see his friends or the self-employed 1 also want the

    this is his facebook


    4 years ago

    can u give full detail, how to connect arduino circuit?? pleasa


    6 years ago on Introduction

    I think you would enjoy a YouTube channel by Thomas Jenner,

    I like how you used the potentiometer to adjust the counterweight, and I suspect you could do it without the arduino. I don't know if you are into analog robotics, but this YouTube channel shows some interesting stuff about how he makes a balancing robot with a 555 chip.


    Reply 6 years ago on Introduction

    Thank you for your input. I watched a couple of his videos and found I was familiar with some of his stuff ("Ball Whacker" and analogue self-balancing robot). I actually thought about using a 555 or transistors at one point but I had the Arduino from another project and it took like a few minutes to get everything set up. For the balance routine as it stands, I totally agree you could do it with a lot less than the Arduino. However the program really needs to look at performing some corrective movements at a certain time during the precession (specifically when the rotor is tilted at it's most extreme angle, and the speed with which the servo is returned, and delay time before it is returned - some of which I have not done yet), for that I think you need some sort of programming environment, at least without building a seriously complex circuit. But someone could definitely build a small circuit using a 555 to perform my little corrective routine. Thanks again, hope someone does it.