PID tuning a 3D printer: stop hotend and bed temperature swings
By Sina Esfahani, OmniTechs · Published 30 November 2026
Your printer holds its temperature with a PID controller: it measures how far the reading is from the target and sets the heater power to match. Its three numbers (Kp, Ki and Kd) must fit your heater, block and fan. When they do not, the temperature overshoots after heating, or swings up and down and never settles.
The fix is an autotune: the printer heats and cools a few times, measures how your heater behaves and calculates new values. Run it at your print temperature, with the silicone sock fitted and the part-cooling fan at your usual speed, then save the result. A swing of more than about 5 °C either way, or sudden jumps, is usually a fan, thermistor or wiring fault rather than a tuning problem (Prusa).
Fix it in this order:
Heat to your print temperature and watch the graph for two minutes: a good tune holds within about 1 to 2 °C (Marlin).
Sudden jumps, or swings beyond 5 °C either way: check the hardware first, with the printer switched off and unplugged.
Fit the silicone sock if your hotend has one and aim the fan duct at the nozzle tip, not the block.
Set the part-cooling fan to the speed you print at most, for example M106 S128 for 50%.
Tune the hotend at your print temperature and stay with the printer: Marlin M303 E0 S210 C8 U1 then M500; Klipper PID_CALIBRATE HEATER=extruder TARGET=210 then SAVE_CONFIG.
Tune the bed only if its heater may be switched fast (a MOSFET or suitable SSR, never a mechanical relay): M303 E-1 S60 C8 U1 then M500, or PID_CALIBRATE HEATER=heater_bed TARGET=60 then SAVE_CONFIG.
Check again: steady within 1 to 2 °C, and a dip when the fan starts that recovers within about half a minute.
Read the temperature graph first
Temperature behaviour, what it means and what to do
| What you see | What it means | What to do |
|---|---|---|
| A few degrees past the target, one or two swings, then steady | Normal for a tuned heater | Nothing |
| A slow, regular swing of several degrees that never settles | The PID values do not fit this heater | Run an autotune and save it |
| A drop of several degrees when the fan starts, a few layers in | The fan cools the heater block | Fit the sock, aim the duct, tune with the fan on |
| Sudden spikes or drops, often when the head moves | Loose thermistor, connector or damaged wire | Switch off and unplug, then check the wiring |
| Keeps rising past the target | Heater on when it should be off, or the sensor misreads | Switch off now; see the thermal runaway guide |
| Bed wobbles a degree or two every few seconds | Bang-bang bed control, the Marlin default | Usually fine; consider bed PID |
Why the temperature overshoots or swings
The heater cartridge, block and sensor lag behind each other, so simple on-off control overshoots, undershoots and overshoots again. PID sets a power between off and full, based on how far off the reading is, for how long, and how fast it is changing (Marlin). Marlin uses PID only within 20 °C of the target; below that the heater runs flat out, so the tune shapes the last 20 °C and the hold.
The stock values were measured on someone else's machine, and Klipper warns that values from other firmware or example configurations often work poorly. Tune again after anything that changes how fast the block gains or loses heat: a new hotend, cartridge, thermistor or block, a new fan duct, adding or removing a sock, or moving the printer into an enclosure (Marlin).
Run the autotune under printing conditions
The result describes the heater and everything that cools it, so tune as you print:
Fan. Neither Marlin's M303 nor Klipper's PID_CALIBRATE touches the part-cooling fan; it keeps the speed you set. An accepted answer on the 3D Printing Stack Exchange advises tuning at the fan speed you use most: values tuned at full fan are too aggressive with the fan off, and values tuned without fan struggle when it runs.
Sock and duct fitted. Marlin warns against tuning a bare block on the bench.
Temperature: the one you use most, for example 210 °C for PLA. Values get less accurate the further you print from it (Marlin, Prusa).
Position: nozzle a few centimetres above the bed; when you tune the bed, leave the hotend cold (Marlin).
Room: stable, above 20 °C, no draught (Prusa).
Stay with the printer for the whole test: the autotune deliberately drives the temperature above and below the target several times. Thermal protection stays active, but it does not replace you. If the printer halts with Heating failed or THERMAL RUNAWAY during an autotune, Marlin says the cause is wiring or power, not tuning: go to the hardware section below.
Marlin: M303, then save with M500
Send these from a host program with a terminal, such as Pronterface or OctoPrint:
M106 S128 sets the part-cooling fan to 50% (S runs from 0 to 255). Use your usual speed, or M107 for off.
M303 E0 S210 C8 U1 tunes hotend 0 at 210 °C for 8 cycles and applies the result.
M500 saves it. U1 only changes working memory; without M500 the values are gone at the next reset.
E picks the heater: E0 the first hotend (default), E1 the second, E-1 the bed, E-2 the chamber. S is the target; without it Marlin uses the Preheat 1 temperature. C is the number of cycles: at least 3, default 5, and Marlin calls 8 a good choice. U1 applies the result; without it the values are only printed. With EMERGENCY_PARSER enabled, M108 stops a running autotune.
M500 needs EEPROM_SETTINGS in the firmware. Without it, M500 only replies EEPROM disabled, and you copy the values into Configuration.h and rebuild.
Worked example. Marlin's documentation shows an autotune ending with Kp 15.58, Ki 0.99 and Kd 61.19. Run without U1, you enter them yourself with M301 P15.58 I0.99 D61.19, then M500; for the bed the command is M304. M503 shows the stored values. A Kd several times larger than Kp is normal: Marlin's stock hotend values are 22.20, 1.08 and 114.00.
With PID_AUTOTUNE_MENU enabled, the LCD offers Configuration > Advanced Settings > Temperature > Autotune E1 PID. It applies the result but does not save it: choose Configuration > Store Settings afterwards.
In this older video Thomas Sanladerer shows Marlin's PID autotune; menus have changed since, so use the commands above.
Klipper: PID_CALIBRATE, then SAVE_CONFIG
Set the fan with M106 as above.
Send PID_CALIBRATE HEATER=extruder TARGET=210. Klipper's own example uses 170; use your print temperature.
When Klipper prints the new pid_Kp, pid_Ki and pid_Kd, send SAVE_CONFIG. It writes them into printer.cfg and restarts Klipper.
There is no cycle count; the test runs until it has enough peaks. For the bed, use HEATER=heater_bed.
Two Klipper details matter if the temperature still oscillates. On 18 October 2026 Klipper corrected an error that made PID_CALIBRATE recommend values twice as high as intended: if your heater is stable, change nothing; if it keeps oscillating, update Klipper and calibrate again. And on the Klipper forum, a user with a 50 W heater traced a steady oscillation to smooth_time, the period over which Klipper averages readings. Its default became 1 second in 2021, but older printer.cfg files may still set 2.
Prusa, Creality, Elegoo and Bambu Lab printers
Built-in PID routines on maker firmware
| Printer | Where | What to know |
|---|---|---|
| Original Prusa i3 (MK3 family) | LCD Menu > Calibration > PID calibration | Pick your most-used temperature; 5 cycles; with the MK3S thermal model, run Calibration > Temp Model cal. afterwards |
| Prusa MINI, MK4, XL | No menu | A Prusa staff reply says the stock values suit the stock heaters; M303, M301 and M304 exist |
| Creality SPARKX i7 | Settings > Print Settings (page 2) > Expert Mode > Nozzle PID Calibration | Set the filament's print temperature; about 5 minutes |
| Elegoo Neptune 4 series | printer.cfg and console in the web interface | The bed ships on watermark (on-off) control; Elegoo switches it to pid, then runs PID_CALIBRATE HEATER=heater_bed TARGET=60 and SAVE_CONFIG |
| Bambu Lab | No user routine published | Temperature faults go through the HMS error pages |
On a Bambu Lab printer a temperature that will not hold ends in an HMS code; the Bambu Lab HMS error guide explains how to look it up.
Check that the new values work
Heat to your print temperature with the fan at the tuned speed (M109 S210 on Marlin).
Watch for a couple of minutes. M155 S2 reports the temperature every 2 seconds if your firmware has auto-reporting; a graph in your host program shows a slow swing best.
Turn the fan fully on, then off. A dip of 2 to 3 °C that recovers within half a minute is normal (Marlin).
On Marlin, read the @: value in the temperature report, the heater power from 0 to 127. It should sit well below 127. Stuck at 127 means the heater cannot keep up: fan too strong, sock missing, or heater too weak for the target.
If the result is poor, repeat with more cycles, closer to your print temperature, at your usual fan speed. If your prints vary the fan a lot, Marlin's alternative for the hotend is Model Predictive Temperature Control (MPC, tuned with M306 T).
Bed: bang-bang or PID
Marlin's default bed control is bang-bang: every 5 seconds the heater goes fully on below the target and off above it. The bed wobbles a degree or two, which Marlin calls harmless for most prints. Bed PID (PIDTEMPBED in Marlin, control: pid in Klipper) holds it to a fraction of a degree.
PID switches the heater fast, in Klipper up to ten times a second. That suits a MOSFET or an SSR rated for it, never a mechanical relay: Marlin warns the contacts wear out, and a relay that sticks closed is a fire risk. If you do not know what switches your bed, keep bang-bang.
A small swing can still show in prints. CNC Kitchen traced regular horizontal bands to a bed swinging about 1 °C under bang-bang: the bed flexed enough to change the layer height, and bed PID removed the marks. Bed temperatures per material are in the heated bed temperature guide, other causes of bands in Z banding causes and fixes. The video starts at CNC Kitchen's chapter on bang-bang control.
A bed autotune takes far longer than a hotend tune; let it finish. Marlin only gives up after 20 minutes without the temperature crossing the target.
When the autotune fails or the swing is a hardware fault
Autotune messages in Marlin
| Message | Cause | What to do |
|---|---|---|
| PID Autotune failed! Bad heater id | E names a heater without PID, such as E-1 without PIDTEMPBED | Check E and the firmware options |
| PID Autotune failed! Temperature too high | S above the heater's limit, or 30 °C past the target | Lower S; check thermistor type and seating |
| PID Autotune failed! timeout | No crossing of the target for 20 minutes | Less fan, insulate the bed, or tune lower |
| Heating failed or THERMAL RUNAWAY | Thermal protection tripped | A wiring or power fault, not tuning |
No tune fixes broken hardware. Switch the printer off, unplug it and let the hotend cool before you touch the block, cartridge or any wire. Then check:
Thermistor and heater seated fully in the block and held by their screws. A thermistor partly out of the block reads the air, and the controller overheats the block (Marlin).
Wiring where it bends, and connectors at the board and the hotend. Stack Exchange owners traced jumping readings to a thermistor wire loose in its crimp and to a thermistor not seated in the block.
The right heater. One Stack Exchange owner whose new hotend overshot by up to 45 °C had a 12 V cartridge in a 24 V printer; no tune could fix that. A 24 V cartridge in a 12 V printer heats too weakly (Marlin). Check the voltage marked on the part.
Resistance. Prusa gives 80 to 125 kilo-ohm for the MK3S hotend thermistor at room temperature and 12.3 to 15.1 ohm for its heater. Bambu Lab gives about 12 ohm (X1) or 10 ohm (P1) for the heater and 50 to 100 kilo-ohm (X1) or about 100 kilo-ohm (P1) for the thermistor. Otherwise compare with the part's rating.
Power supply. A voltage that sags when the bed switches on starves the hotend; see the power supply guide.
Replace the part if a reading still jumps after reseating, a resistance is far outside its rating, or the heater runs with no target set. A printer that halts with a thermal error belongs in the thermal runaway guide. Never raise the protection limits or switch them off to finish a tune: every such error has a physical cause (Marlin).
Next step and related guides
Once the temperature holds, choose the temperature itself with a temperature tower. If the fan is the trouble, the printer fans guide covers ducts and speeds, and the hotend guide covers socks and heater blocks. Where PID tuning fits among other calibrations is in calibrating a 3D printer in the right order. If you need a part rather than a tuned printer, the 3D printing service prints PLA and PETG parts from your file.
Sources
3D Printing Stack Exchange: PID auto-tuning with the fan at 100%?
3D Printing Stack Exchange: RAMPS won't PID tune and shows unreal temps
3D Printing Stack Exchange: Drop in temperature after couple layers
3D Printing Stack Exchange: PID autotune fails under all conditions
Klipper Discourse: Default extruder smooth_time causing temperature oscillations
CNC Kitchen on YouTube: PID vs Bang-Bang Temperature Control

