Bird
Raised Fist0
3D Printingknowledge~6 mins

Common G-code commands (G0, G1, G28, M104, M106) in 3D Printing - Full Explanation

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
When controlling a 3D printer, you need clear instructions to tell it how to move and operate. These instructions come as simple codes that the printer understands to perform tasks like moving the print head or heating the nozzle.
Explanation
G0 - Rapid Movement
G0 commands tell the printer to move the print head quickly to a new position without extruding any material. This is used to reposition the head between printing areas to save time. The printer moves as fast as possible along the specified coordinates.
G0 moves the print head fast without printing.
G1 - Controlled Movement with Extrusion
G1 commands move the print head to a new position while extruding filament to build the object layer by layer. The speed and amount of material extruded are controlled precisely to create accurate shapes. This is the main command used during printing.
G1 moves the print head while pushing out filament to print.
G28 - Auto Home
G28 sends the print head to its home position, usually the corner of the printer bed. This resets the printer’s position sensors so it knows exactly where the head is before starting a print. It ensures accurate printing by starting from a known point.
G28 moves the print head to the home position to reset location.
M104 - Set Nozzle Temperature
M104 sets the temperature of the printer’s nozzle to a specific value but does not wait for it to reach that temperature before continuing. This command prepares the nozzle to melt the filament for printing. It allows the printer to heat up while doing other tasks.
M104 sets the nozzle temperature without waiting.
M106 - Fan On
M106 turns on the cooling fan at a specified speed to help solidify the printed material quickly. Cooling is important to prevent warping and improve print quality. The fan speed can be adjusted from off to full power.
M106 controls the cooling fan speed during printing.
Real World Analogy

Imagine you are painting a wall. G0 is like moving your brush quickly to a new spot without painting. G1 is moving the brush slowly while applying paint. G28 is stepping back to the corner of the room to start fresh. M104 is turning on the heater to warm the paint so it spreads well. M106 is turning on a fan to help the paint dry faster.

G0 - Rapid Movement → Moving your brush quickly without painting
G1 - Controlled Movement with Extrusion → Moving your brush slowly while applying paint
G28 - Auto Home → Stepping back to the corner to start fresh
M104 - Set Nozzle Temperature → Turning on the heater to warm the paint
M106 - Fan On → Turning on a fan to dry the paint faster
Diagram
Diagram
┌───────────────┐
│   Start Print │
└──────┬────────┘
       │
       ▼
┌───────────────┐       ┌───────────────┐
│     G28       │──────▶│   G0 Move     │
│  Auto Home    │       │ Rapid Position │
└──────┬────────┘       └──────┬────────┘
       │                       │
       ▼                       ▼
┌───────────────┐       ┌───────────────┐
│    M104       │       │     G1 Move   │
│ Set Nozzle    │       │ Controlled    │
│ Temperature   │       │ Movement +    │
└──────┬────────┘       │ Extrusion     │
       │                └──────┬────────┘
       ▼                       │
┌───────────────┐              ▼
│    M106       │       ┌───────────────┐
│  Fan On       │       │   Printing    │
│ (Cooling)     │       │   Process     │
└───────────────┘       └───────────────┘
This diagram shows the flow of common G-code commands during a 3D print, from homing to moving, heating, cooling, and printing.
Key Facts
G0Moves the print head quickly without extruding filament.
G1Moves the print head while extruding filament to print.
G28Moves the print head to the home position to reset coordinates.
M104Sets the nozzle temperature without waiting for it to reach the target.
M106Turns on the cooling fan at a specified speed.
Common Confusions
Believing G0 extrudes filament like G1.
Believing G0 extrudes filament like G1. G0 only moves the print head quickly without pushing filament; extrusion happens only with G1.
Thinking M104 waits for the nozzle to heat before continuing.
Thinking M104 waits for the nozzle to heat before continuing. M104 sets the temperature but does not pause the printer; M109 is the command that waits.
Assuming G28 moves the print head to any position.
Assuming G28 moves the print head to any position. G28 always moves the head to the predefined home position to reset coordinates.
Summary
G0 moves the print head quickly without printing, while G1 moves it precisely with filament extrusion.
G28 resets the printer’s position by moving the head to the home corner before printing starts.
M104 sets the nozzle temperature without waiting, and M106 controls the cooling fan speed.

Practice

(1/5)
1. What does the G-code command G28 do in 3D printing?
easy
A. Sets the extruder temperature
B. Homes all axes to their origin positions
C. Moves the print head quickly without extruding
D. Turns on the cooling fan

Solution

  1. Step 1: Understand the purpose of G28

    The G28 command is used to move the printer's axes to their home or origin positions, ensuring the printer knows where the starting point is.
  2. Step 2: Compare with other commands

    Other commands like G0 move quickly without printing, M104 sets temperature, and M106 controls the fan, so they do not home the axes.
  3. Final Answer:

    Homes all axes to their origin positions -> Option B
  4. Quick Check:

    G28 = Home axes [OK]
Hint: G28 always means 'go home' for all axes [OK]
Common Mistakes:
  • Confusing G28 with G0 or G1 which move the head
  • Thinking M104 or M106 control movement instead of temperature or fan
  • Assuming G28 sets temperature or fan speed
2. Which of the following is the correct syntax to set the extruder temperature to 200°C using G-code?
easy
A. G28 S200
B. M106 S200
C. G1 S200
D. M104 S200

Solution

  1. Step 1: Identify the command for setting extruder temperature

    M104 is the G-code command used to set the extruder temperature to a specified value.
  2. Step 2: Check the syntax

    The correct syntax is M104 followed by S and the temperature value, so M104 S200 sets the extruder to 200°C.
  3. Final Answer:

    M104 S200 -> Option D
  4. Quick Check:

    M104 sets extruder temp = M104 S200 [OK]
Hint: M104 sets extruder temp; M106 controls fan [OK]
Common Mistakes:
  • Using M106 which controls the fan instead of temperature
  • Using G1 or G28 which are for movement, not temperature
  • Omitting the S parameter for temperature value
3. What will happen when the following G-code commands are executed?
G0 X50 Y50
G1 X100 Y100 E10
medium
A. The print head homes all axes, then sets extruder temperature to 10°C
B. The print head moves slowly to (50,50) while extruding, then quickly to (100,100) without extruding
C. The print head moves quickly to (50,50) without extruding, then moves to (100,100) while extruding filament
D. The print head turns on the fan and moves to (100,100)

Solution

  1. Step 1: Understand G0 and G1 commands

    G0 moves the print head quickly without extruding filament. G1 moves the print head while extruding filament as specified by the E parameter.
  2. Step 2: Analyze the commands given

    First, G0 moves the head to X50 Y50 quickly without extrusion. Then, G1 moves the head to X100 Y100 while extruding 10 units of filament.
  3. Final Answer:

    The print head moves quickly to (50,50) without extruding, then moves to (100,100) while extruding filament -> Option C
  4. Quick Check:

    G0 = fast move no extrusion, G1 = move with extrusion [OK]
Hint: G0 = fast move no extrusion; G1 = move with extrusion [OK]
Common Mistakes:
  • Mixing up G0 and G1 commands
  • Assuming extrusion happens during G0
  • Confusing E parameter as fan speed or temperature
4. A user writes the following G-code to turn on the cooling fan at half speed:
M106 S128

But the fan does not turn on. What is the likely error?
medium
A. The printer firmware might require a different command or fan pin setup
B. The S value should be between 0 and 255, 128 is invalid
C. The command should be M104 to control the fan
D. The G28 command is missing before M106

Solution

  1. Step 1: Understand M106 command and S parameter

    M106 controls the cooling fan speed with S value from 0 (off) to 255 (full speed). S128 is a valid half speed.
  2. Step 2: Consider why fan might not turn on

    If the fan does not turn on, it is likely due to printer firmware settings or hardware configuration, such as fan pin assignment or disabled fan control.
  3. Final Answer:

    The printer firmware might require a different command or fan pin setup -> Option A
  4. Quick Check:

    M106 S128 valid but hardware/firmware may block fan [OK]
Hint: Check firmware and hardware if M106 S128 doesn't work [OK]
Common Mistakes:
  • Thinking S128 is out of range (it's valid)
  • Using M104 instead of M106 for fan control
  • Assuming G28 is needed before fan commands
5. You want to start a print by homing all axes, setting the extruder temperature to 210°C, waiting for it to reach temperature, then moving the print head to X10 Y10 quickly without extruding. Which sequence of G-code commands is correct?
hard
A. G28
M104 S210
M109 S210
G0 X10 Y10
B. M104 S210
G28
M109 S210
G1 X10 Y10 E0
C. G28
M109 S210
M104 S210
G0 X10 Y10
D. M106 S210
G28
M109 S210
G0 X10 Y10

Solution

  1. Step 1: Identify commands for each action

    G28 homes all axes. M104 sets extruder temperature without waiting. M109 sets temperature and waits until reached. G0 moves quickly without extruding.
  2. Step 2: Check command order for correct sequence

    First home with G28, then set temp with M104, wait with M109, finally move with G0 to X10 Y10 without extrusion.
  3. Final Answer:

    G28
    M104 S210
    M109 S210
    G0 X10 Y10
    -> Option A
  4. Quick Check:

    Home, set temp, wait, then fast move = G28
    M104 S210
    M109 S210
    G0 X10 Y10 [OK]
Hint: Use M109 to wait for temp after M104, then move with G0 [OK]
Common Mistakes:
  • Using M106 instead of temperature commands
  • Moving with G1 and extruding when not needed
  • Setting temperature after moving the head