PID Tuning Formula for 3D Printers
How PID control regulates hotend and bed temperature in 3D printers.
Covers Kp, Ki, Kd terms, autotune commands, and common temperature oscillation causes.
The PID Formula
u(t) is the heater output (0-255 in Marlin, 0-100% in Klipper). e(t) is the error: target temperature minus actual temperature. The three terms each handle a different aspect of temperature control.
The Three Terms
| Term | What it does | Too high | Too low |
|---|---|---|---|
| Kp (proportional) | Reacts to current error size | Oscillation, overshoot | Slow response, large steady-state error |
| Ki (integral) | Eliminates persistent offset | Windup, slow oscillation | Temperature settles below setpoint |
| Kd (derivative) | Brakes as temperature approaches target | Amplifies noise, jitter | Overshoot on heat-up |
Running Autotune
In Marlin: M303 E0 S220 C8 runs 8 autotune cycles for the hotend at 220C and reports Kp, Ki, Kd. Save with M301 and M500.
In Klipper: PID_CALIBRATE HEATER=extruder TARGET=220, then SAVE_CONFIG.
Run autotune with the printer in its typical operating state: enclosure closed if you use one, cooling fan at its normal speed, and the same ambient temperature you print in. PID constants calibrated at 20C room temperature will oscillate in a 40C enclosure.
Typical Values
| Component | Kp | Ki | Kd |
|---|---|---|---|
| Standard 40W hotend (V6, Dragon) | 20–30 | 1.5–3.0 | 60–120 |
| High-power hotend (50W+) | 15–25 | 1.0–2.5 | 50–100 |
| 120W heated bed | 50–80 | 5–10 | 200–600 |
Key Notes
- Temperature oscillation at print speed: if temperature drops when printing starts (cooling fan turning on), the PID was tuned with the fan off. Re-run autotune with
M303 E0 S220 C8 U1(U1 applies values immediately) with the fan at print speed. - Thermal runaway protection triggers when the hotend fails to reach or maintain target temperature within a time window. Proper PID tuning prevents false thermal runaway trips caused by oscillation.
- Ki windup occurs when the heater is asked to hold a temperature it physically cannot reach, such as 300C on a 30W heater. The integral term accumulates error indefinitely, then overshoots severely when the target is lowered. Anti-windup clamps the integral term.
- Bed PID is sometimes replaced with bangbang control in firmware for beds with slow thermal response and high thermal mass. Bangbang simply turns the heater fully on below setpoint and fully off above it. It works but allows temperature swings of 2-5C, which is noticeable in first layer consistency.