# How does the PID controller actually work?

Preferably PID functions on an Arduino uno or any other examples. I have been researching but many of the the websites really do not explain it.

P.S is there an algorithm for a PID? Thanks

• Wikipedia explains it perfectly. Maybe the problem is that you don't understand the explanation? Commented Jan 3, 2016 at 13:19
• @Majenko, Hmm, I'd say if people aren't understanding it perhaps the Wikipedia explanation isn't "perfect." Also, quite a few sites don't really explain the terms and what each one does (e.g., how you'd think about or tune a PID controller).
– dlu
Commented Jan 3, 2016 at 21:33
• When you're asking questions about subjects you're not understanding it really helps if you can say what you've learned in your research and focus the question on the next part you'd like to understand.
– dlu
Commented Jan 3, 2016 at 21:34
• controls.engin.umich.edu/wiki/index.php/PIDIntro Commented Jan 4, 2016 at 4:24
• brettbeauregard.com/blog/2011/04/… is an excellent explanation of the playground.arduino.cc/Code/PIDLibrary Commented Jan 5, 2016 at 21:12

I, also, didn't get the idea behind PID from just reading Wikipedia. After some videos/tutorials, I believe the best way to explain it is:

What is PID

PID is an algorithm. It involves three factors which can be adjusted to tune a signal.

It is often used in servo's (and things like thermostates, basic signal controllers)

Imagine this

The servo will be used in the practical examples.

A servo has: - a current position (signal) - the position you want the servo to be in (goal signal) - a speed (PID output signal)

The PID output signal/algorithm makes sure that the servo reaches it's goal.

In short:

PID is an algorithm that can adjust a signal towards an setpoint. Or correct it for that matter. It regulates how much you have to adjust the signal, without getting serious overshoot, or oscillation around the setpoint.

Detail:

P stands for proportional.

Which means that the further the servo is from it's setpoint, the more speed we want to/can give it. So that we're faster towards the set point. This also means that we slow down as we near the set point. Of course you can multiply each of these rules with a factor, to achieve a better balance.

I stands for integrating.

It basically comes down to the fact that it constantly keeps adding to the signal, depending on how long there is a difference between the current point and set point. This is so that if P is still a little slow, it adds some speed over time.

D stands for differentiating

It's less commonly used. (Wikipedia) The D factor reacts on the speed of the change in value. Or speed of change in setpoint (Dutch wikipedia is not 100%, comment if neccesary :) )

These factors / the algorithm provides a smooth regulation of various systems, hence that's why it is so adjustable.

It can be used for balancing quadcopters or making your house comfortably warm (without sudden changes, or too slow changes)

Why?

How would you balance a quadcopter? If it shifts to one side, you don't want to fully reverse the throttle. It'll make it wobble, since you get a lot of overshoot. Controlling things can be hard, PID is an known working algorithm for those cases. But you have to adjust the factors right to adjust it to your specific system. (They all react differently, or have to react differently).

• +1, but stabilizing a quadcopter can't really be done with a single PID loop; it usually takes 2 cascading PID loops, one for rotational position and one for rotational velocity /Pedantry Commented Jan 7, 2016 at 23:16
• @BrettAM Good point, I thought each axis could be controlled individually by a PID loop, but it might indeed make sense to couple them in some way.
– aaa
Commented Jan 8, 2016 at 10:19
• You can use a single pid for each axis, roll, pitch, & yaw. Velocity is handled by bias. Eg github.com/benripley/Arduino-Quadcopter Commented Dec 5, 2022 at 17:15

How a PID controller works depends on the particular implementation.

There is a algorithm/library for PID on the Arduino: http://playground.arduino.cc/Code/PIDLibrary and an excellent explanation of the all of functions within it at http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

Over on stackoverflow and electronics, there are some good questions and explanations that might help: