A Raspberry Pi Kiln Controller
Somewhere in the project constellation is a kiln controller. Not a metaphorical kiln — a real ceramics kiln with three independent heating zones, K-type thermocouples, relay-controlled elements, and a Raspberry Pi 4 running the control loop.
The original version is a Pascal/Lazarus desktop app. The migration target is a Node.js service with a web UI. The physics are the same either way.
How a kiln controller works
A ceramics firing follows a schedule: segments of ramp rates (degrees per hour), target temperatures (up to 2300F for high-fire), and hold times. A cone 6 glaze firing might be: ramp at 300F/hr to 250F, hold 30 minutes (to drive off moisture), ramp at 400F/hr to 2000F, then 150F/hr to 2232F (cone 6), hold 10 minutes, then controlled cooling.
The controller’s job is to make reality match the schedule. Every second, for each of three zones:
- Read the thermocouple temperature
- Calculate the target temperature from the schedule (interpolating along the ramp)
- Run a PID controller to compute a duty cycle (0.0 to 1.0)
- Fire the heating element for
duty * cycle_lengthseconds
The heating elements are controlled by relays — on or off, no dimming. The PID modulates the time each element is on within a 15-second cycle. Duty cycle 0.6 means the element is on for 9 seconds and off for 6.
The thermocouples
K-type thermocouples generate a voltage proportional to temperature — about 41 microvolts per degree Celsius. The MAX31855 chip reads this voltage via SPI and reports a digital temperature. But the reported value assumes a standard reference junction, and real-world accuracy requires correction.
The controller applies NIST polynomial correction coefficients to the raw reading. These are published polynomials that convert thermocouple voltage to temperature with sub-degree accuracy across the full range. The coefficients are different for different temperature ranges, so the correction function switches between polynomial sets based on the current reading.
There’s also cold-junction compensation — the MAX31855 reports the temperature at the chip itself (the “cold” junction) and the controller uses this to adjust the thermocouple reading. Without it, the ambient temperature of the electronics enclosure would introduce a systematic error.
The PID
PID (Proportional-Integral-Derivative) control is standard for kilns, but there’s a twist: three zones share one kiln cavity. Heat migrates between zones. If zone 1 is ahead of target and zone 3 is behind, zone 1’s PID wants to turn off while zone 3’s wants to go full power. But zone 3’s full power heats zone 1 through convection.
The controller implements “sister element balancing” — when one zone’s PID requests more than 100% duty (which the integral term can cause), it’s clamped, and the excess demand influences the other zones’ calculations. This prevents one ring from hogging power while another can’t contribute.
The thermal simulation
Development happens on a MacBook, not on a Raspberry Pi next to a kiln. The controller includes a thermal simulation mode: instead of reading real thermocouples, it models heat input (watt-seconds from element on-time), heat loss (polynomial regression from the kiln manufacturer’s HVAC data), and thermal mass (140 kg of firebrick and furniture at 545 J/kg*K).
The simulation is good enough to test schedule execution, PID tuning, and the web UI without any hardware. Setting PIKILN_SIMULATE=1 activates it.
The migration
The Pascal version uses Lazarus (Free Pascal) with LCL for the GUI and PascalIO for GPIO/SPI access. It works, but it’s tied to a desktop environment — you need a monitor and keyboard connected to the Pi.
The Node.js version serves a web UI. Control the kiln from your phone while you’re in the other room. Or from your laptop while you’re in another building. The Pi connects outbound to a VPS relay server (no NAT issues), and any browser can connect as a viewer.
The migration is five phases: library port (done), web UI (in progress), VPS relay integration, real hardware testing, and safety hardening. The safety module is new — a watchdog timer, over-temperature shutdown, and element timeout that didn’t exist in the Pascal version. When you’re controlling 240V heating elements from software, the safety layer isn’t optional.
Orton cone tracking
Ceramists measure kiln temperature not just in degrees but in “cones” — standardized ceramic test pieces that deform at specific combinations of temperature and time. Cone 6 isn’t a single temperature — it’s approximately 2232F at a heating rate of 150F/hr, but shifts higher or lower at different rates.
The controller calculates cone progress in real-time by interpolating across three rate tables published by the Orton Foundation. It tells you not just “the kiln is at 2200F” but “you’re at cone 5.8 and 12 minutes from cone 6 at the current rate.” This is genuinely useful information that most commercial controllers don’t provide.