Learning about G-codes is a fantastic way to optimize your 3D printer as best as possible, considering they offer you the most in-depth way of tweaking the configuration.
While there are way too many G-codes to go through, it’s undeniable that some of them are more useful than others due to the functionality they bring to the table.
Today, we will be talking about a set of hotend temperature-related G-codes we believe are among the most useful; and should be a part of every 3D printing enthusiast’s toolkit.
So, what are the M104 and M109 G-codes?
- M104 (Set Hotend Temperature) – Sets the hotend to the specified temperature without pausing the printing process.
- M109 (Wait for Hotend Temperature) – Sets the hotend to the specified temperature and pauses the printing process until the hotend reaches the target temperature.
As both of these G-codes come with parameters that allow you to extend their functionality further, we will be talking about both of them in greater detail moving forward.
Table of Contents
M104 G-Code (Set Hotend Temperature)
The M104 G-code is the primary way of setting the temperature of the hotend.
When you send the M104 command to the printer with the target temperature, the printer immediately starts bringing the hotend to the target temperature while continuing the printing process.
Using the basic functionality of the M104 command is as easy as passing it a target temperature, which we will outline in the example below.
In this example, the S flag refers to the target temperature, and 200 refers to 200 degrees.
When you run this command, the printer will start bringing the hotend temperature to 200 degrees as the printing process goes on and hold the temperature stable when the hotend reaches the target.
On the Marlin firmware, the M104 command has extended functionality in the form of AutoTemp, which stands for automatic temperature.
If you’re on Marlin, you can enable the AutoTemp feature by passing the F flag to the command, which we will outline in the example below:
M104 F S150 B200
In this example, as AutoTemp is enabled, the S flag determines the minimum auto-temperature, whereas the B flag determines the maximum.
As a result of running this command, the hotend will have a variable temperature between 150 and 200 degrees, changing depending on the scenario.
Since the optimal hotend temperature depends on the extruder velocity, the temperature also needs to change if the extruder velocity changes throughout the print, which is where AutoTemp comes into play.
Finally, there is one last parameter in the Marlin firmware, which is the T flag.
This flag determines the hotend index for printers with multiple hotends, but as it defaults to the active hotend when omitted, it’s usually not necessary to pass this flag.
M109 G-Code (Wait for Hotend Temperature)
While the M109 G-code is also for setting the hotend temperature, it works slightly differently than M104.
When you run the M109 G-code, the printer pauses the printing process and starts bringing the temperature of the hotend to the target you have chosen. When the hotend reaches the target temperature, the printing process continues.
Here is an example of the most common way of using the M109 command, consistent between all 3D printer firmware.
In this example, the S flag refers to the target temperature. Due to how the S flag works, the printer will only pause the process if the target temperature is above the current temperature (heating).
If we assume that the hotend is at 150 degrees when you run this command, the printer will wait until 180 degrees of temperature is reached and continue the print afterward.
On the other hand, if we assume that the hotend is at 200 degrees, the printer will bring the temperature of the hotend down to 180 degrees without pausing the printing process.
On the Marlin firmware, it’s possible to extend the functionality of the M109 command with a few additional parameters.
R Flag (Wait for Both Cooling and Heating)
The R flag is also a way of setting the temperature like the S flag, but there is a vital difference between the two.
Unlike the S flag that only causes the printing process to stop for a heating operation, the R flag will pause the printing process regardless of whether the target temperature triggers the heating or cooling of the hotend.
The usage of the R flag is similar to the S flag, which you can see in the example below.
In this case, whether the hotend is at 200 degrees or 150 degrees when you run the command, the printing process will pause until the target temperature of 180 degrees is reached.
AutoTemp (Automatic Temperature)
It’s also possible to activate AutoTemp with M109, which works the same way with M104.
Once again, the B flag is for maximum temperature, the S flag is for minimum temperature, and the F flag activates the AutoTemp feature.
Let’s take a look at a quick example.
M109 F S170 B190
In this example, the hotend will have a dynamic temperature between 170 and 190 degrees, and the printing process will be paused for temperature changes whenever they may happen.
Finally, just as M104, M109 also allows you to use the T flag to choose the hotend index if you have a printer with multiple hotends.
To bring it all together, let’s look at one final example.
M109 F T1 S150 B200
In this example, extruder number 1 will have AutoTemp enabled with a minimum temperature of 150 degrees and a maximum temperature of 200 degrees.
As the M109 command is used, the printer will stop printing when a temperature change is initiated.
As these G-codes allow you to have in-depth access to the temperature control of your 3D printer’s hotend, they can come in handy in quite a few situations where fine-tuning is necessary.
While using these G-codes effectively to improve your prints may take some experience, they are a great set of tools to keep in mind as the occasion for using them will eventually arise.
We will be sharing more of these in-depth explanations for G-codes that we think are useful to know about in the future, so stay tuned.
Mike started his 3D printing journey with the Anet A8 when it first came out back in 2017, and has been obsessed with 3D printers ever since. Nowadays, he primarily uses his Ender 3 to print functional parts that make his life more convenient whenever possible.