74  PID: Tuning and Applications

In 60 Seconds

PID tuning methods include Ziegler-Nichols (find the ultimate gain and oscillation period, then apply ratios), manual tuning (start with P-only, add I, then D), and auto-tune algorithms. Real-world IoT applications achieve settling times under 2 seconds for temperature control and under 50ms for motor position control.

74.1 Learning Objectives

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

  • Apply Tuning Methods: Execute Ziegler-Nichols and manual tuning procedures to optimize PID performance
  • Implement Domain-Specific Control: Design temperature, motor, and position control systems for specific IoT applications
  • Evaluate Real-World Systems: Assess industrial PID implementations using performance metrics and ROI analysis
  • Justify Configuration Selection: Defend the choice of P, PI, or PID based on sensor noise, process dynamics, and precision requirements
MVU: PID Tuning in Practice

Core Concept: Start tuning with P only (increase until oscillation), add I to eliminate steady-state error, then add D to reduce overshoot - not every application needs full PID; PI often suffices. Why It Matters: Poorly tuned PID causes oscillation, overshoot, or sluggish response; systematic tuning achieves optimal performance without trial-and-error waste. Key Takeaway: Start with Kp that produces slight oscillation, set Ki to eliminate offset in 2-5 settling times, add Kd only if overshoot causes actual problems - simpler is usually better in production IoT systems.

Process control in IoT is about automatically adjusting systems to maintain desired conditions. Think of cruise control in a car: it continuously measures your speed, compares it to your target, and adjusts the throttle to keep you on track. IoT systems use similar feedback loops to control everything from room temperature to industrial manufacturing processes.

74.2 Prerequisites

Before diving into this chapter, you should be familiar with:

Misconception 1: “Higher Kp always means better performance”

Reality: Increasing proportional gain Kp makes the system respond faster initially, but excessive Kp causes overshoot and oscillation. There’s an optimal Kp value - too low leaves steady-state error, too high creates instability.

Example: Thermostat with Kp=10 oscillates wildly between 18C and 26C. Reducing to Kp=2 provides smooth approach to 22C target.


Misconception 2: “Integral term is always necessary”

Reality: Integral control eliminates steady-state error but isn’t always needed. Simple applications with acceptable error tolerance (LED dimming, fan speed) work fine with P-only control. Adding I increases complexity and can cause integral windup problems.

When I is critical: Precision temperature control, motor position control, chemical process regulation.

When I is optional: Simple ON/OFF with hysteresis, non-critical comfort applications.


Misconception 3: “Derivative term makes the system faster”

Reality: Derivative actually slows down aggressive P and I responses to prevent overshoot. It doesn’t speed up the system - it adds damping and stability. D term is the “brake” that prevents overshooting the target.

Analogy: Car approaching stop sign. P says “brake proportional to distance.” I says “brake more if you’ve been too close for a while.” D says “if approaching fast, brake harder NOW to prevent passing the line.”


Misconception 4: “PID parameters can be randomly adjusted until system works”

Reality: PID tuning requires systematic methods. Random adjustment wastes time and can cause damage or instability. Use established methods: Ziegler-Nichols, Cohen-Coon, or software auto-tuning.

74.3 Systematic PID Tuning Approach

Systematic approach:

  1. Start with all gains at zero
  2. Increase Kp until stable oscillation (critical gain Ku)
  3. Add Ki to eliminate offset
  4. Add Kd to reduce overshoot
  5. Fine-tune iteratively

74.3.1 Interactive: Ziegler-Nichols Tuning Calculator

Enter your measured ultimate gain (Ku) and oscillation period (Tu) to get recommended starting gains.

Tradeoff: P-Only vs Full PID Control

Option A: P-Only Control - Simplest implementation using only proportional gain. Fast response but always has steady-state error (offset from setpoint).

Option B: Full PID Control - Three-term controller with proportional, integral, and derivative gains. Eliminates steady-state error and reduces overshoot but requires careful tuning.

Decision Factors:

  • Choose P-Only when: Application tolerates 2-10% steady-state offset (LED dimming, fan speed), system responds quickly with minimal inertia, tuning time must be minimized, or computational resources are extremely limited (8-bit microcontrollers with <2KB RAM).

  • Choose Full PID when: Zero steady-state error is required (precision temperature control within 0.1C), overshoot must be minimized (liquid level control to prevent overflow), system has significant thermal or mechanical inertia, or disturbances are frequent and unpredictable.

  • Tuning effort comparison: P-only requires adjusting 1 parameter (Kp) - typical tuning time 5-15 minutes. Full PID requires tuning 3 parameters (Kp, Ki, Kd) with interaction effects - typical tuning time 1-4 hours for manual methods, or 15-30 minutes with auto-tuning algorithms.

MVU: Choosing Your PID Configuration

Core Concept: You rarely need full PID - PI control handles 80% of real-world applications because most systems tolerate some overshoot but cannot tolerate persistent steady-state error. Why It Matters: Adding the D term introduces noise sensitivity and tuning complexity; only precision applications like motor positioning or temperature-critical processes justify the extra effort. Key Takeaway: Start with PI control (Kp for responsiveness, Ki for accuracy), add D only if overshoot causes actual problems - simpler is usually better in production IoT systems.

74.4 Real-World Example: Industrial Brewery Temperature Control

Industry Context: A craft brewery fermentation process requires precise temperature control during different fermentation stages. Temperature variations >+/-0.5C affect yeast metabolism, producing off-flavors that ruin entire 1,000-liter batches worth $8,000-$12,000 each.

System Architecture:

Component Specification Cost Purpose
Fermentation Tank 1,000L stainless steel, jacketed $15,000 Primary fermentation vessel
Temperature Probe PT100 RTD, +/-0.1C, 4-20mA $120 Measure wort temperature
Glycol Valve Modulating control valve, 0-100% $850 Regulate cooling flow
Heating Element 2kW immersion heater, PWM control $280 Provide heating when needed
ESP32 Controller Custom board + 16-bit ADC $45 Execute PID control loop
Cloud Platform AWS IoT Core + Lambda $30/month Monitoring and alerts

Fermentation Profile Requirements:

Line graph showing a three-stage brewery fermentation temperature profile: primary fermentation stage holds at 18C for several days with tight PID control, diacetyl rest stage steps up to 20C, and cold conditioning stage rapidly drops to 2C; each stage has distinct Kp Ki Kd tuning values shown
Figure 74.1: Beer fermentation temperature profile with three PID-controlled stages

PID Tuning for Different Stages:

Stage Setpoint Kp Ki Kd Rationale
Primary (18C) 18.0C 4.5 0.15 1.8 Tight control, moderate Kp (exothermic fermentation produces heat)
Diacetyl Rest (20C) 20.0C 3.0 0.1 1.2 Less aggressive (allows natural temp rise)
Conditioning (2C) 2.0C 6.0 0.25 2.5 High Kp for cold-crash, strong integral to overcome thermal mass

During Conditioning cold-crash (18°C → 2°C), with \(K_p=6, K_i=0.25, K_d=2.5\):

  • t=0: Error = \(2 - 18 = -16\)°C, \(P = 6 \times (-16) = -96\)%, \(I=0\), \(D=0\) → Cooling at 96%
  • t=60min: Temp = 10°C, error = \(-8\)°C, rate = \((-8-(-16))/60 = +0.13\)°C/min (warming trend)
    • \(P = -48\)%, \(I = 0.25 \times (-960) = -240\)% (clamped), \(D = 2.5 \times 0.13 = +0.33\)%
    • Total: \(-48 - 60 + 0.33 = -107.67\)% → Clamped at -100% (full cooling)
  • t=180min: Temp = 2.5°C, error = \(-0.5\)°C, rate = \(+0.01\)°C/min
    • \(P = -3\)%, \(I = -15\)%, \(D = +0.025\)% → Total = -17.975% (gentle cooling)

The derivative (+0.33% at t=60) reduces cooling slightly when temperature drops too fast, preventing undershoot below 2°C.

Performance Metrics (Before vs After PID Implementation):

Metric Before (Hysteresis Control) After (PID Control) Improvement
Temperature Stability +/-1.5C oscillation +/-0.15C deviation 90% improvement
Off-Flavor Batch Rejection 12% (5 batches/year) 1.2% (0.5 batches/year) 90% reduction
Annual Waste Cost $50,000 (5 x $10K/batch) $5,000 (0.5 x $10K) $45K saved
Energy Consumption 45 kWh/batch (frequent on/off) 32 kWh/batch (modulation) 29% reduction
Setpoint Transition Time 18C to 2C in 8 hours (overshoot to -1C) 18C to 2C in 6 hours (no overshoot) 25% faster, no overshoot
Glycol Valve Cycling 200 cycles/day (wear) 15 cycles/day (smooth modulation) 92% reduction, 5x valve lifespan

PID Control Response During Disturbance Event:

Scenario: During primary fermentation (Day 3), yeast activity peaks, generating 150W of metabolic heat. Ambient temperature also rises from 20C to 28C (summer heatwave).

Time-series plot of PID controller response to a combined disturbance event: yeast metabolic heat (150W) and ambient temperature rise from 20C to 28C cause a brief temperature spike above the 18C fermentation setpoint; the PID controller detects the error and increases glycol cooling to restore temperature to setpoint within minutes
Figure 74.2: PID response to combined fermentation heat and ambient temperature disturbance

Key Lessons:

  1. Adaptive PID Gains: Different fermentation stages require different tuning. High Kp during cold-crash (large temperature delta), moderate Kp during fermentation (smaller delta, exothermic reaction).

  2. Derivative is Critical: Without D term, system overshoots 2C setpoint down to -1C during cold-crash, stressing yeast. D term (Kd=2.5) provides predictive damping, smooth approach to 2.0C.

  3. Integral Eliminates Offset: Yeast metabolic heat creates constant +150W disturbance. P-only control settles at 18.4C (0.4C offset). Adding integral (Ki=0.15) accumulates error, increasing cooling until exact 18.0C achieved.

  4. Local Control Latency: ESP32 PID loop runs at 1 Hz (1-second intervals). Cloud-based control would have 3-10 second latency - during rapid fermentation, temperature could swing +/-0.8C before correction arrives. Local feedback is mandatory.

  5. ROI Analysis: $1,295 hardware investment. Payback in 11 days from avoiding just one bad batch ($10K). Additional savings from energy (29% reduction = $450/year) and valve longevity (5x lifespan = $170/year replacement cost savings).

74.5 PID Across Different IoT Domains

This variant shows how the same PID concepts apply differently across various IoT application domains.

Four-panel diagram showing PID control applied across different IoT domains: HVAC systems use slow PI tuning for room temperature, industrial motors use fast PID for precise speed control, agricultural irrigation uses medium PI for soil moisture management, and autonomous vehicles use high-frequency PID for stability
Figure 74.3: Different IoT domains require different PID tuning strategies based on sensor response time, actuator characteristics, and system priorities.

74.6 Practical Design Considerations

When designing IoT systems with PID control, consider:

Sensor Placement:

  • Feedback sensors must accurately measure the controlled variable
  • Minimize latency between actual change and sensor detection
  • Consider sensor accuracy requirements vs. cost

Communication Delays:

  • For distributed systems, network latency affects feedback loop performance
  • Long delays can cause instability
  • May need to implement local closed-loop with cloud monitoring

Failure Modes:

  • What happens if feedback sensor fails?
  • Should system fail-safe (shut down) or continue open-loop?
  • Redundant sensors for critical applications?

Power Constraints:

  • Closed-loop systems consume more power
  • May need to alternate between open and closed loop operation
  • Sleep modes between control actions

74.7 Knowledge Check

Key Concepts

  • Ziegler-Nichols Tuning: A closed-loop tuning method: increase Kp until sustained oscillation begins (Ku = ultimate gain, Tu = oscillation period), then set Kp=0.6Ku, Ki=1.2Ku/Tu, Kd=0.075Ku×Tu — provides aggressive starting point requiring refinement
  • Cohen-Coon Method: An open-loop tuning method using the process reaction curve (step response) to extract process gain (Kp), time constant (τ), and dead time (θ), then compute PID gains from tabulated formulas
  • Lambda Tuning: A model-based method specifying desired closed-loop time constant (λ) and computing PID gains to achieve it — conservative (large λ) for robust control of uncertain processes; aggressive (small λ) for fast setpoint tracking
  • Auto-Tuning: A controller feature that automatically identifies process dynamics (by injecting a relay or step test) and computes PID gains without manual parameter entry, supported by most industrial DCS and PLC systems
  • Gain Scheduling: A strategy using different PID gain sets at different operating points of a nonlinear process, with smooth interpolation between gain sets to maintain consistent performance across the operating range
  • ITAE (Integral of Time-weighted Absolute Error): A performance criterion that weights later errors more heavily than early errors, producing tuning that minimizes the time taken to settle after a disturbance — used to objectively compare alternative PID tuning methods
  • Quarter Decay Ratio: The traditional performance criterion where the second overshoot peak is one-quarter of the first — produced by aggressive Ziegler-Nichols tuning; more conservative tuning criteria (ITAE, ISE) are preferred in practice

Common Pitfalls

Applying Ziegler-Nichols gains directly to production systems. The method is designed to produce aggressive response near the stability limit (1/4 decay ratio), which is often too oscillatory for industrial processes where stability is preferred over speed. Use Z-N as a starting point only, then detune by reducing Ki by 30–50%.

Verifying PID performance only during normal operation without testing disturbance rejection. A well-tuned controller for setpoint tracking may have poor disturbance rejection. Always test with representative disturbances (load steps, pressure pulses, temperature changes) after tuning.

Tuning PID at one operating point (e.g., 50% load) and applying the same gains across the full range. Nonlinear processes have different gains at different points — a pH control loop with correct gains at pH 7 may be dangerously aggressive near pH 4 or pH 10 where the process sensitivity is 10× higher.

Changing PID gains without recording the reason, expected behavior, and operating conditions at time of tuning. When a control loop begins oscillating months later, undocumented gain changes make root cause analysis very difficult. Maintain a tuning log with date, gains, and justification.

74.9 Summary

This chapter covered practical PID tuning and real-world applications:

  • Systematic Tuning: Start with P-only, add I to eliminate offset, add D to reduce overshoot
  • Configuration Selection: PI handles 80% of applications; full PID for precision requirements
  • Real-World Example: Industrial brewery achieving 90% improvement in temperature stability with $45K annual savings
  • Domain-Specific Tuning: HVAC (low Kp, high Ki), motors (high Kp, high Kd), irrigation (medium Kp, high Ki)
  • Design Considerations: Sensor placement, communication delays, failure modes, power constraints

74.10 What’s Next

The next chapter explores Processes & Systems Fundamentals, covering the theoretical foundations of systems, processes, input-output transformations, and how IoT devices transform inputs into meaningful outputs through controlled operations.

Previous Current Next
PID Control Theory PID Tuning and Applications Processes & Systems

Foundation:

Architecture:

Sensing & Actuation:

Applications:

Learning Resources: