0
0
3D Printingknowledge~15 mins

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

Choose your learning style9 modes available
Overview - Common G-code commands (G0, G1, G28, M104, M106)
What is it?
G-code is a language that tells 3D printers and CNC machines how to move and operate. Common G-code commands like G0, G1, G28, M104, and M106 control movements, positioning, and machine functions such as heating and fan control. These commands are simple instructions that guide the printer step-by-step to create objects. Understanding these commands helps you know how your 3D printer works and how to fix or customize prints.
Why it matters
Without these commands, 3D printers wouldn't know where to move or how to prepare for printing. They solve the problem of translating digital designs into physical movements and actions. If these commands didn't exist, printing would be random or impossible, leading to failed prints and wasted materials. Knowing them lets you troubleshoot, optimize prints, and even create custom printing behaviors.
Where it fits
Before learning these commands, you should understand basic 3D printing concepts like layers, axes (X, Y, Z), and printer parts (nozzle, bed, fans). After mastering these commands, you can explore advanced G-code programming, custom macros, and firmware settings to fully control your printer.
Mental Model
Core Idea
Common G-code commands are simple, step-by-step instructions that tell a 3D printer how to move, heat, and cool to build an object layer by layer.
Think of it like...
It's like giving a robot precise directions: 'Go straight to this spot,' 'Move slowly while drawing,' 'Heat up before starting,' or 'Turn on the fan now.' Each command is a clear order the robot follows exactly.
┌───────────────┐
│  G-code Line  │
│  (Command)    │
└──────┬────────┘
       │
       ▼
┌───────────────┐
│  Movement     │
│  or Action    │
└──────┬────────┘
       │
       ▼
┌───────────────┐
│  Printer      │
│  Executes     │
└───────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding G-code Basics
🤔
Concept: G-code commands are text instructions that control printer movements and actions.
G-code lines start with a letter (G or M) followed by numbers and parameters. G commands mainly control movements, while M commands control machine functions like heating or fans. For example, G0 and G1 move the print head, but G1 moves while extruding filament.
Result
You can read and recognize basic G-code commands and know their general purpose.
Understanding the difference between G and M commands helps you know which control movement and which control machine functions.
2
FoundationAxes and Positioning in G-code
🤔
Concept: G-code commands use X, Y, and Z coordinates to tell the printer where to move.
The printer's nozzle moves in three directions: X (left-right), Y (front-back), and Z (up-down). Commands like G0 and G1 include coordinates like X10 Y20 Z0.3 to specify exact positions. The printer moves the nozzle to these points to build layers.
Result
You can understand how G-code controls the printer's position in 3D space.
Knowing how coordinates map to physical printer movements is key to understanding how prints are formed layer by layer.
3
IntermediateG0 and G1: Rapid and Controlled Moves
🤔Before reading on: do you think G0 and G1 commands move the printer head at the same speed or different speeds? Commit to your answer.
Concept: G0 commands move the print head quickly without extruding, while G1 moves at controlled speeds and extrudes filament.
G0 is used for fast, non-printing moves to reposition the nozzle quickly. G1 moves the nozzle while pushing filament out to create the print. Both commands include coordinates and optional speed settings. For example, G1 X50 Y50 E10 moves to X50 Y50 while extruding 10 units of filament.
Result
You can distinguish between fast moves and printing moves in G-code.
Understanding the difference prevents mistakes like extruding filament during rapid moves, which can cause blobs or stringing.
4
IntermediateG28: Homing the Printer
🤔Before reading on: does G28 move the printer to a random position or a fixed reference point? Commit to your answer.
Concept: G28 tells the printer to move all axes to their home positions, usually where limit switches are triggered.
Homing sets the printer's coordinate system by moving the nozzle to known reference points, often at the edges of the print bed. This ensures all future moves are accurate. For example, G28 moves X, Y, and Z axes to their home positions. You can also home individual axes like G28 X or G28 Z.
Result
You understand how the printer knows its starting point for accurate printing.
Knowing homing is essential for print accuracy and avoiding crashes or misaligned layers.
5
IntermediateM104: Setting Nozzle Temperature
🤔Before reading on: does M104 wait for the nozzle to reach temperature before continuing or not? Commit to your answer.
Concept: M104 sets the nozzle temperature but does not wait for it to reach the target before moving on.
M104 S200 sets the nozzle temperature to 200°C. The printer starts heating but continues executing the next commands immediately. To wait until the temperature is reached, M109 is used instead. This allows heating and other preparations to happen in parallel.
Result
You can control nozzle heating timing and avoid print errors from cold extrusion.
Knowing the difference between M104 and M109 helps optimize print start times and prevents nozzle jams.
6
AdvancedM106: Controlling the Cooling Fan
🤔Before reading on: does M106 turn the fan on at full speed only, or can it set variable speeds? Commit to your answer.
Concept: M106 controls the cooling fan speed with values from 0 (off) to 255 (full speed).
M106 S128 sets the fan to about half speed. Cooling fans help solidify the printed filament quickly, improving print quality. You can turn the fan off with M107. Adjusting fan speed during printing affects layer adhesion and surface finish.
Result
You can manage cooling to improve print quality and avoid warping or stringing.
Understanding fan control lets you fine-tune prints for different materials and geometries.
7
ExpertCombining Commands for Efficient Printing
🤔Before reading on: do you think combining movement and temperature commands in sequence affects print speed or quality? Commit to your answer.
Concept: Expert G-code sequences combine movement, heating, and fan commands to optimize print speed and quality.
For example, starting a print might include G28 to home, M104 to start heating, G0 to move to start position, and M106 to turn on the fan. Knowing when to wait for temperature (M109) or move immediately (M104) affects print time. Also, combining G1 moves with extrusion and fan speed changes can smooth transitions and improve layer bonding.
Result
You can write or modify G-code to make prints faster and better without manual intervention.
Knowing how to sequence commands strategically unlocks advanced control over printing processes and troubleshooting.
Under the Hood
G-code commands are interpreted line-by-line by the printer's firmware, which translates them into electrical signals that move stepper motors, control heaters, and operate fans. The firmware maintains a coordinate system and tracks temperatures, ensuring movements and actions happen precisely as commanded. Commands like G0 and G1 adjust motor steps to move the nozzle, while M commands control hardware components. The printer processes commands in order, sometimes waiting for conditions like temperature before continuing.
Why designed this way?
G-code was designed as a simple, text-based language to be easy to generate, read, and modify. Separating movement (G commands) from machine functions (M commands) keeps instructions clear and modular. The design allows printers from different manufacturers to use a common language, promoting compatibility. Waiting commands like M109 were added to handle hardware constraints safely, while non-waiting commands like M104 improve efficiency by allowing parallel operations.
┌───────────────┐
│  G-code Line  │
└──────┬────────┘
       │
       ▼
┌───────────────┐
│  Firmware     │
│  Interpreter  │
└──────┬────────┘
       │
       ▼
┌───────────────┬───────────────┬───────────────┐
│Stepper Motors │Heaters       │Fans           │
│(X,Y,Z,E axes)│(Nozzle, Bed) │(Cooling Fan)  │
└───────────────┴───────────────┴───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does G0 always move faster than G1? Commit to yes or no before reading on.
Common Belief:G0 always moves the print head faster than G1.
Tap to reveal reality
Reality:G0 is intended for rapid moves without extrusion, but actual speed depends on firmware settings and can be similar to G1 speeds.
Why it matters:Assuming G0 is always faster can lead to incorrect expectations about print time and cause confusion when speeds seem inconsistent.
Quick: Does M104 wait for the nozzle to reach temperature before continuing? Commit to yes or no before reading on.
Common Belief:M104 waits for the nozzle to heat before moving to the next command.
Tap to reveal reality
Reality:M104 sets the temperature but does not wait; the printer continues immediately. M109 is the command that waits.
Why it matters:Misunderstanding this can cause printing to start before the nozzle is hot, leading to poor extrusion or clogs.
Quick: Does G28 move the nozzle to a random position? Commit to yes or no before reading on.
Common Belief:G28 moves the nozzle to a random or user-defined position.
Tap to reveal reality
Reality:G28 always moves the nozzle to the home position defined by the printer's limit switches.
Why it matters:Thinking G28 moves to arbitrary points can cause confusion and improper printer setup, risking crashes or misalignment.
Quick: Can M106 only turn the fan fully on or off? Commit to yes or no before reading on.
Common Belief:M106 can only turn the fan fully on or off.
Tap to reveal reality
Reality:M106 can set the fan speed anywhere from 0 (off) to 255 (full speed), allowing fine control.
Why it matters:Ignoring variable fan speeds limits print quality control and material-specific cooling strategies.
Expert Zone
1
Some printers and firmware allow combining multiple commands on one line, but this can cause timing issues if not handled carefully.
2
The difference between absolute and relative positioning modes (G90 vs G91) changes how coordinates in G0/G1 are interpreted, which can cause unexpected moves if misunderstood.
3
Fan control with M106 can be linked to temperature sensors or print progress, enabling dynamic cooling strategies that improve print quality.
When NOT to use
Using manual G-code commands is not ideal for beginners or complex prints; slicer software automates command generation better. For advanced motion control, newer protocols or firmware-specific commands may be preferred. Also, relying solely on G-code for temperature control can be risky; firmware safety features and sensors should be used.
Production Patterns
In professional 3D printing, G-code is often customized with start and end scripts to prepare the printer and finish prints cleanly. Conditional commands and macros automate repetitive tasks. Cooling fan speeds are adjusted dynamically based on layer time or material. Homing (G28) is always done before printing to ensure accuracy. Temperature commands are sequenced to minimize wait times while ensuring proper extrusion.
Connections
CNC Machining G-code
Common language and command structure
Understanding 3D printer G-code helps grasp CNC machining commands since both use similar instructions for precise machine control.
Robotics Motion Control
Shared principles of coordinate-based movement
G-code commands resemble robotic arm instructions, showing how coordinate systems and stepwise commands control physical movement in automation.
Cooking Recipes
Step-by-step instructions to achieve a result
Like G-code guides a printer, recipes guide cooking; both require precise steps in order and timing to produce a successful outcome.
Common Pitfalls
#1Starting a print before the nozzle is heated.
Wrong approach:M104 S200 G28 G1 X50 Y50 E10
Correct approach:M104 S200 G28 M109 S200 G1 X50 Y50 E10
Root cause:Using M104 without waiting (M109) causes extrusion before the nozzle reaches proper temperature.
#2Assuming G0 extrudes filament during moves.
Wrong approach:G0 X100 Y100 E5
Correct approach:G1 X100 Y100 E5
Root cause:G0 is for rapid moves without extrusion; adding extrusion parameters to G0 is ignored or causes errors.
#3Not homing the printer before printing.
Wrong approach:G1 X0 Y0 Z0
Correct approach:G28 G1 X0 Y0 Z0
Root cause:Skipping G28 means the printer doesn't know its true position, leading to inaccurate or damaging moves.
Key Takeaways
Common G-code commands like G0, G1, G28, M104, and M106 are essential instructions that control printer movement, positioning, heating, and cooling.
G0 moves the print head quickly without extruding, while G1 moves with extrusion to build the object layer by layer.
Homing with G28 sets the printer's reference point, ensuring accurate and safe printing.
M104 sets nozzle temperature without waiting, while M109 waits for the target temperature before continuing.
M106 controls the cooling fan speed, allowing fine adjustments to improve print quality.