232  PID Control Fundamentals

232.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Explain the three components of a PID controller (Proportional, Integral, Derivative)
  • Define and calculate error in feedback control systems
  • Understand how proportional control responds to current error magnitude
  • Identify the limitations of proportional-only control
  • Apply the PID equation to calculate controller output

232.2 PID (Proportional-Integral-Derivative) Control

Block diagram of PID controller showing error signal splitting into three parallel paths: Proportional term (Kp times error for immediate response), Integral term (Ki times accumulated error for steady-state correction), and Derivative term (Kd times error rate for overshoot prevention), all summing to produce final control output
Figure 232.1: PID control system block diagram showing the three parallel control actions: Proportional (responds to current error), Integral (eliminates steady-state error), and Derivative (anticipates future error)

While simple closed-loop systems provide basic feedback, achieving optimal performance often requires more sophisticated control algorithms. The PID controller is the most widely used feedback control algorithm in industrial and IoT applications.

232.2.1 PID Overview

Block diagram of a closed-loop feedback control system with setpoint input, error calculation, PID controller, plant/process, and sensor feedback path
Figure 232.2: Closed-loop feedback control system showing setpoint, controller, plant, and sensor in a continuous loop

A PID controller uses three different control strategies simultaneously, each addressing different aspects of error correction:

  1. P (Proportional): Reacts to current error magnitude
  2. I (Integral): Reacts to accumulated error over time
  3. D (Derivative): Reacts to rate of error change

Imagine you’re driving on a highway and need to change lanes. Your brain performs PID control naturally:

232.2.2 Proportional (P) - React to the Error

  • Situation: You’re 2 feet from where you want to be
  • Response: Turn the steering wheel proportionally - bigger error = bigger turn
  • Problem: If you only use P, you’ll overshoot and oscillate!

232.2.3 Integral (I) - Eliminate Steady-State Error

  • Situation: A crosswind keeps pushing you right
  • Response: You notice you’re always a bit off, so you hold the wheel slightly left
  • The I term accumulates past errors and corrects persistent bias
  • Real IoT example: Temperature sensor with consistent 0.5C offset

232.2.4 Derivative (D) - Anticipate and Dampen

  • Situation: You’re approaching your target lane fast
  • Response: You start turning back before you reach it to avoid overshooting
  • The D term predicts future error based on rate of change
  • Real IoT example: Slowing down a motor before it hits the target position

232.2.5 The Complete Picture

Term Responds To Fixes Danger If Too High
P Current error Immediate deviation Oscillation
I Accumulated error Persistent bias Overshoot, instability
D Rate of change Overshoot Noise amplification

Key insight: Most IoT control uses PI (no derivative) because sensor noise makes D unstable. Only use D when you have clean, high-frequency data!

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'fontSize': '15px'}}}%%
graph TB
    SP["Setpoint"] --> Error["Error<br/>Calculation<br/>(SP - PV)"]
    PV["Process<br/>Variable<br/>(Measured)"] --> Error

    Error --> P["P Term:<br/>Kp × error<br/>(Current Error)"]
    Error --> I["I Term:<br/>Ki × ∫error dt<br/>(Accumulated)"]
    Error --> D["D Term:<br/>Kd × d(error)/dt<br/>(Rate of Change)"]

    P --> Sum["Σ<br/>Sum"]
    I --> Sum
    D --> Sum

    Sum -->|Control Signal| Plant["Process/<br/>Plant"]
    Plant -->|Output| PV

    style Error fill:#E67E22,stroke:#16A085,stroke-width:2px,color:#fff
    style P fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style I fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style D fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style Sum fill:#E67E22,stroke:#16A085,stroke-width:3px,color:#fff
    style Plant fill:#7F8C8D,stroke:#16A085,stroke-width:2px,color:#fff

Figure 232.3: PID controller: P, I, D terms summed for control signal

PID Controller Block Diagram: Error signal splits into three parallel paths. P term responds to current error, I term accumulates past errors, D term predicts future based on rate of change. All three combine to produce optimal control signal.

PID Equation:

\[ u(t) = K_p \cdot e(t) + K_i \cdot \int_{0}^{t} e(\tau) \, d\tau + K_d \cdot \frac{de(t)}{dt} \]

Where: - \(u(t)\) = Controller output at time \(t\) - \(e(t)\) = Error (Set Point - Process Variable) - \(K_p\) = Proportional gain - \(K_i\) = Integral gain - \(K_d\) = Derivative gain

Common PID Combinations:

Table 232.1: PID Mode Combinations
Mode Usage Application Examples
P Sometimes Simple temperature control, LED brightness
PI Most common HVAC systems, level control, pressure regulation
PID Sometimes Motor speed control, precision positioning
PD Rare Servo motors, fast response systems

232.3 Understanding Error in PID Control

The foundation of PID control is the error signal:

Process Variable (PV):
The actual measured value of what we’re controlling (e.g., current temperature)
Set Point (SP):
The desired target value (e.g., target temperature)
Error (e):
The difference between desired and actual values

\[ e(t) = SP - PV(t) \]

PID temperature control example showing room starting at 18C with target 22C creating +4C error, proportional term providing strong initial heating, integral term accumulating error over time, derivative term detecting rapid temperature rise and reducing heating to prevent overshoot, system smoothly reaching and maintaining 22C setpoint
Figure 232.4: Practical example of PID control applied to home temperature control system showing sensor feedback, error calculation, and combined P+I+D control actions

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'fontSize': '14px'}}}%%
flowchart TB
    Start["Initial State:<br/>Room 18°C<br/>Target 22°C<br/>Error +4°C"] --> P1["P: Strong Heat<br/>(Kp × 4)"]
    Start --> I1["I: Accumulating<br/>(Ki × ∫4 dt)"]
    Start --> D1["D: Rate = 0<br/>(No change yet)"]

    P1 & I1 & D1 --> Heat1["Full Heating"]
    Heat1 --> Mid["After 5min:<br/>Room 20°C<br/>Error +2°C"]

    Mid --> P2["P: Medium Heat<br/>(Kp × 2)"]
    Mid --> I2["I: Growing<br/>(Ki × ∫errors)"]
    Mid --> D2["D: Negative<br/>(Temp Rising)"]

    P2 & I2 & D2 --> Heat2["Reduced Heating"]
    Heat2 --> Final["After 15min:<br/>Room 22°C<br/>Error 0°C<br/>Stable"]

    style Start fill:#E67E22,stroke:#16A085,stroke-width:2px,color:#fff
    style Heat1 fill:#E74C3C,stroke:#2C3E50,stroke-width:2px,color:#fff
    style Heat2 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
    style Final fill:#2C3E50,stroke:#16A085,stroke-width:3px,color:#fff

Figure 232.5: Home heating: 18C to 22C using P, I, D components

PID Temperature Control Sequence: Initially large error (18-22C) produces full heating. As temperature rises, P term decreases (smaller error), D term provides braking (rapid approach), and system smoothly reaches setpoint without overshoot.

Scenario Analysis:

Table 232.2: Temperature Control Timeline
Time SP PV Error Action
0 min 22C 18C +4C Full heating
5 min 22C 20C +2C Reduce heating
10 min 22C 21.5C +0.5C Minimal heating
15 min 22C 22C 0C Heating OFF
20 min 22C 21.8C +0.2C Small heating pulse

Key Observations: - As error decreases, control action decreases - Zero error means no action needed (maintain state) - Small variations around set point are normal

232.4 Proportional Control (P)

Diagram of proportional-only control system showing error input multiplied by proportional gain Kp to produce control output directly proportional to current error magnitude, with large errors producing strong corrections and small errors producing weak corrections, demonstrating fast response but potential steady-state offset
Figure 232.6: Proportional control system diagram showing output proportional to current error magnitude - immediate response but may have steady-state error

The Proportional term provides control action directly proportional to the current error. Larger errors produce stronger corrections.

\[ u_p(t) = K_p \cdot e(t) \]

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'fontSize': '16px'}}}%%
graph LR
    Error["Error<br/>e t"] -->|Multiply by Kp| Gain["Proportional<br/>Gain<br/>Kp"]
    Gain -->|Output = Kp x e t| Output["Control<br/>Output<br/>u_p t"]

    Large["Large Error<br/>e = 5°C"] -.->|Kp=2<br/>Output=10| Strong["Strong<br/>Correction"]
    Small["Small Error<br/>e = 0.5°C"] -.->|Kp=2<br/>Output=1| Weak["Weak<br/>Correction"]

    style Error fill:#E67E22,stroke:#16A085,stroke-width:2px,color:#fff
    style Gain fill:#2C3E50,stroke:#16A085,stroke-width:3px,color:#fff
    style Output fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff

Figure 232.7: Proportional: output = Kp times error magnitude

Proportional Control Mechanism: Output directly proportional to error magnitude. Large errors produce strong corrections, small errors produce weak corrections. Simple but may leave steady-state offset.

Characteristics:

  • Fast response: Immediate reaction to errors
  • Simple implementation: Single multiplication
  • Proportional output: Big errors = big corrections; small errors = small corrections
TipAnalogy: Driving and Lane Changes

Imagine changing lanes on a highway (the “process”) by steering (the “control action”):

Set Point (SP): Center of target lane Process Variable (PV): Current car position Error: Distance from center of target lane

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'fontSize': '14px'}}}%%
flowchart LR
    subgraph Low ["Low Kp = 0.1 (Gentle)"]
        L1["Error: 2 feet"] -->|Steering: Kp × 2 = 0.2| L2["Gentle Turn"]
        L2 -.-> L3["Slow Approach<br/>May Never<br/>Reach Center"]
    end

    subgraph Med ["Moderate Kp = 0.5 (Balanced)"]
        M1["Error: 2 feet"] -->|Steering: Kp × 2 = 1.0| M2["Smooth Turn"]
        M2 -.-> M3["Good Balance<br/>Reaches Target"]
    end

    subgraph High ["High Kp = 2.0 (Aggressive)"]
        H1["Error: 2 feet"] -->|Steering: Kp × 2 = 4.0| H2["Aggressive Turn"]
        H2 -.-> H3["Fast But<br/>Overshoot +<br/>Oscillation"]
    end

    style L2 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
    style M2 fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style H2 fill:#E74C3C,stroke:#2C3E50,stroke-width:2px,color:#fff

Figure 232.8: Kp tuning: low (slow), moderate (balanced), high (overshoot)

Kp Tuning Impact on Lane Change: Low Kp produces slow, gentle response that may never reach target. Moderate Kp balances speed and stability. High Kp causes fast but unstable response with overshoot and oscillation.

Kp Selection Impact:

Table 232.3: Impact of Proportional Gain
Kp Value Steering Behavior System Response Issues
Small Kp (0.1) Gentle turns Slow lane change May never reach target
Moderate Kp (0.5) Smooth transitions Good balance Acceptable performance
Large Kp (2.0) Aggressive turns Fast lane change Overshoot, oscillation

Proportional Control Response:

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'fontSize': '14px'}}}%%
graph TB
    subgraph Timeline ["P-Only Control Response Over Time"]
        T0["t=0: Error Large<br/>Output High<br/>Fast Response"] --> T1["t=10s: Error Medium<br/>Output Medium<br/>Approaching Target"]
        T1 --> T2["t=20s: Error Small<br/>Output Weak<br/>Slowing Down"]
        T2 --> T3["t=30s: Steady State<br/>Small Error Remains<br/>Output Constant"]
        T3 -.->|"Never Reaches<br/>Exact Setpoint"| T3
    end

    Problem["Problem:<br/>Steady-State<br/>Error Persists"] -.-> T3

    style T0 fill:#E74C3C,stroke:#2C3E50,stroke-width:2px,color:#fff
    style T1 fill:#E67E22,stroke:#16A085,stroke-width:2px,color:#fff
    style T2 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
    style T3 fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style Problem fill:#E74C3C,stroke:#2C3E50,stroke-width:3px,color:#fff

Figure 232.9: P-only control: steady-state error persists at equilibrium

Proportional-Only Control Timeline: Fast initial response due to large error, but as error decreases, control action weakens. System settles with persistent steady-state error because small remaining error produces insufficient control output.

Problems with P-Only Control:

  1. Steady-State Error: System may never reach exact set point
  2. Overshoot: High Kp causes system to go past target
  3. Oscillation: High Kp can cause continuous cycling around set point
  4. Cannot handle disturbances: External forces cause permanent offset
WarningP-Only Control Limitation: Steady-State Error
Graph comparing three proportional-only control responses over time: low Kp shows slow gentle approach settling below setpoint with steady-state error, moderate Kp shows balanced response reaching near setpoint with small offset, high Kp shows fast aggressive response with large overshoot and sustained oscillation around setpoint
Figure 232.10: Graph comparing proportional control responses with different Kp values - higher Kp gives faster response but more oscillation

With proportional control alone, there’s often a permanent offset from the set point called steady-state error.

Why? - As error decreases, control action decreases - Eventually, control action becomes too weak to eliminate remaining error - System settles with small persistent error

Example: - Set point: 22C - Steady state: 21.7C - Error: 0.3C persists indefinitely - P-only control cannot eliminate this offset

Solution: Add Integral control to eliminate steady-state error

Question: A thermostat maintains 22C room temperature. Current temperature is 18C. With P-only control (Kp=5), what is the controller output?

Explanation: Proportional control formula: Output = Kp times error. Error = Setpoint - Measured = 22C - 18C = 4C. Output = 5 times 4 = 20 units (e.g., % heater power). Behavior: Large error leads to large correction. As temperature rises to 20C (error=2), output reduces to 10 units. At 21C (error=1), output=5 units. P-only limitation: Never reaches exactly 22C due to steady-state error - when output barely sustains temperature below setpoint. This is why PI or PID control is typically needed for precise temperature regulation.

232.5 Summary

In this chapter, we covered the fundamentals of PID control:

Key Takeaways:

  1. PID Components: The three terms (Proportional, Integral, Derivative) each address different aspects of control - current error, accumulated error, and rate of change

  2. Error Calculation: The foundation of PID is the error signal (e = SP - PV), representing the difference between desired and actual values

  3. Proportional Control: Provides immediate response proportional to error magnitude, but cannot eliminate steady-state error

  4. Kp Tuning: Low Kp gives slow response; high Kp gives fast response but risks overshoot and oscillation

  5. P-Only Limitations: Cannot eliminate steady-state error or handle constant disturbances - requires integral term

232.6 What’s Next?

In the next chapter, we’ll explore the Integral and Derivative terms in detail, learning how they address the limitations of proportional-only control.

Continue to Integral and Derivative Control