Demystifying PID Controllers in Building Services
How PID controllers keep HVAC systems on setpoint, from the three terms and loop vocabulary through digital execution, anti-windup, tuning methods, and a worked example.
When we work with building systems, especially HVAC, we constantly need to keep conditions like temperature, pressure, humidity, or airflow right where we want them. A PID controller is the tool that makes this happen. PID stands for Proportional, Integral, and Derivative. It is a closed-loop feedback system that watches the actual condition, compares it to the target we set, and then adjusts equipment such as valves, dampers, or fans to correct any difference.
In simple terms, the controller calculates an error. The error is just the gap between the value we want (the setpoint) and the value we actually measure (the process variable). Then it uses three separate calculations to decide how strongly to correct that error. Let us walk through each part so you can see exactly how it works.
The Three Terms That Drive PID Control
Every PID controller relies on three mathematical terms. Each one looks at the error from a different angle.
Proportional term (P)
This term reacts to the error right now. It multiplies the current error by a gain value we call . The bigger the error, the bigger the immediate correction.
You will notice that proportional action alone can bring the system close to the target quickly. However, it always leaves a small leftover error. That leftover is called steady-state offset. The controller needs some error to keep producing an output, so it never quite reaches the exact setpoint if only the P term is active.
Integral term (I)
This term looks at the history of the error. It adds up every bit of error that has occurred over time. Think of it as measuring the area under the error curve.
Because it keeps accumulating, the integral term slowly removes the offset that the proportional term leaves behind. Eventually the process variable matches the setpoint exactly.
Derivative term (D)
This term watches how fast the error is changing. It looks at the slope of the error.
When the error is racing toward the setpoint, the derivative term acts like a brake. It reduces the output early so the system does not overshoot. In theory this improves stability.
What each term is watching
The same loop seen three ways. Switch between the terms to see the offset proportional action leaves behind, the area the integral adds up, and the slope the derivative follows.
Proportional action climbs quickly and then stalls. The gap that never closes is the steady-state offset, because the controller needs some error to keep producing an output.
The model below puts all three terms on a real damper, so you can see the offset appear and disappear as you change the gains.
Try the three terms on a real damper
A variable-air-volume damper is trying to hold the airflow setpoint. Move the gains and watch which term does the work. The lower chart stacks how much of the damper command comes from P, from I, and from D at every sample. Choose P only and watch the airflow settle short of the dashed line. That gap is the steady-state offset. Switch to PI and the green band grows until the gap closes.
The Language of the Control Loop
Before we can understand how the controller makes decisions, we need to know the basic terms it uses.
- Process Variable (PV) is the actual measured condition. Examples include supply-air temperature from an air-handling unit or static pressure inside a duct.
- Setpoint (SP) is the target value we want to maintain.
- Error is simply .
- Control Variable (CV), sometimes called the manipulated variable, is the signal the controller sends out. It is usually a 0-10 V or 4-20 mA signal that tells a valve or damper how far to move.
Where each name sits in the loop
Select a term to light up the block it lives in. The pulse travels the way a real signal does: sensor to controller, controller to actuator, actuator back into the air.
The direction of the control action also matters.
In direct-acting mode, a rising process variable causes the controller to increase its output. Cooling valves often work this way: as room temperature climbs, the valve opens wider.
In reverse-acting mode, a rising process variable causes the output to decrease. Heating valves behave this way: as temperature climbs, the valve closes.
Direct acting or reverse acting
The measured temperature rises in exactly the same way in both cases, so the top panel never changes. Only the direction of the controller output changes: a cooling valve opens as the room warms, a heating valve closes.
Two physical characteristics of the system itself also shape the response.
Dead time is the pure delay between the moment the controller changes its output and the first moment the process variable starts to react.
The time constant is the time needed for the process variable to reach about 63 percent of its final new value once it begins to move. Thermal mass and fluid volume largely determine this lag.
Process gain tells us how sensitive the system is: how many degrees or how many litres per second the process variable changes for a one-percent change in the control signal.
Dead time, time constant and process gain
The controller makes one step change in its output at the marked moment. Everything after that belongs to the physics of the duct, the water and the thermal mass. The dot marks the moment the process variable has moved 63 percent of the way to its new value: one time constant after the movement begins.
From Physical Condition to Digital Error
Let us follow a concrete example. Suppose a room is at 26 °C and we want it at 22 °C.
- The wall thermostat contains a thermistor. At 26 °C its resistance is exactly 9,310 ohms.
- The direct digital controller (DDC) applies a reference voltage across that thermistor. An analog-to-digital converter reads the resulting voltage and turns it into a binary number.
- Firmware inside the controller uses a lookup table to convert that binary number back into a temperature reading of 26 °C.
- The controller then subtracts the setpoint: 26 °C - 22 °C = 4 °C. That 4 °C difference is the error that enters the PID calculation.
The same four steps, as the signal sees them
Press play to send the room condition through the thermostat, the converter and the firmware until it arrives as a number the PID calculation can use.
How a Digital PID Processor Actually Works
Modern PID control is simply software running on a microprocessor inside the DDC. The processor keeps a few important values in memory: the current error, the previous error, and a running total of all past errors (the integral accumulator).
The calculation does not run continuously. It executes at a fixed interval, usually every 1 to 5 seconds for HVAC applications. Because the processor works with discrete time steps, it cannot perform true continuous integration. Instead, every second it multiplies the current error by the time interval and adds that product to the integral accumulator. The derivative term is calculated from the change in error between the current and previous samples.
What the processor sees between samples
The smooth line is the real error in the room. The controller only ever sees the dots. Each shaded block is one multiplication of error by time interval, added straight into the integral accumulator. Stretch the interval to 5 seconds and the blocks become coarse: the controller is still adding up area, but it is guessing more between each look.
Turning Math into Valve Motion
Once the three terms are calculated, the processor adds them together to obtain the total control variable.
The digital percentage is then converted by a digital-to-analog converter into a physical voltage, for example 6.5 V for a 65 percent command. That voltage travels to the actuator, which positions the valve stem at exactly 65 percent of its stroke.
From the calculated number to the valve stem
Slide the calculated total past 100 percent and watch the clamp hold the output while the accumulator freezes. The voltage and the stem position follow the clamped command, never the raw number.
How the Three Terms Share the Work
The relative importance of P, I, and D changes as the process moves.
At the very beginning, when the error is large, the proportional term dominates. It opens the valve quickly. The integral has not yet had time to accumulate, so it contributes almost nothing.
As the process variable approaches the setpoint, the error shrinks and the proportional contribution falls. Meanwhile the integral has been quietly adding up the remaining error. The integral term gradually takes over the job of holding the valve open.
When the process variable finally equals the setpoint, the error is zero. The proportional term therefore produces zero output. The integral term alone holds the exact steady-state position the valve needs.
If a sudden disturbance occurs (a door opens and a heat load rushes in), the error is still small and the integral has not yet reacted. The derivative term, however, sees the steep slope of the rising temperature and immediately boosts the output to counteract the surge.
Who is holding the valve open
Step through the life of one correction. The bars show how much of the output each term is providing at that moment.
At the very beginning, when the error is large, the proportional term dominates. It opens the valve quickly. The integral has not yet had time to accumulate, so it contributes almost nothing.
Finding the Right Gains
Because every mechanical system is different, we must tune the three gains in the field.
A common practical method is trial and error. First set the integral and derivative gains to zero. Increase the proportional gain until the system oscillates with a steady amplitude. Then cut that gain in half. Slowly raise the integral gain until the steady-state offset disappears without excessive overshoot. Leave the derivative gain at zero for most HVAC loops.
A more formal approach is the Ziegler-Nichols method. We raise the proportional gain until the system just sustains continuous oscillation. That critical gain is called the ultimate gain . We also measure the time between successive peaks, called the ultimate period . Standard formulas then give us the recommended gains. For a PI controller the formulas are roughly and .
Raise the gain until the oscillation just sustains
Push the proportional gain up slowly. Too little and the wobble dies away. Too much and it grows until the actuator is slamming. The one gain that holds a steady amplitude is the ultimate gain, and the suggested PI gains appear once you find it (0.45 times Ku, and 1.2 times Kp divided by Tu).
Many modern controllers also offer auto-tuning. The controller forces a deliberate step change, measures the dead time and process gain of the real system, and calculates suitable parameters automatically.
A Numerical Walk-Through
Let us put numbers to the ideas with a variable-air-volume airflow loop. The execution interval is one second.
- Setpoint = 500 L/s
- Current airflow = 300 L/s
- Gains: , ,
At the first sample (t = 0 s)
- Error = 500 - 300 = 200 L/s
- Proportional = 0.10 × 200 = 20 %
- Integral (accumulator starts at 200) = 0.05 × 200 = 10 %
- Derivative (slope treated as 200 for the first step) = 0.02 × 200 = 4 %
- Total output = 34 % damper open
One second later (t = 1 s)
Airflow has risen to 400 L/s.
- Error = 500 - 400 = 100 L/s
- Proportional = 0.10 × 100 = 10 %
- Integral (accumulator now 200 + 100 = 300) = 0.05 × 300 = 15 %
- Derivative (change in error = 100 - 200 = -100) = 0.02 × (-100) = -2 %
- Total output = 10 + 15 - 2 = 23 % damper open
Two samples, one second apart
Step through the arithmetic above and watch the damper follow the running total. Setpoint 500 L/s, starting airflow 300 L/s, gains Kp 0.10, Ki 0.05, Kd 0.02, execution interval one second.
Error = 500 - 300 = 200 L/s
Notice what happened. As the airflow moved closer to the setpoint, the proportional contribution dropped while the integral contribution grew. At the same time the derivative term went negative and reduced the total output, helping prevent overshoot.