IdleLoop Notes

← journal

Espresso adventures, part 2: teaching a kettle some PID

Part one ended with an exploded thermometer and a kettle that boiled its own heating element. This time: doing it properly. The goal is boring on purpose — hold water at 93 °C ±0.5 while the pump runs.

The trick, as usual, is not the algorithm but the sensor placement. My first probe sat next to the heating element and reported the element's mood swings instead of the water's temperature. Moving it to the return line made the whole thing behave.

// PID loop, 4 Hz, on an MCU that has no business doing this
float update(float set, float meas) {
  integral += (meas - set) * dt;
  integral = constrain(integral, -30, 30);   // anti-windup: saves the weekend
  return kp*(set-meas) + ki*integral + kd*deriv(meas);
}

Numbers that worked: Kp = 18, Ki = 0.6, Kd = 40, but only after adding a 2-second moving average on the measurement. The raw signal has 1 °C noise from mains hum in the amplifier wiring — a software filter is cheaper than shielding.

Next adventure: flow profiling. Right now the pump runs at full blast, which makes every second cup worse than the first. Suspicious, fixable, and a good excuse to buy a flow sensor I definitely don't need.