Tag Info

A PID controller is a control loop feedback mechanism (controller) commonly used in industrial control systems. Use this tag for discussions about PID algorithms and libraries.

## What is a PID controller?

A PID controller continuously calculates an "error value" as the difference between a measured process variable and a desired setpoint.

The letters PID stand for:

• Proportional
• Integral
• Derivative

Basically a PID algorithm takes two variables:

• The current measured value (eg. current fish tank temperature)
• The desired (target) temperature (eg. 25 °C)

The output is the manipulated variable (eg. in this case the amount of power to a heater).

For example, if the measured temperature was 20 °C and the target temperature was 25 °C, then the manipulated variable might be 5 (being the difference between the target and the actual).

The proportional configuration parameter simply multiplies the error by a fixed (proportional) amount. So in this case as the temperature of the tank approaches the target it would reduce the power to the heater.

The derivative configuration parameter multiplies the error by a derivative of the error (that is, the rate of change of the error). This means you might reduce the power as the temperature approaches the target, so as to not overshoot.

The integral configuration parameter multiplies the error by the accumulation of past errors, to compensate for the corrections being applied too slowly or too quickly.

## Library

There is an Arduino PID library (see Reference below) which allows you to supply the appropriate variables (target, error) and your tuning parameters (P, I and D).

You call the `Compute` function from time to time (eg. when going through the main loop) and it calculates a new manipulated variable, which you would then use to control your heater / motor / cooler / light or whatever-it-is you are controlling.