What Do the M106 & M107 G-Codes Do? (Do They Work in Marlin?)

While they are the lifeblood of a 3D printer, we usually don’t have to get too hands-on with G-codes most of the time, thanks to slicer software handling the majority of the work.

On the other hand, some G-codes can be very handy to know about as they allow you to fine-tune your 3D printer in almost every way imaginable. Even though fine-tuning isn’t always necessary, it is a fantastic way to improve your 3D printing experience as much as possible.

Two such G-codes are M106 and M107. While these commands aren’t necessary for a standard printing process, they can improve your prints or solve some of the print-related issues you face when you tune them correctly.

So, what do the M106 and M107 G-codes do?

The M106 (Set Fan Speed) command allows you to turn the cooling fans on and configure them in various ways, such as setting their speeds.

On the other hand, the M107 (Fan Off) command is what you will need to turn the cooling fans off.

Almost every 3D printing firmware supports these two G-codes, including popular firmware such as Marlin and Prusa.

While it sounds very straightforward, there are many nuances to be aware of, as the M106 command accepts a wide variety of parameters that allows you to go even deeper into fan tuning, depending on the firmware your printer is running on.

What Does the M106 G-Code Do?

At its core, the M10 G-code is one of the more user-friendly commands to understand as its functionality isn’t technically complex by any means.

In a nutshell, the M106 G-code allows you to turn the cooling fans of your printer on and configure them by using the parameters it offers.

While the first thing that comes to mind is the fan speed, the M106 command has many other parameters that you can use, depending on what the firmware offers.

To start, let’s look at the basic functionality of the M106 G-code, which is consistent between all 3D printer firmware, which, as you may predict, is tuning the fan speed.

The M106 G-code requires two parameters for tuning the fan speed, P (Fan Number) and S (Fan Speed).

  • P (Fan Number) – The value of this parameter should be a number between 0 and the number of cooling fans your printer has. If you don’t pass this parameter, it defaults to 0 in most cases, such as Marlin firmware.
  • S (Fan Speed) – The value of this parameter should be between 0 and 255 (0.0 to 1.0 also accepted in RepRapFirmware), with 0 referring to the minimum (off) – and 255 referring to maximum speed.

An example command is:

M106 P1 S150

Running this command sets the speed of fan number 1 to 150 out of 255, a value that is slightly over half-speed.

As we have mentioned earlier, the functionality of the M106 G-code doesn’t end here with plenty of extra parameters you can use for further optimization, which is what we will be talking about next.

Thermostatic Mode

Thermostatic mode allows you to set a temperature for the cooling fans to activate automatically, which can come in handy scenarios where you need as minimal cooling as possible.

You will be using the T switch for the trigger temperature – and the H switch for the heaters the printer will be monitoring.

Let’s look at a quick example:

M106 P1 T50 H1:2

In this example, P1 refers to fan number 1, T50 refers to a trigger temperature of 50 degrees, and H1:2 refers to the first and second heaters.

As a result of running this command, fan number 1 will activate as soon as heaters 1 or 2 reach a temperature of 50 degrees or greater.

The H switch is only available in RepRapFirmware and MK4duo.

Minimum and Maximum Fan Speed

The minimum and maximum fan speed parameters allow you to set boundaries for the fan speed, with 0 (or 0.0) and 255 (or 1.0) being the lowest and highest values possible.

You will be using the X switch for the maximum speed and the L switch for the minimum. As these are two separate parameters, you can choose to either use both or just one.

Let’s look at a quick example:

M106 P2 L100 X200

In this example, P2 refers to fan number 2, L100 refers to a minimum fan speed value of 100, and X200 refers to a maximum of 200.

As a result of running this command, you will only be able to set the speed of fan number 2 to a value between 100 and 200.

Minimum and maximum fan speed parameters are only available in RepRapFirmware and MK4duo.

Blip Time

The blip time parameter allows you to set a period where the selected fan will run at full speed after it starts spinning.

To activate blip time, you will need to use the B switch.

Let’s look at a quick example:

M106 P1 B0.1

In this example, P1 refers to fan number 1, and B0.1 refers to 0.1 seconds of blip time.

As a result of running this command, the fan will run at maximum speed for 0.1 seconds when it spins for the first time; and go back to its usual fan speed afterward.

The blip time parameter is only available in RepRapFirmware.

Restore Speed

The restore speed parameter allows you to restore a fan’s speed to the value it had before a pause.

To restore the speed of a fan, you will need to use the R switch.

Let’s look at an example:

M106 R1

In this example, R refers to the restore speed parameter, and 1 refers to the fan number.

As a result of running this command, fan number 1 will go back to the speed it was running at before a pause.

The restore speed parameter is only available in RepRapFirmware.

What Does the M107 G-Code Do?

The M107 (Fan Stop) G-code allows you to turn the selected fan off. If you don’t choose a fan, most firmware automatically turns fan number 0 off.

A quick example would be:

M107 P0

In this example, P0 refers to fan number 0, meaning that the fan number 0 would turn off after running this command.

In some firmware, such as RepRapFirmware and Teacup, the M107 G-code is deprecated, and as a result, you should use the command M106 S0 to turn a fan off.

Wrapping Up

Even though they are simple commands at their core, the M106 and the M107 G-codes allow you to have greater control of the cooling fans and give you the option to fine-tune them for different scenarios.

While making effective use out of the more advanced parameters can require specific circumstances, we believe these G-codes should be in every 3D printing enthusiast’s arsenal.

As we will be covering more and more G-codes in the upcoming articles, stay tuned if you have enjoyed this one!