Control: closing the loop
420-302-VA · WEEK 10 · FALL 2026

Stage 2 of 6 · Theory · about 30 minutes

The loop

Before any term or gain, the structure: what feedback is, what every signal in a control loop is called, what the simplest possible controller already achieves, and the four numbers engineers use to grade any loop's behaviour. Everything on this page is pure control theory, and all of it is visible on your bench within the hour.

Open loop, closed loop

An open-loop system acts on a plan and never checks the result: Week 8's dimmer set a duty and trusted physics. It works exactly when the world cooperates, same LED, same room, same everything, and fails silently the moment anything drifts. A closed-loop system measures the result, compares it to the goal, and corrects, then does it again, forever. The loop needs no model of why reality disagrees; it only needs to see that it disagrees, and which way.

Open loop: a command goes into the plant and the result is whatever it is, with disturbances unanswered. Closed loop: the result is measured and fed back, the command is corrected, and disturbances are absorbed. Open loop: plan and hope fixedcommand plantLED + room result: whatever disturbance, unanswered Closed loop: measure and correct comparee = SP−PV controllerdecides u plantLED + room measured PV, fed back every cycle disturbance, absorbed
The feedback path is the entire difference. Same plant, same hardware; the green return wire is what turns "set it and hope" into "hold it regardless". Cruise control, thermostats, drone hover, your eye's pupil: all the bottom diagram.

The block diagram, mapped to your bench

Control engineering has a fixed vocabulary for the loop's signals, worth learning exactly because every datasheet, PLC manual and textbook uses it:

The standard closed-loop block diagram. The setpoint and the measured process variable meet at a comparison junction producing the error. The controller turns error into the control output u. The actuator, the PWM LED, drives the plant, the light field over the LDR, which disturbances also push on. The sensor, the LDR divider and ADC, measures the process variable and feeds it back. SP target, 50 % Σ + − controller your PID class actuator PWM → LED plant light over LDR sensor divider → ADC → read_pct() e u disturbance: shadows, flashlights, the sun PV
One diagram, two readings. As theory: SP and PV meet at the junction, e = SP − PV drives the controller, u drives the plant, the sensor closes the ring. As your bench: the junction and controller are Python, the actuator is set_brightness(), the plant is photons crossing an air gap, the sensor is Week 8's divider and calibration. Disturbances enter the plant uninvited, which is exactly where feedback catches them.

Two habits this diagram should install. First, PV is sacred: the controller only ever knows what the sensor reports, so Week 8's calibration quality is now control quality. Second, the sign convention matters: with e = SP − PV, too dark means positive error means push harder, and one swapped sign anywhere in the ring turns regulation into runaway, the troubleshoot page's layer B exists for it.

On/off control: the honest baseline

Week 8's night-light ladder already built a real controller: on/off (bang-bang) control with hysteresis, full power below one threshold, zero above another. It deserves respect, your kettle, fridge, iron and most thermostats use it, and it has a signature every automation tech learns to recognize:

Bang-bang control with a 45 to 55 hysteresis band. The light level rises past the upper threshold, the output cuts to zero, the level falls past the lower threshold, full power returns, forever. Below, the duty trace switches between full and zero. The oscillation overshoots the band slightly on each side because of the loop's delay.0204060800123456secondslight level (%)off above 55SP = 50on below 45duty: full / zerothe orbit never ends
On/off control holds an orbit, not a value. The level cycles between the thresholds at full-or-nothing duty (gray trace), and the loop's delay carries each swing slightly past its threshold before the switch bites. Amplitude comes from the band plus that delay; the period from the plant's speed. Nothing here is broken; this is the method's best.

The oscillation is not a tuning mistake; it is the method. With only two output levels, the loop can never rest at the setpoint, so it orbits it forever, at an amplitude set by the hysteresis band and a period set by the plant's speed. For a kettle, fine. For anything needing precision, smooth actuation, or mercy on a relay that would otherwise chatter itself to death, you need an output that can take intermediate values sized to the error, which is the whole idea of proportional control and the door into the next page.

Grading a response

Engineers grade a loop by its step response: change the setpoint abruptly and read the curve that follows. Four numbers summarize it, and the lab's tuning log asks for each:

An annotated step response. The setpoint steps from 20 to 60 percent; the curve rises, overshoots to a marked peak, and settles inside a shaded plus or minus five percent band around the setpoint. Markers show the ten to ninety percent rise time, the overshoot peak, the settling instant, and the near zero steady-state error.02550751000123456secondslight level (%)SP = 60rise time (10→90 %)overshoot: peak 70 %settled: stays in the ±5 % bandess ≈ 0
Four numbers grade any loop. A setpoint step from 20 % to 60 %: the 10→90 % rise time measures speed, the peak measures overshoot, the last exit from the shaded ±5 % band sets the settling time, and the resting gap is the steady-state error (here ≈ 0, the integral term at work). The lab's tuning log asks for exactly these four, read off your own CSV curves.
MetricDefinitionWhat it tells you
Rise timeTime from 10 % to 90 % of the stepRaw speed; mostly bought with proportional gain
OvershootPeak beyond SP, as a percent of the stepAggressiveness; the price of speed, tamed by damping
Settling timeTime until PV stays inside a band around SP (we use ±5 %)When the loop is done, which matters more than when it first arrives
Steady-state errorThe gap that remains after settlingAccuracy at rest; the integral term's entire portfolio

The step test grades how the loop chases a new goal; the equally important twin is disturbance rejection, hold the setpoint steady and hit the plant (flashlight on the LDR), then read the same metrics off the recovery. A loop can be good at one and mediocre at the other; the lab tests both.

The warning: feedback can bite

Feedback's power has one standing danger: pushed too hard, a stable loop becomes an oscillator. The mechanism is delay. Your loop's corrections act on slightly old information, the sensor averages, the loop ticks at a fixed period, Week 9's network adds transit, and a correction based on stale news can land after the problem has already reversed, now pushing the wrong way, harder each cycle if the gain is high. Every curve on the next page with ringing in it is this mechanism, and the entire craft of tuning is taking the loop close to that edge, for speed, without crossing it. Hold the one-line summary: gain buys speed; delay sells stability; tuning is the exchange rate.

Checklist for this stage

Check yourself

Week 8's light follower set duty from the reading with no comparison to a target. Open or closed loop?
Open, despite using a sensor: it mapped input to output with no setpoint, no error, no correction toward a goal. Feedback means the result is compared to a target and the gap drives the action; the follower had reaction, not regulation.
PV reads 38 %, SP is 50 %. Give e, its sign's meaning, and the direction u should move.
e = 50 − 38 = +12 %. Positive means reality is below target, too dark, so the controller should raise u, more LED duty. If your loop lowers u on positive error, a sign is flipped somewhere in the ring.
Why does widening a bang-bang controller's hysteresis band slow the relay chatter but worsen regulation?
The band sets the orbit: switching happens only at its edges, so a wider band means fewer switches per minute (kinder to the relay and the LED) but a larger amplitude of oscillation around SP, worse holding. Band width trades actuator wear against precision; no width makes the orbit disappear.
Two tunings both reach SP in 0.4 s. One overshoots to 68 % on a 20→60 step and rings twice; the other touches 61 % and stops. Which settles first, and which metric separates them?
The second: settling time. Rise time is identical; the first loop keeps leaving the ±5 % band with each ring, so it is not "done" until the ringing dies. Settling time, not arrival, is usually what the application feels.
Where, concretely, does delay enter your bench's loop? Name three sources.
The 16-sample read average (Week 8) smears the measurement over time; the fixed loop period means corrections land only on ticks; and in the distributed version, MQTT transit adds network latency both ways. Each one is small; together they set how much gain the loop tolerates before ringing.