Smoothieware Switch Module for Automatic Fan Control

Introduction: Smoothieware Switch Module for Automatic Fan Control

About: I'm blogging about my projects before they make it to Once I've finished a subject on my blog, I'll put it together and post it on Instructables, so you can get a preview on my site.

This is a follow up to my Instructable about Configuring MKS Sbase v1.2 32-bit Controller basics and intro to Smoothieware.

As the previous one, this is using Sbase but it Works equally fine on the original Smoothieboard.

This time I am going to take a look at one of the advanced interesting features, which will allow us to control fans based on a temperature of our choosing.

The fan cooling the heatsink on the hotend fan can be rather loud, and there is no need for it to be active unless the hotend is in use. To do something about this we are going to use the temperatureswitch module, which have a few options, to turn the fan on when the hotend reaches 50c and off again, when the temperature drops below 50c.

The 15th of may I just added a deal of notes regarding using switches and M-codes. In case you want to reread it :)

  1. Configuring Switch for HOTEND HEATSINK fan
  2. Configuring Temperatureswitch to control hotendheatsinkfan

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Configuring Switch for HOTEND HEATSINK Fan

We start by creating a standard switch which have a lot of options we can use.

I am defining the name a hotendheatsinkfan as this switch is going to manage the fan on our hotend heatsink.

All options are prepended with switch.hotendheatsinkfan which denotes it is a switch and the name of the switch.

  1. We make a new section a headline descriptive name of our switch, in this case Switch for HOTEND HEATSINK fan. I use caps to be able to spot it easily in my config.txt file.
  2. We use .enable true to enable the switch.
  3. I have setup, but commented out the .input_on_command, .input_off_command and .subcode for our switch.
    1. They are commented out, as Smoothieware is currently in need of a planned update to fix a few bugs related to the switches.
      Note. For general usage it makes no different wheter you have them uncommented or not. The firmware does not use the M-codes to control the fan.
    2. The commands are used to manually turn the fan on and off, where the subcode specifies the specific object assigned to a switch, in this case a fan, we want to control, in case we have more of them.
    3. Example: M106.2 toturn it on and M107.2 to turn it off. If I had an additional switch with subcode 3, I would control it using M106.3 and M107.3
    4. Note: when using MKS TFT displays you do not want to add a subcode to FAN, which is the one cooling your printed objects, as you are going to be unable to control it from the display. You can still use subcodes for other fans.
      Do not add on and off _command to several switches without using subcodes, unless you want all of them to be turned on and off with the same command.
  4. The .output_pin defines the pin our fan is attached to. In this case we use 2.6 which is the Heater2 terminals.
  5. The .output_type is either pwm or digital. PWM can be setup with power from 0-100% defined by 0-255 where digital is on or off.
  6. The .max_pwm setting defines maximum output to our fan. Mine is rather loud and cool just fine at speed 200.
    1. You don't want to set this too low as you risk heatcreep up the hotend where the filament gets soft and clogs up the hotend.
  7. The .fail_safe_set_to defines what to do in case our printer goes into Crash or HALT mode (maybe some other failture mode as well). I have set it to 1 which Means the fan will keep up spinning if the the printer encounters problems.
    1. I don't want the hotend heatsink fan to stop working in case I have a case of overheating!

# Switch for HOTEND HEATSINK fan
switch.hotendheatsinkfan.enable                true   # true/false
# switch.hotendheatsinkfan.input_on_command    M106   #
# switch.hotendheatsinkfan.input_off_command   M107   #
# switch.hotendheatsinkfan.subcode                2   #
switch.hotendheatsinkfan.output_pin             2.6   # Heater2
switch.hotendheatsinkfan.output_type            pwm   # digital would be on/off
switch.hotendheatsinkfan.max_pwm                200   # default is 255
switch.hotendheatsinkfan.fail_safe_set_to         1   # CRASH or HALT. 0 or 1

Step 2: Configuring Temperatureswitch to Control Hotendheatsinkfan

We have now setup a switch which gives us, and the controller, access to turn the hotendheatsink fan on and off and we are now going to setup a temperatureswitch to do just that depending on a readout of a temperature designator, which is the letter T for our hotend in this case.

All options are prepended with temperatureswitch.hotend which denotes it is a temperatureswitch and the name of the temperatureswitch (hotend).

  1. First write a descriptive headline and comment it out: # Toggle the switch hotendheatsink on/off at 50c
  2. We use .enable true to enable the switch
  3. The .designator is used to designate which temperature_controlmodule we are going to monitor. We want to monitor our hotend, which is deginated with the letter T as default.
    1. As it is now you must not use anything else than a single letter, and it is not recommend changing the letter T. I hope this will change in later firmware updates.
  4. Now we define which .switch is used when conditions are met. We set it as our hotendheatsinkswitch.
  5. The .threshold_temp is the temperature at which point the the above is set into motion. We set it at 50c which is a good setting for our hotend.
  6. .heatup_poll defines how often the controller checks the temperature on heating up. The default i 15 seconds, but my hotends can get very hot in 15 seconds, so I've set it at 3 seconds instead.
  7. .cooldow_poll defines how oten the controller checks the temperature on cooldown. 30 seconds is default, but I'd rather have my fan to be quiet as fast as reasonable possible, so I've set it at 3 seconds.
# Toggle the switch hotendheatsink on/off at 50c
temperatureswitch.hotend.enable        true #
temperatureswitch.hotend.designator    T    # From: temperature_control.hotend.designator
temperatureswitch.hotend.switch        hotendheatsink  # Select which switch to use.
temperatureswitch.hotend.threshold_temp   50.0 # Temperature to turn on/off
temperatureswitch.hotend.heatup_poll      3    # Default is 15 - Poll heatup
temperatureswitch.hotend.cooldown_poll    3    # Default is 30 - Poll cooldown

Be the First to Share


    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge
    • First Time Author Contest

      First Time Author Contest
    • Space Challenge

      Space Challenge

    8 Discussions


    2 years ago

    Your instructables are indispensable!!! Really excellent work...just starting to get my head around smoothie and it really is a great firmware. I had the same question for the 30x30 hotend Ill use TH4 with the above. Cheers


    Reply 2 years ago

    Hey, did you manage to get the 30mmX30mm fan going with that? I'm trying to find a way to set up the E3D V6 hotend heatsink fan and can't seem to get the switch to work with TH4 (0.26) but I can with 2.4 for the other fan. I'm reluctant to put the 5V hotend heatsink fan on the 2.5 pin output because I'm scared that it'll draw 12V and annihilate the thing. Any help would be infinitely great!


    Reply 2 years ago

    Hello Reuben.
    E3Dv6 does not use a 5v heatsink fan. It comes with 12v for 12v set and 24v for 24v set. I used the TH4 just fine.
    One thing I noticed on E3Dv6 heatsink fans is that I've had issues running them at lower than 100%. I fixed it on Duet controller by raising frequency to over 5k.


    Reply 2 years ago

    I have a couple of printers...cant remember which one but I tested both th4 and fan 2, they both worked. I simply plugged in the fan jts connector, assigned the pin in firmware and away it went. I think one of the smoothie boards needed to have the logic inverted ie z sensor was showing on when it was actually off...just follow the instructions at and use the ^ symbol. HTH


    3 years ago

    I think there is a slight mistake in the config switch:

    temperatureswitch.hotend.switch hotendheatsink <--- should be hotendheatsinkfan


    Reply 3 years ago

    without that, you get the error "// Failed to get switch state."


    3 years ago

    How much current can TH4 deliver and which voltage range is supported? I have only 24V fans and don't want to fry my board and / or have my fans running too slow (would like to control two fans simultanously over that pin)

    Thank you very much for your instructions! They helped me a lot already.


    Reply 3 years ago

    I guess you know the board can handle 12-24v? It means it can output the same voltage as you provide as input.

    I do not know max current of any output. Talking 40x40 fans or similar, you do not have to worry about it though.

    You can ask the manufacturer if you really want to know :)