Marlin PID Tuning Guide: Fix Temperature Swings & Thermal Runaway

If you have ever watched your 3D printer’s temperature graph and seen it waving up and down like a rollercoaster, you have a PID problem.
Temperature stability is the backbone of high-quality prints. If your hotend fluctuates by even a few degrees, the plastic’s viscosity changes, leading to inconsistent extrusion. Equally important is your heated bed; if it oscillates, the build plate expands and contracts, causing visible horizontal lines or causing parts to warp and detach from the bed. In the worst case, instability in either heater triggers the dreaded "Thermal Runaway" error that halts your print mid-way.
Fortunately, Marlin firmware has a built-in "Autotune" feature that fixes this. It’s called PID Tuning. It essentially teaches your printer how to handle its own heating elements intelligently, rather than just blasting power blindly.
In this guide, we will walk through exactly how to calibrate these settings to get that temperature line dead flat.
To perform PID tuning, you need to send direct G-code commands to your printer. You cannot usually do this from the printer's standard LCD screen.
You will need:
- A Terminal Interface: You can use OctoPrint (Terminal tab) or Pronterface (connected via USB).
- Filament Loaded: Having filament in the nozzle ensures the thermal mass represents a real-world printing scenario.
- A "Cold" Printer: For the best accuracy, start with the printer at room temperature.
What is PID? (The "Cruise Control" Analogy)
PID stands for Proportional, Integral, and Derivative.
Without getting bogged down in calculus, think of it like the cruise control in your car. If you want to go 60 MPH, you don't floor the gas until you hit 60 and then slam on the brakes. You apply variable gas to maintain speed smoothly, adjusting for hills (external cooling) and wind (fans).

Old-school printers used "Bang-Bang" heating—full power ON or full power OFF. This causes temperatures to swing wildly. PID allows the printer to feather the power—applying 100%, then 50%, then 2%—to keep the temperature rock steady.
You should run a PID Autotune whenever you change a component that affects how your hotend heats up or cools down:
- Changing the hotend (e.g., swapping to an all-metal hotend).
- Replacing the heater cartridge or thermistor.
- Installing a new part cooling fan or fan duct.
- Adding or removing a silicone sock.
Tuning Your Hotend
Marlin makes this surprisingly easy with the M303 command. This tells the printer to heat up, cool down, and analyze how the heater responds to power changes.
Step 1: Turn on Your Part Cooling Fan
This is the most common mistake people make. You print with your fan on, so you must tune with your fan on. If you tune with the fan off, your printer won't account for that extra cooling air, and your temperature will plummet as soon as the fan kicks on during a real print.
Set your part cooling fan to your typical printing speed (usually 100%) before running the command. Send the command M106 S255 to turn the fan to 100%.
Step 2: Run the M303 Command
In your terminal, you will send a command that tells the printer: "Run autotune (M303) on the first extruder (E0) at 210 degrees (S210) for 10 cycles (C10)."
Pick a temperature close to what you usually print. If you print PLA at 205°C, tune at 205°C. If you print PETG at 245°C, tune at 245°C. If you print both, pick a middle ground (like 225°C).
Send this command in your terminal:
M303 E0 S210 C10
Your printer will now cycle the heat. Watch the terminal output; you will see it reporting "PID Autotune start." This process usually takes 5–10 minutes.
Step 3: Get Your Values
Once the 10 cycles are done, the terminal will output a final result that looks like this:
Kp: 22.20 Ki: 1.08 Kd: 114.00
PID Autotune finished! Put the last Kp, Ki and Kd constants from below into Configuration.h
Write down those three numbers (Kp, Ki, and Kd).
Step 4: Apply and Save
Now you need to tell the printer to use these new numbers using the M301 command.
Example (Use YOUR numbers, not these):
M301 P22.20 I1.08 D114.00
Finally, and most importantly, you must save this to the printer's memory (EEPROM). If you turn the printer off without saving, you lose the tune.
M500
Tuning Your Heated Bed
Many people skip tuning the bed, but a fluctuating bed causes the printers build plate to expand and contract. This can lead to "Z-banding" (horizontal lines) or cause prints to detach and warp due to inconsistent adhesion.
The process is nearly identical to the hotend, but we use E-1 to select the bed.
Step 1: Run the Autotune
We recommend tuning the bed to your most common printing temperature—typically around 60°C for PLA, 80°C for PETG, or 100°C for ABS.
M303 E-1 S60 C10
Step 2: Apply the Values
Once the process finishes, grab your Kp, Ki, and Kd values. Note that for the bed, we use M304 to apply them (M301 is for hotends, M304 is for beds).
Example (Use YOUR numbers, not these):
M304 P120.43 I2.15 D890.22
Step 3: Save
M500
Some older printers have "PIDTEMPBED" disabled in the firmware, forcing them to use Bang-Bang mode. If you send M303 E-1 and get an error saying "PID not enabled," you will need to recompile your firmware to enable it. For most modern printers (Ender 3 V2, Prusa, etc.), this is enabled by default.
Troubleshooting Common Errors
This happens if your heater is very powerful and overshoots the target temperature before the sensor catches it.
How to Fix:
- Let the machine cool down completely.
- Try running the test at a slightly higher temperature.
- Ensure your thermistor is securely seated inside the heater block.
This means the heater didn't reach the target temperature fast enough.
How to Fix:
- Check if your heater cartridge is underpowered.
- Ensure your part cooling fan is not blowing directly on the heater block (try insulating the block with a silicone sock).
- Always Fan On: Turn your part cooling fan to 100% before tuning the hotend.
-
M303 is the key: Use
M303 E0 S[Temp] C10for the hotend andM303 E-1 S[Temp] C10for the bed. - Don't forget M500: If you don't save to EEPROM, your settings vanish when you power off.
- Tune after changes: If you change your nozzle, heater, or fan duct, you must retune.
- Stability = Quality: Stable temperatures prevent layer lines and thermal runaway errors.
Do I need to PID tune for every filament type?
No. While technically ideal, it's not practical. We recommend tuning at a "middle ground" temperature (e.g., 220°C) which covers both PLA and PETG reasonably well. The PID algorithm is robust enough to handle small deviations.
Can I PID tune from the LCD screen?
On some advanced printers (like Prusa MK3/MK4 or custom compiled Marlin), there is a PID calibration menu option. However, for most stock Creality or Ender style machines, you must use a terminal via USB or OctoPrint.
My temperature still fluctuates after tuning. Why?
If tuning doesn't fix it, you likely have a hardware issue. Check for a loose thermistor screw, a damaged thermistor wire, or a drafty room. Also, ensure your silicone sock is installed on the heater block.
What is the 'U1' parameter I sometimes see?
Adding 'U1' to the end of the M303 command (e.g., M303 E0 S210 C10 U1) tells Marlin to automatically apply the result to current settings if the test finishes successfully. You still need to run M500 to save it permanently.
4 comments
This is the best documentation of PID for desk top 3D “printing” i would love to share this but the credits only state -3DMaker Engineering and normally there is an name attached. Our company policy is to give 100% credit in all documentation
Hot end tuning went very well. Heated bed tuning seems to result in widely varying results as the K values from the previous run are entered and the test re run. One question I have is how much variation is to be accepted? Second question is whether I should repeat the test multiple times while updating the K values until satisfied?
Thanks for this a bunch!! One thing I ran into in recent Marlin builds is that the heated bed pid autotune is disabled out of the box.
Line 531
#define PIDTEMPBED
Thanks again for this guide!
I enter command as stated. Machine heats to temp. Hovers up and down then cools. I get no feedback. Sent using both Cura 4.4 and Easy Print.
Thank you