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:

  1. Heat to your print temperature and watch the graph for two minutes: a good tune holds within about 1 to 2 °C (Marlin).

  2. Sudden jumps, or swings beyond 5 °C either way: check the hardware first, with the printer switched off and unplugged.

  3. Fit the silicone sock if your hotend has one and aim the fan duct at the nozzle tip, not the block.

  4. Set the part-cooling fan to the speed you print at most, for example M106 S128 for 50%.

  5. 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.

  6. 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.

  7. 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

Based on Marlin's PID and thermal protection documentation and Prusa's PID tuning article, read on 30 November 2026.
What you seeWhat it meansWhat to do
A few degrees past the target, one or two swings, then steadyNormal for a tuned heaterNothing
A slow, regular swing of several degrees that never settlesThe PID values do not fit this heaterRun an autotune and save it
A drop of several degrees when the fan starts, a few layers inThe fan cools the heater blockFit the sock, aim the duct, tune with the fan on
Sudden spikes or drops, often when the head movesLoose thermistor, connector or damaged wireSwitch off and unplug, then check the wiring
Keeps rising past the targetHeater on when it should be off, or the sensor misreadsSwitch off now; see the thermal runaway guide
Bed wobbles a degree or two every few secondsBang-bang bed control, the Marlin defaultUsually 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:

  1. M106 S128 sets the part-cooling fan to 50% (S runs from 0 to 255). Use your usual speed, or M107 for off.

  2. M303 E0 S210 C8 U1 tunes hotend 0 at 210 °C for 8 cycles and applies the result.

  3. 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.

3D printing guides - Using Marlin's PID autotune (Made with Layers)

Klipper: PID_CALIBRATE, then SAVE_CONFIG

  1. Set the fan with M106 as above.

  2. Send PID_CALIBRATE HEATER=extruder TARGET=210. Klipper's own example uses 170; use your print temperature.

  3. 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

From Prusa's PID tuning and thermal model articles and Buddy G-code list, Creality's SPARKX i7 guide and Elegoo's Neptune 4 bed PID page, read on 30 November 2026.
PrinterWhereWhat to know
Original Prusa i3 (MK3 family)LCD Menu > Calibration > PID calibrationPick your most-used temperature; 5 cycles; with the MK3S thermal model, run Calibration > Temp Model cal. afterwards
Prusa MINI, MK4, XLNo menuA Prusa staff reply says the stock values suit the stock heaters; M303, M301 and M304 exist
Creality SPARKX i7Settings > Print Settings (page 2) > Expert Mode > Nozzle PID CalibrationSet the filament's print temperature; about 5 minutes
Elegoo Neptune 4 seriesprinter.cfg and console in the web interfaceThe 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 LabNo user routine publishedTemperature 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

  1. Heat to your print temperature with the fan at the tuned speed (M109 S210 on Marlin).

  2. 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.

  3. Turn the fan fully on, then off. A dip of 2 to 3 °C that recovers within half a minute is normal (Marlin).

  4. 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.

PID vs Bang-Bang Temperature Control (CNC Kitchen)

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

From Marlin's PID temperature control page, read on 30 November 2026.
MessageCauseWhat to do
PID Autotune failed! Bad heater idE names a heater without PID, such as E-1 without PIDTEMPBEDCheck E and the firmware options
PID Autotune failed! Temperature too highS above the heater's limit, or 30 °C past the targetLower S; check thermistor type and seating
PID Autotune failed! timeoutNo crossing of the target for 20 minutesLess fan, insulate the bed, or tune lower
Heating failed or THERMAL RUNAWAYThermal protection trippedA 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:

  1. 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).

  2. 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.

  3. 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.

  4. 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.

  5. 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).

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.