Is PID controller working correctly in my self balancing robot project?

Thread Starter


Joined Dec 29, 2017
Hello. I have built a self balancing robot. I have used potentiometers to adjust pid controller gains. I guess, if it worked correctly, it would fall when I make zero all gains.

No matter how low the gains or how high, it is always stable . It is generally stable with the same rising time and oscillations.

Why do you think it is? My advisor said it might be set not to a good value but I don't know what it means.

So full code is here,
by the way the source of arduino sketch and used libraries is here, at below of the page

I know from the code that

void readPIDTuningValues()
int potKp = analogRead(A0);
int potKi = analogRead(A1);
int potKd = analogRead(A2);

kp = map(potKp, 0, 1023, 0, 25000) / 100.0; //0 - 250
ki = map(potKi, 0, 1023, 0, 100000) / 100.0; //0 - 1000
kd = map(potKd, 0, 1023, 0, 500) / 100.0; //0 - 5

So when I change potentiometer, the assignments
between 0-250 for kp, 0-1000 for ki, 0-5 for kd will occur.

What should it be look like actually? Is kp much or kd is less?
Why do you think changing potentiometer values do not affect to the robot?
Wiring diagram is the same as in the website I provided you.

Thread Starter


Joined Dec 29, 2017
It was solved. There are potentiometers to adjust PID controller in the project and I had to activate it, changing
"#define MANUAL_TUNING 0 "
"#define MANUAL_TUNING 1" in the code. Now it is falling over with little disturbances for bad tuning.