Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (2024)

While setting the fan speed is a task that the slicer software you’re using will handle through the G-code file it produces, there can be cases where it becomes necessary to manually adjust how quickly the fan runs, usually for testing purposes.

In this guide, we will take you through the functionality and the usage of the M106 and M107 G-code commands in Marlin firmware, which are the two commands responsible for adjusting the state of the cooling fans of your 3D printer.

Table of Contents

What Is the M106 (Set Fan Speed) G-Code Command in Marlin Firmware?

The M106 G-code command in Marlin Firmware allows you to activate the cooling fan of your choice based on its index (based on the pin it’s connected to) and offers you a few different ways to set the speed of a fan based on your 3D printer’s firmware configuration.

When using this command, one thing, in particular, to pay attention to is that speed values range from 0 to 255, where a value of 0 would provide a fan speed of 0%, and a value of 255 would bring the fan speed all the way up to 100%.

To convert a percentage fan speed value to an S value, which you will require for using the M106 G-code command, you can multiply the percentage value of your choice with 2.55 and round the result.

As an example, if you would like to find out which value you will need to use for a percentage fan speed of 65%, the operation you will need to perform is 65 * 2.55, which will give you 165.75, and when you round this value up, you will find 166.

With this in mind, to set the fan speed value with the M106 G-code command in Marlin, what you will need to do is pass the S parameter together with the speed value of your choice (don’t forget that it goes up to 255!), and the P parameter with the index of the fan you would like to apply the modification to, which will get the job done.

As an example, if you would like to set the first fan (which would have an index of 0) to 50%, you would need to send the command M106 P0 S128 through the G-code terminal, with the value 128 (out of 255) corresponding to 50%.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (1)


While you do need the S and P parameters to get M106 to work as intended, both of these parameters are technically optional, as leaving the P parameter out will lead to the firmware automatically selecting the print cooling fan, and leaving the S parameter out will get the firmware to set the fan to full speed, which are some handy shortcuts to keep in mind if you find yourself manually controlling the fan frequently for testing purposes.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (2)


Additionally, if you have used the M145 G-code command to save material presets on your 3D printer, where you can store fan speed, bed temperature, and hotend temperature values for different types of filaments to make the pre-heating process more convenient, you can also opt to utilize the I parameter together with the material preset index instead of the S parameter, which will load the fan speed value from the preset.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (3)


Finally, if the EXTRA_FAN_SPEED parameter is defined in the Configuration_adv.h file for the firmware you’re using, one last parameter you can use with M106 is T, which allows you to set a secondary speed for the purposes of alternating between two fan speeds conveniently.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (4)


To set a secondary speed for the fan of your choice, you will need to use the syntax T3-<fan_speed>, once again, along with the index of the fan you will be setting the speed for, such as M106 P0 T3-128 to set a secondary speed of 50% for the first fan on your 3D printer.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (5)


To use this secondary fan speed, the parameter you will need to use is T2, such as M106 P0 T2 for activating the secondary fan speed for the first fan of your 3D printer, which, following the example from earlier, will bring the fan speed to 50% as we have set with T3.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (6)


Finally, to revert to the original fan speed that was in use before switching to the secondary fan speed with T2, you will need to use the T1 parameter instead, such as M106 P0 T1, which will restore the fan speed for the first fan of your 3D printer.

What Is the M107 (Fan Off) G-Code Command in Marlin Firmware?

The M107 G-code command in Marlin Firmware allows you to turn off the cooling fan of your choice, once again, based on its index.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (7)


While it’s technically possible to achieve the same effect with the M106 G-code command, as you can pass a value of 0 to the S parameter to set the fan speed value to 0%, which would effectively mean that the fan is off, the M107 G-code command offers an alternative way to turn a fan off, which can come in handy at times.

To use the M107 G-code command to turn a fan off on your 3D printer, all you will need to do is to pass the P parameter along with the index of the fan that you would like to turn off, such as sending the M107 P0 command to your 3D printer for the purposes of shutting the first fan down.

That said, as the P parameter is optional when using the M107 G-code command, it’s also worth mentioning that running the command alone without any parameters will result in the firmware automatically shutting the print cooling fan down, which is something to keep in mind regarding the behavior of this command.

Conclusion

The M106 and M107 G-code commands make it possible to control any of the fans on your 3D printer, whether turning them on and off or setting their speed to the value of your choice.

While it’s technically possible to also perform these tasks through the LCD controller of your 3D printer, using the G-code commands instead can come in handy in scenarios where it would be less convenient to interact with the 3D printer, such as when it’s further away from your desk.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (8)

David Taylor

As a software developer by profession, David has been particularly interested in how 3D printing works even before he picked up his first 3D printer, and completely fell in love with the hobby once he got his hands on a Prusa i3 MK2 for the first time back in 2017. Due to him enjoying both the functional and the non-functional sides of 3D printing equally, you’ll rarely see David’s 3D printer in an idle state.

Marlin Firmware M106 / M107 G-Code Commands Explained - 3D Print Gorilla (2024)
Top Articles
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 6320

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.