Skip to content

PID tuning

Alejandro Mora edited this page May 15, 2026 · 1 revision

PID tuning can be quite complicated. We have a few PID factors to consider and our expectations of the process. First you should know a bit about PID algorithm - there is plenty of papers and YT videos on the topic. You could also read the short documentation from the PID library author.

Then you can prepare a quick test environment, as described here and start experimenting. That is just an approximation of your target environment so don't expect to find perfect values there and move them directly to production.

Auto PID tuning

ESP32Kiln includes an automatic PID tuning feature based on the Ziegler-Nichols relay oscillation method. This is a good starting point to get initial PID values before manual fine-tuning.

How it works:

  1. The tuner heats the kiln to a target temperature (~300°C) and oscillates the heater on/off to induce a sustained oscillation in temperature.
  2. It measures the oscillation period and amplitude to calculate initial Kp, Ki, Kd values.
  3. On completion, the calculated values are automatically saved to preferences.

How to start auto-tune:

  • From the LCD: navigate to the Calibrate option in the menu.
  • The tuner uses the PID_Algorithm preference setting (default 5 = P_PoM) to determine which PID variant to tune.

What to expect:

  • The kiln will heat to ~300°C and cycle up and down repeatedly for several minutes.
  • Do not abort unless necessary - the tuner needs multiple oscillation cycles to get good results.
  • After completion, review the Kp/Ki/Kd values in Preferences. For kilns, Kd is often capped to prevent the derivative term from overpowering the response.

After auto-tune: Run a test program and observe the temperature trace. The auto-tuned values are a starting point - manual adjustment is usually still needed for your specific kiln.


Factors to consider

I would recognize three types of variables here:

Physical

These depend on your environment and physical components: how big your kiln is and how long heat distributes inside. This will delay the PID response, making it prone to temperature overshoot. The closer the thermocouple is to the heating element, the faster the response - but then you cannot control the temperature of the entire kiln chamber and need longer dwell times.

Also consider whether your heating element produces heat proportional to time (almost never exactly true).

Keep in mind that we usually only control heating - not cooling. If you need a cooling step in your program, make it long enough to allow natural cooling of your kiln chamber, otherwise the next heating step may stall.

Since by default the controller advances on time (not on reaching temperature), use PID_Temp_Threshold if you need the controller to wait until a target temperature is actually reached before advancing.

Your demands

You probably know how your heating should look: whether you want to reach the target temperature as fast as possible (and accept some overshoot), or never exceed it. Large temperature overshoot may ruin your work.

PID behaviour

In PID algorithm we have three values: Kp, Ki, Kd. We can also switch between Proportional on Measurement (PoM) or Proportional on Error (PoE) via PID_POE. There is also a built-in PID_WINDOW_DIVIDER define in ESP32Kiln.h that inflates PID responsiveness.

  • Kp - proportional part. Multiplies the current error (SV-PV). No memory of the past - it only reacts to current error and cannot stabilize temperature on its own. Too small and it may never reach target.
  • Ki - integral part. Accumulates past error. Controls how fast target is reached and how much overshoot occurs.
  • Kd - derivative part. Dampens fluctuations and measurement noise, enabling faster stabilization. For slow thermal processes, large Kd values can stall heating.

Examples

Here are a few examples with comments.

Test naming convention: PoM or PoE _ divider _ Kp,Ki,Kd

Slow but precise

An example where we don't want to exceed the target temperature. PID cannot follow the program closely, but extending expected program time produces good results. Kp=20 Ki=0.2 Kd=0.1, divider=10. Slow, but true

Too slow

Same parameters (20, 0.2, 0.1) without the divider. PID is too slow to reach the target temperature before the program moves on. Too slow

All tests together

All tests in one place

Clone this wiki locally