Article
Control Theory · Thermodynamics · ⏱ ~11 min read · Last updated: 9 July 2026

Regulating a Heat Engine — PID Control Meets Thermodynamics

A thermostat holding a boiler at a set temperature, a turbine governor keeping a generator's speed locked to grid frequency, an engine control unit trimming fuel to hold air-fuel ratio — every one of these is a feedback loop wrapped around a thermodynamic process. Getting the loop right requires two separate disciplines to meet: the thermodynamic model of how the engine actually behaves, and PID (Proportional-Integral-Derivative) control theory for turning a measured error into a corrective action.

TL;DR: A heat engine's temperature or speed is set by thermodynamics (heat in, heat lost, thermal mass), while a PID controller turns the error between setpoint and measured value into a corrective action. Tuning methods like Ziegler-Nichols balance fast response against overshoot, and tighter control keeps the engine running closer to its peak thermodynamic efficiency.

1. The Thermal Engine as a Plant

In control-engineering terms, the heat engine (boiler, combustion chamber, Stirling hot-side, or turbine) is the "plant": a physical system with an input (fuel/heat rate) and an output (temperature, pressure, or shaft speed) linked by thermodynamics rather than simple algebra:

First law (lumped thermal mass model): C · dT/dt = Q_in(u) − Q_loss(T) where C = thermal capacitance [J/K], u = controller output (e.g. fuel valve position), Q_loss = h·A·(T − T_ambient) (Newton's law of cooling) This is a first-order lag plant: step response approaches steady state with time constant τ = C / (h·A) Real engines add: combustion delay (dead time), nonlinear Q_in(u) (valve/injector characteristics), and multi-mass thermal paths (higher-order lag)

2. PID Control Basics

A PID controller drives the plant input from the error e(t) = setpoint − measured value using three terms:

u(t) = Kp·e(t) + Ki·∫e(τ)dτ + Kd·de/dt Proportional (Kp): reacts to current error — too small is sluggish, too large overshoots/oscillates Integral (Ki): eliminates steady-state offset by accumulating past error — necessary because a pure P controller settles below setpoint (needs u > 0 to balance heat loss even at e = 0) Derivative (Kd): reacts to the RATE of change of error, damping overshoot — but amplifies sensor noise, so often filtered or applied to measurement instead of error

3. Closing the Loop on Temperature

Combining the plant and controller equations gives the closed-loop dynamics:

C·dT/dt = Q_in(u(T)) − h·A·(T − T_amb) u(t) = Kp·(T_set − T) + Ki·∫(T_set − T)dτ + Kd·d(T_set−T)/dt Substituting yields a 2nd/3rd-order ODE in T whose stability depends on Kp, Ki, Kd relative to plant parameters C, h·A, and any actuator/sensor delay τ_d. Rule of thumb: increasing Kp too far relative to τ_d causes oscillation; adding Ki without enough Kp/Kd causes slow "integral windup" oscillation, especially if the actuator saturates (e.g. valve fully open) during startup.

4. Tuning: Ziegler-Nichols and Beyond

Classic tuning finds gains empirically from the plant's own response, without needing a full analytical model:

Ziegler-Nichols closed-loop method: 1. Set Ki = Kd = 0, raise Kp until output oscillates steadily → this is the ultimate gain Ku, with oscillation period Tu 2. Classic PID: Kp = 0.6·Ku, Ki = 2·Kp/Tu, Kd = Kp·Tu/8 Open-loop (reaction curve) method: fit plant step response to a first-order-plus-dead-time model, then use published Kp/Ki/Kd formulas based on the time constant and dead time Modern practice: auto-tuning relay feedback, then manual refinement to reduce overshoot for thermally sensitive processes (overshoot can mean scorching, thermal stress, or runaway combustion in real engines)

5. Efficiency Under Regulation

Controlling temperature is not the only goal — the engine's thermodynamic efficiency depends on how tightly it is held near its design operating point:

Carnot limit: η_max = 1 − T_cold / T_hot Real cycle efficiency η_real < η_max, and typically peaks at a specific T_hot — running below it wastes potential work, running above it risks material limits and increased losses. Regulation trade-off: tight temperature control (low overshoot, fast settling) keeps the engine near peak efficiency continuously, while sloppy control causes efficiency to oscillate and average lower even if the setpoint is "correct" on average.

6. JavaScript PID + Thermal Plant Simulator

// First-order thermal plant + discrete PID controller
class PID {
  constructor(Kp, Ki, Kd, dt) {
    Object.assign(this, { Kp, Ki, Kd, dt, integral: 0, prevError: 0 });
  }
  step(setpoint, measured) {
    const error = setpoint - measured;
    this.integral += error * this.dt;
    const derivative = (error - this.prevError) / this.dt;
    this.prevError = error;
    const u = this.Kp*error + this.Ki*this.integral + this.Kd*derivative;
    return Math.max(0, Math.min(1, u)); // clamp to valve range [0,1] (anti-windup via clamping)
  }
}

function simulateEngine({ C, hA, Tamb, QmaxIn, Tset, Kp, Ki, Kd, dt = 0.5, steps = 1200 }) {
  const pid = new PID(Kp, Ki, Kd, dt);
  let T = Tamb;
  const log = [];
  for (let i = 0; i < steps; i++) {
    const u = pid.step(Tset, T);           // controller output in [0,1]
    const Qin = u * QmaxIn;                // heat input [W]
    const Qloss = hA * (T - Tamb);       // Newton cooling [W]
    const dT = (Qin - Qloss) / C * dt;
    T += dT;
    log.push({ t: i*dt, T, u });
  }
  return log;
}

// Boiler: Tset 90°C, ambient 20°C, tuned via Ziegler-Nichols
const trace = simulateEngine({
  C: 50000, hA: 120, Tamb: 20, QmaxIn: 15000, Tset: 90,
  Kp: 180, Ki: 6, Kd: 40
});
console.log(`Final temperature: ${trace[trace.length-1].T.toFixed(1)} °C`);

7. Real-World Applications

Steam Boiler Control

Industrial boilers use cascaded PID loops: an outer loop regulates steam pressure/temperature, an inner faster loop regulates fuel valve or burner firing rate.

Turbine Governors

Steam and gas turbine governors use PID (often with droop feedback) to hold rotational speed against variable electrical load, keeping grid frequency stable.

Automotive Engine Control

Modern ECUs use PID-family loops (often augmented with feedforward maps) to regulate idle speed, boost pressure, and exhaust-gas recirculation against a thermodynamic combustion model.

3D Printer Hotends

A familiar small-scale example: PID (or bang-bang with hysteresis) firmware holds nozzle temperature against ambient cooling and filament heat absorption.

8. Limitations and Advanced Control

Classic PID assumes a roughly linear, time-invariant plant near the operating point. Real thermal engines break this in several ways: