Add variable fan speed using an Ulimaker shield & Marlin firmware

Using a fan to cool the extruded plastic helps a lot to get better prints, but having it at a fixed speed it’s not the best way at all.
A variable speed fan can be used more efficiently during different moments of the printing process: first layers, bridges, small layers…

Variable speed fan

My variable speed printing fan at work 🙂

THE PROBLEM: on my board the pin dedicated to regulate the fan speed (via pwm) gets its current from an unregulated source. The Ultimaker board uses pin 7 to control the fan speed, but this pin has not a 12v maximum tension, instead it gets it power directly from the power supply  (in my case a 18v transformator).
If I had used this feature out of the box my fan would have received a voltage of 0/18V not suitable for the popular 12v fan commonly used for this task.

POSSIBLE SOLUTION 1: Use a 24v fan, but this would also have been impractical since at 18v (maximun voltage of my transformer) the fan would have worked at a very low speed.
In fact, computer fans have a working range that’s not 0 to 100% volts since you need to kick in some power to make it turn first, for instance my fan can effectively operate in the range of 5 to 12v. Under 5v my fan doesn’t even start turning. But once it does you can lower it a little more, I will discuss it later on this post about this.

POSSIBLE SOLUTION 2: in your slicer program limit the maximum fan speed to a value safe for your fan. It works, but it’s not really practical nor intuitive and if you are using a controller (like the utilpanel, ultimaker controller ecc.) it’s not safe at all since you coul easily burn your fan using some functionality these controller provide.


Testing the pwv tension before attaching the fan.. safety first 😉

MY SOLUTION: I modified the firmware and set a parameter to define the maximum voltage suitable for my fan. Now I can safely use any slicer/controller in their full range of 0/100% fan speed. The firmware will then handle all the conversions for me.

I use a new parameter called FAN_MAX_SPEED to scale the output of the pin to the new working range (0 to FAN_MAX_SPEED). You can download the modified firmware on my github repository: or follow this simple tutorial:

Step 1:

In configuration.h, after “#define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH) //prevent extrusion of very large distances.” add this lines:
// Fan speed limit
#define FAN_SPEED_MAX 135

Step 2:

In planner.cpp, search and substitute “analogWrite fanSpeed” with:
analogWrite(FAN_PIN, map(fanSpeed, 0, 255, 0, FAN_SPEED_MAX));

Step 3:

In ultralcd.cpp, search and substitute “analogWrite fanSpeed” with:
analogWrite(FAN_PIN, map(fanSpeed, 0, 255, 0, FAN_SPEED_MAX));

Step 4:

Compile and upload the new firmware

POSSIBLE UPGRADE 1: have your board to auto adjust this new parameter. It can be made modifying the hardware to sense the “vin”, but I assume that in this case It would be easier to simply modify the pin to get it’s input from a regulated 12v.

POSSIBLE UPGRADE 2: set a new parameters called FAN_SART_SPEED and FAN_MIN_SPEED and scale the 0-100% fan speed to your FAN_MIN_SPEED and FAN_MAX_SPEED with a kistart functionality.
Assume that your fan start moving at 5v but once started it can still turn as low as 3v, then you could define FAN_MIN_SPEED 3v, FAN_SART_SPEED 5v and FAN_MAX_SPEED 12v and have the firmware to handle the 0 to 100% range speed in the 3v-12v range with a kickstart for speeds below the 5v.

Anyway I’m using this modification since 2 weeks and I just adore it. If works flawlessly and one found the right amount of “fresh air” I needed to add to my objects, I obtained better prints.. unattended 😉

Have fun!

Categories: 3D Printer, Improvements | Tags: , , , , , | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: