3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 8 Temperature Control
description: Heating the bed and nozzle safely and efficiently.
---

Tutorial 8 Temperature Control

1. Lesson Header

2. Concept Introduction

The Physics of Melting.

Every filament has a "Goldilocks Zone."
- Too Cold: Layers delaminate (don't stick), extruder skips.
- Too Hot: Stringing, blobs, curling, and degradation.

G-code gives us direct control over the heaters. We have two main heaters:
1. Extruder (T0): Melts the plastic.
2. Bed (B): Helps the first layer stick.

3. Machine State Explanation

Wait vs. Don't Wait
This is the key distinction.
- Set & Forget (M104): "Set the target to 200°C and immediately execute the next line of code." (Multitasking).
- Set & Wait (M109): "Set the target to 200°C and pause the entire machine until it reaches that temperature." (Blocking).

4. Command Breakdown

Set Extruder Temp (M104 S...)

- Syntax: M104 S200 - Use: Preheating while homing.

Wait for Extruder Temp (M109 S...)

- Syntax: M109 S200 - Use: Right before printing starts.

Set Bed Temp (M140 S...)

- Syntax: M140 S60 - Use: Preheating.

Wait for Bed Temp (M190 S...)

- Syntax: M190 S60 - Use: Right before printing starts.

5. Minimal Working Example

A typical "Start G-code" sequence:

M140 S60     ; Set Bed to 60C (Don't wait)
M104 S160    ; Set Nozzle to 160C (Don't wait - prevent oozing)
G28          ; Home all axes (Takes time, so heaters are working)
M190 S60     ; Wait for Bed to reach 60C
M109 S200    ; Wait for Nozzle to reach 200C (Printing Temp)
; Now start printing...

6. Visual Representation

Interactive preview is available in the interactive reader.

7. Build Exercise

Task: Write a script that:
1. Sets the bed to 50°C.
2. Sets the nozzle to 190°C.
3. Waits for both.
4. Extrudes 10mm of filament.
5. Turns off all heaters (S0).

...

Solution:

M140 S50 ; Set Bed
M104 S190 ; Set Nozzle
M190 S50 ; Wait Bed
M109 S190 ; Wait Nozzle

G21
G90
M83
G1 E10 F100 ; Extrude slow

M104 S0 ; Turn off Nozzle
M140 S0 ; Turn off Bed

8. Deep Insight Section

PID Tuning
Your printer doesn't just turn the heater ON or OFF (Bang-Bang control). It uses a PID loop to pulse the power thousands of times a second to hold the temperature steady within 0.1°C.
You can auto-tune this with M303 (advanced command), but G-code just sets the Target (S value).

9. Common Failure Modes

  1. The "Forever Wait": If your printer can only reach 240°C but you command M109 S250, it will sit there forever trying to reach it. You must reset the printer.
  2. Oozing during Heatup: If you heat the nozzle to 200°C before homing (G28), plastic will drool out while the head is moving to the home position. This is why we often heat to 160°C first, home, then heat to 200°C.

10. Real-World Application

Temperature Towers

This is the standard way to find the best temp for a new roll of filament.
- Layer 0-50: Print at 220°C.
- Layer 50-100: Print at 215°C (M104 S215).
- Layer 100-150: Print at 210°C (M104 S210).

You can insert these M104 commands manually into the G-code or use a post-processing script.

11. Final Clean Version

Save this as lesson8.gcode.

; Lesson 8 - The Heat Tower Segment
; Setup
G21
G90
M83

; --- HEATING SEQUENCE ---
M140 S60     ; Bed Target
M104 S190    ; Nozzle Target
G28          ; Home
M190 S60     ; Wait for Bed
M109 S190    ; Wait for Nozzle

; --- SEGMENT 1 (190C) ---
G1 Z0.3
G1 X50 Y50
G1 X100 Y50 E5 F1500 ; Line 1

; --- CHANGE TEMP ---
M104 S210    ; Change target to 210 (Don't wait, keep printing)
; The nozzle will heat up WHILE printing the next lines

; --- SEGMENT 2 (Transitioning to 210C) ---
G1 X100 Y60 E1
G1 X50 Y60 E5

; --- COOL DOWN ---
M104 S0
M140 S0
G28 X0 Y0    ; Park

12. Stretch Challenge

Challenge: Write a "Cooldown" script.
After a print finishes, sometimes we want the fan to stay on until the nozzle drops below 50°C to prevent "Heat Creep" (heat rising up the heartbreak).

Hint: There is no standard "Wait for Cool Down" command in basic G-code, but M109 R50 (Wait for Target and Wait if Cooling) exists in some firmwares (Marlin).

Answer Key:

M106 S255 ; Fan Full Speed
M104 S0   ; Turn off heater
M109 R50  ; Wait for temp to drop to 50
M107      ; Fan Off