Skip to content

Control Systems

Bang-bang (on-off) control vs PID

Bang-bang control, or on-off control, switches its output fully on or fully off: on below the target, off above it. It's how most thermostats, fridges and kettles work. It's simple and robust, but it never holds the target exactly: it swings around it. With one threshold it chatters; with a hysteresis band it switches calmly but swings wider than the band. When you need a fraction of a degree, use PID on a variable output.

One threshold chatters

Hold a 3D printer bed at 60 °C with a relay: on below 60, off above. The thermometer's reading jitters by a few tenths of a degree, so near 60 every jitter flips the decision. Over 20 minutes the relay clicks hundreds of times, wearing out its contacts, and the noise is doing the switching.

A band calms it

Switch on below 59 °C and off above 61 °C, and do nothing in between. Now jitter can't cross the gap and the relay clicks a few dozen times instead. But the bed still swings about 4 °C either way, from about 56.5 to 64.3 °C, not 1.

The reason is lag. The thermometer warms up about 15 s behind the bed. By the time it reads 61, the bed is already hotter, and heat already in the element keeps soaking in. Coming down, the same delay makes it fall below 59 before the heater comes back on. A bang-bang loop always swings by the band plus whatever the lag adds.

Live experiment

Chatter, a band, or proportional power

A printer bed held at 60 °C for 20 minutes, with a thermometer that jitters and reads 15 s late. One threshold clicks the relay 406 times; a 59 to 61 °C band clicks 37 times but swings from 56.5 to 64.3 °C; PI on proportional power holds within 0.2 °C.

Try it yourself: free lesson

“Hold the heat” is lesson 1 of 6 in Balance Bluffs, Control Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 14 before it first.

Proportional power holds it

Instead of all or nothing, give the heater a power between 0 and 1, by PWM on a solid-state relay that can switch quickly without wearing out. A PI controller sets that power:

power = 0.4 + Kp × error + Ki × integral

The 0.4 is feedforward, the power that holds 60 °C in a still room. The P term reacts to changes, and the integral finds any extra power needed, like when a window opens and the room cools. The bed stays within about 0.2 °C.

Choosing

Bang-bang with a bandPID on proportional power
Outputon or offany level
Accuracyband plus laga fraction of a degree
Partsa relayPWM and a solid-state relay
Tuningpick the bandthree gains

Bang-bang is also the right choice when the actuator really is two-state: a solenoid valve, a compressor or a pump.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Hold the heat” is lesson 1 of 6 in Balance Bluffs, Control Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 14 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3With hysteresis the heater switches on below 59 °C and off above 61 °C. The bed is cooling and reads 60.3 °C. The heater is…
    Show the answer

    Answer: Off: it stays as it was until the reading drops below 59. Inside the band nothing changes. It turned off above 61 and stays off until the bed cools past 59.

    • Why not “Switching”? Inside the band nothing switches, which is what stops the chatter.
    • Why not “Half on”? A relay is either on or off; there's no half setting.
    • Why not “On”? The heater turned off when the bed passed 61 °C, and it only turns on again below 59. At 60.3 °C neither rule fires.
  2. Question 2 of 3The band is ±1 °C, but the bed swings about ±4 °C. Why?
    Show the answer

    Answer: The thermometer reports late, so the heater switches after the bed has passed each edge. The thermometer warms up about 15 s behind the bed. By the time it reads 61, the bed is already hotter, and the heater keeps going until the reading catches up. Lag, from Lag Lagoon, again.

    • Why not “The band is too narrow”? A narrower band would swing less, not more. The extra swing comes from acting on old readings.
    • Why not “The relay is slow”? A relay switches in milliseconds. The delay that matters is the thermometer's 15 s.
    • Why not “The bed is too big”? The bed's size doesn't widen the swing here; the late thermometer does.
  3. Question 3 of 3Which job suits a relay with hysteresis better than PI on proportional power?
    Show the answer

    Answer: A fridge: a couple of degrees either way is fine. A fridge is happy anywhere from 3 to 5 °C, and its compressor hates being switched on and off quickly. A printer bed, a sous-vide bath and an incubator need a fraction of a degree.

    • Why not “A 3D printer bed”? A 3D printer bed needs a steady temperature for the first layer to stick, within a fraction of a degree.
    • Why not “A sous-vide cooker”? Sous-vide cooking depends on holding the water within a fraction of a degree for hours.
    • Why not “An egg incubator”? Eggs need a very steady temperature to hatch, so an incubator needs fine control.
Keep practising: free lesson

“Hold the heat” is lesson 1 of 6 in Balance Bluffs, Control Systems World 3. Free with an account. Lessons unlock in order, so you’ll do the 14 before it first.

Questions people ask

What is bang-bang control?

A controller whose output has only two states, fully on or fully off, chosen by whether the measurement is below or above the target. A home thermostat switching a boiler is the classic example. It's also called on-off control.

Why does a bang-bang controller overshoot its band?

Because of lag. The heater keeps heating until the sensor reads past the top of the band, but by then the heated thing is already hotter, and it keeps warming while the heat soaks through. The longer the lag, the wider the swing.

When is PID better than bang-bang control?

When you need the temperature or speed held within a fraction of a degree or percent, and the output can be varied smoothly, by PWM or a solid-state relay. For a fridge or a room, where a degree or two either way is fine, on-off with hysteresis is simpler and enough.

Every topic