<p>You can use the <code>M42</code> g-code to manually set any supported digital pin, which can then be used to either enable one of the on-board MOSFETs (D7, D8, D9, D10) or an external MOSFET.
For example, <code>M42 P9 S255</code> would enable the parts cooling fan at 100&nbsp;%.</p>

<p>You should never run any fan or heater directly off of a microcontroller pin (the ATmega2560 on your board supports up to <strong>40&nbsp;mA</strong>. Standard 5&nbsp;V fans I found online tend to draw <strong>100&nbsp;mA</strong> or more).</p>

<p>Your board supports up to four switchable "power" outputs - bed, heater 0, heater 1 and FAN.
Depending on what you use so far, one of those may be usable for your fans.</p>

<p>Note that on-board MOSFETs usually switch the ground side of the connected device.
This means that you for your 12&nbsp;V fan, you can connect it directly to one of those connectors.
The 5&nbsp;V would have to receive +5&nbsp;V from elsewhere (like the +5&nbsp;V pins near the bottom right mounting hole), but you can still control the fan by connecting its ground lead over one of the on-board MOSFETs.</p>

<p>If four MOSFETs are not enough for you, the L298N module provides an easy way to control four additional fans, while using normal digital pins to control the L298N.</p>

CC BY-SA 4.0
2019-07-08T10:27:19.227Z
Please note that it is not advised to run a fan from a digital pin directly, the current can be too much for the microprocessor, instead connect the pin to a (external) MOSFET to schedule either a 12 V or 5 V load.
0scar
CC BY-SA 4.0
2019-07-08T14:44:28.933Z
Thanks. Just to summarize so that I have it clear. I can connect a 12V fan to the "FAN" pin (D9). That's something I can do today, because it is one of the four "power" outputs.
K Mmmm
CC BY-SA 4.0
2019-07-08T14:44:55.700Z
But when I use the L298N module, I will also need to buy external MOFSETS? I can research this part separately.
K Mmmm
CC BY-SA 4.0
2019-07-08T14:48:52.743Z
Correct, you can connect a 12V fan to D9 / the fan connector and control it via firmware / g-code.
The L298N essentially *is* a module with four external MOSFETs in it. It's suitable for driving one stepper motor, two DC motors (in either direction) or four "single direction" loads such as fans.
towe
CC BY-SA 4.0
2019-07-08T10:01:05.473Z
2019-07-08T11:27:15.323Z
2019-07-08T11:27:15.323Z
towe
<p>The <a href="http://www.robotrebels.org/index.php?topic=769.0" rel="nofollow noreferrer">MKS Gen L v1.0</a> Board you are using does support microcontroller controlled fans without doing some surface level modification to the board via the <code>D9/FAN</code>. The port you marked FAN is not a controllable port, it runs a direct 12/24&nbsp;V all the time and should be used for the Hotend cooling solution. The ports <code>D7/HE1</code> and <code>D10/HE0</code> are for two hotendes, corresponding to <code>E0</code> and <code>E1</code>.</p>

<p><a href="https://i.sstatic.net/YlGDW.png" rel="nofollow noreferrer" title="MKS Gen L port/pin layout"><img src="https://i.sstatic.net/YlGDW.png" alt="MKS Gen L port/pin layout" title="MKS Gen L port/pin layout"></a></p>

<h2>Variant A: Swappy Fans</h2>

<p>This is the more tricky variant and does need both coding and wiring expertise.</p>

<p>You'll have to run both hotend cooling fans via that one port in the top left corner. Make sure they are running fast enough to keep the heatsinks cool and prevent heat creep!</p>

<p>Your <strong>custom</strong> Firmware will have to define <code>D9</code> as a microcontroller controlled Fan instead of a 100&nbsp;% running fan as the normal firmware is most likely.</p>

<p>Without extra hardware, you can't get 2 individually controllable ports from <code>D9</code>, but you can use, the fact that you don't want part cooling for a hotends in 'resting' position. So a pair of couple Normally Closed switches cab achieve disabling of the resting hotend's part cooling fan:</p>

<ul>
<li>make a wire splitter for D9, so that you have both <code>+</code> and both <code>-</code>-wires connect to the one <code>+</code>/<code>-</code>-pin on the board. You'll have the part cooling fans in parallel now. 

<ul>
<li>Do the same for the Hotend Cooling Fans!</li>
</ul></li>
<li>connect each <code>+</code>-line to a Normally Closed switch, which is installed on the hotend in a way so it triggers and opens the line if the hotend is in the resting (homing) position.</li>
<li>As the line connects when the hotend moves into the build volume, the part cooling fan on the currently active hotend starts to spin while the one of the non-active hotend is isolated.</li>
</ul>

<h2>Variant B: MOSFETs and Safety</h2>

<p>An alternate source for the part cooling fan signals might be the SERVOS1/SERVOS2 group, where <code>D4</code> to <code>D6</code> and <code>D11</code> are accessible. This leaves the FAN and top-left 12 V pinnings free for the hotend cooling. The downside is, that these pins don't likely provide 12 V but at best a 5 V digital output. However, a 0 to 5 V signal can be used to control a separate MOSFET which outputs 0 to 12 V, which then can power the part cooling fans. Due to the power draw of the Fans, a simple step-up converter is not a solution it needs a separate power supply.</p>

<p>The Main benefit is, that this does draw less power from the board than Variant A and does not re-pin <code>D9</code>. The "Cooling Fan Board" could use a 6-line ribbon cable to connect to the <code>SERVOS1</code> pins, using the 5V as reference for the MOSFETs, <code>D4</code>/<code>D5</code> as the trigger signal and GND as return lines.</p>

<p>A pre-assembled board that could serve in this position would be a <a href="https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/" rel="nofollow noreferrer">L298N Driver</a>. Due to how it is set up, one could run both part cooling fans, if their speed is set up to be always equal.</p>

CC BY-SA 4.0
2019-07-07T18:30:53.867Z
WOW I missed that open one. Thank you!!! What circuit hardware would I need to extend this port into two controllable ports?
K Mmmm
CC BY-SA 4.0
2019-07-08T12:23:52.413Z
For your information, the MKS GEN L is basically a RAMPS board as the pin layout of the RAMPS configuration is used in the firmware of the MKS GEN L (see e.g. the [Marlin source code](https://github.com/MarlinFirmware/Marlin/blob/bugfix-1.1.x/Marlin/pins_MKS_GEN_L.h)).
0scar
CC BY-SA 4.0
2019-07-08T17:26:50.600Z
@KMmmm I am far better on the hardware side... The Code snippet linked by 0scar uses the pins in `AUX1`. The 5V fans spin slowly because the board only provides a very low current of the right voltage but the fans need considerably more.
Trish
CC BY-SA 4.0
2019-07-07T18:17:45.037Z
2019-07-08T16:45:58.840Z
2019-07-08T16:45:58.840Z
Trish
<p>I recently discovered this kit after reading this Instructables, <a href="https://www.instructables.com/id/Adding-More-Extruders-to-Any-3d-Printer/" rel="nofollow noreferrer">Adding More Extruders to Any 3d Printer</a>: </p>

<blockquote>
  <p><a href="https://i.sstatic.net/Lq4uQ.png" rel="nofollow noreferrer" title="New CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino"><img src="https://i.sstatic.net/Lq4uQ.png" alt="CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino" title="New CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino"></a></p>
</blockquote>

<p>I'm pretty sure I can use this kit with my board since it uses the same drivers as mine. But that's for motors, not fans. And while I know G-code pretty well, I'm not sure how I would use this to activate and deactivate a fan from G-code. There is probably a better way to do this.</p>

<p>The board I am using is from an FLSUN Large Scale 3D printer. Here is a picture of the board: </p>

<p><a href="https://i.sstatic.net/Bq8w1.jpg" rel="nofollow noreferrer" title="FLSUN printer board"><img src="https://i.sstatic.net/Bq8w1.jpg" alt="FLSUN printer board" title="FLSUN printer board"></a></p>

<p>There appears to be only one labeled pin for the fan. BUT even if there are other pins that I don't recognize, they would have to be controlled by a micro controller (G-code commands). There appear to be a bunch of un-used pins in the bottom right of the board. But if this board just can't do it, there is a newer board here: [link removed]. </p>

<p>It does seem like it is using Arduino and the newer board might have extra pins for a fan. But at that point, would it be easier (cheaper) to just control the fan from the extruder extender kit? Would I just set it as an extruder with a really high filament extrusion speed and send appropriate G-code commands when needed to run it at max voltage?</p>

<p>I know on my Lulzbot Mini there is a "parts cooling" fan which allows you to cool off the layers as your structure rises vertically. This is a fan I want. The parts cooling fan <em>must</em> be controlled by the micro controller. It only comes on when printing vertically.</p>

<p>I would like to actually add two fans like this to my 3D printer. One of them is a >= 5&nbsp;V cooling fan like above. Another is a regular 12&nbsp;V cooling fan for an extra extruder that I am adding.</p>

CC BY-SA 4.0
2019-07-07T18:20:09.587Z
Am I even able to use two motors at once? Assuming I was able to control a fan from the extruder extender... Would I be able to run the fan, and keep printing, then turn off  the fan later?
K Mmmm
CC BY-SA 4.0
2019-07-07T18:21:58.943Z
I could use the LCD pins somehow?
K Mmmm
CC BY-SA 4.0
2019-07-07T18:28:56.833Z
I was wrong, you'll just need custom firmware. Your wiring diagram is wrong though.
Trish
CC BY-SA 4.0
2019-07-08T10:34:45.177Z
Adding fans has been discussed in other questions, why does it specifically need to be through an additional microcontroller as it can be done by your current board/microcontroller.
0scar
CC BY-SA 4.0
2019-07-08T14:32:31.990Z
@Oscar I can control it by the same microcontroller, there doesn't need to be an additional microcontroller. The problem with this question was that I didn't notice there was even a pin for a microcontrollable fan! It wasn't labeled in the assembly manual and was off in the distance.
K Mmmm
CC BY-SA 4.0
2019-07-08T15:11:51.753Z
Ok, Steve, thanks for the update. I have added an image of the product rather than a link, as it is more appropriate. Now, regarding the second link, apparently it sets off virus warnings. @0scar noticed them this morning
Greenonline
CC BY-SA 4.0
2019-07-08T15:41:19.477Z
Note: With the firmware it is shipped, the FAN port is 100% all the time. you need to re-pin the software, but you have lots of other free pins that could be programmed for though
Trish
<prusa-i3>
How can I add an extra fan, controlled by a microcontroller, to my board?
K Mmmm
# How can I add an extra fan, controlled by a microcontroller, to my board?

(Asked by: username_0 on 2019-07-07)

I recently discovered this kit after reading this Instructables, [Adding More Extruders to Any 3d Printer](https://www.instructables.com/id/Adding-More-Extruders-to-Any-3d-Printer/):

> [![CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino](https://i.sstatic.net/Lq4uQ.png "New CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino")](https://i.sstatic.net/Lq4uQ.png "New CNC Shield v3 engraving machine / 3D Printer / + 4pcs A4988/DRV8825/AT2100 Driver Expansion Board for Arduino")

I'm pretty sure I can use this kit with my board since it uses the same drivers as mine. But that's for motors, not fans. And while I know G-code pretty well, I'm not sure how I would use this to activate and deactivate a fan from G-code. There is probably a better way to do this.

The board I am using is from an FLSUN Large Scale 3D printer. Here is a picture of the board:

[![FLSUN printer board](https://i.sstatic.net/Bq8w1.jpg "FLSUN printer board")](https://i.sstatic.net/Bq8w1.jpg "FLSUN printer board")

There appears to be only one labeled pin for the fan. BUT even if there are other pins that I don't recognize, they would have to be controlled by a micro controller (G-code commands). There appear to be a bunch of un-used pins in the bottom right of the board. But if this board just can't do it, there is a newer board here: [link removed].

It does seem like it is using Arduino and the newer board might have extra pins for a fan. But at that point, would it be easier (cheaper) to just control the fan from the extruder extender kit? Would I just set it as an extruder with a really high filament extrusion speed and send appropriate G-code commands when needed to run it at max voltage?

I know on my Lulzbot Mini there is a "parts cooling" fan which allows you to cool off the layers as your structure rises vertically. This is a fan I want. The parts cooling fan *must* be controlled by the micro controller. It only comes on when printing vertically.

I would like to actually add two fans like this to my 3D printer. One of them is a >= 5 V cooling fan like above. Another is a regular 12 V cooling fan for an extra extruder that I am adding.

**Tags:** prusa-i3

> **Comments:**
> **username_0**: Am I even able to use two motors at once? Assuming I was able to control a fan from the extruder extender... Would I be able to run the fan, and keep printing, then turn off  the fan later?  
> **username_0**: I could use the LCD pins somehow?  
> **username_1**: I was wrong, you'll just need custom firmware. Your wiring diagram is wrong though.  
> **username_2**: Adding fans has been discussed in other questions, why does it specifically need to be through an additional microcontroller as it can be done by your current board/microcontroller.  
> **username_0**: @Oscar I can control it by the same microcontroller, there doesn't need to be an additional microcontroller. The problem with this question was that I didn't notice there was even a pin for a microcontrollable fan! It wasn't labeled in the assembly manual and was off in the distance.  
> **username_3**: Ok, Steve, thanks for the update. I have added an image of the product rather than a link, as it is more appropriate. Now, regarding the second link, apparently it sets off virus warnings. @username_2 noticed them this morning  
> **username_1**: Note: With the firmware it is shipped, the FAN port is 100% all the time. you need to re-pin the software, but you have lots of other free pins that could be programmed for though  

---

## 2 answers

### Answer by username_1 on 2019-07-07. Score: 4 | Accepted answer

The [MKS Gen L v1.0](http://www.robotrebels.org/index.php?topic=769.0) Board you are using does support microcontroller controlled fans without doing some surface level modification to the board via the `D9/FAN`. The port you marked FAN is not a controllable port, it runs a direct 12/24 V all the time and should be used for the Hotend cooling solution. The ports `D7/HE1` and `D10/HE0` are for two hotendes, corresponding to `E0` and `E1`.

[![MKS Gen L port/pin layout](https://i.sstatic.net/YlGDW.png "MKS Gen L port/pin layout")](https://i.sstatic.net/YlGDW.png "MKS Gen L port/pin layout")

## Variant A: Swappy Fans

This is the more tricky variant and does need both coding and wiring expertise.

You'll have to run both hotend cooling fans via that one port in the top left corner. Make sure they are running fast enough to keep the heatsinks cool and prevent heat creep!

Your **custom** Firmware will have to define `D9` as a microcontroller controlled Fan instead of a 100 % running fan as the normal firmware is most likely.

Without extra hardware, you can't get 2 individually controllable ports from `D9`, but you can use, the fact that you don't want part cooling for a hotends in 'resting' position. So a pair of couple Normally Closed switches cab achieve disabling of the resting hotend's part cooling fan:

* make a wire splitter for D9, so that you have both `+` and both `-`-wires connect to the one `+`/`-`-pin on the board. You'll have the part cooling fans in parallel now.
  + Do the same for the Hotend Cooling Fans!
* connect each `+`-line to a Normally Closed switch, which is installed on the hotend in a way so it triggers and opens the line if the hotend is in the resting (homing) position.
* As the line connects when the hotend moves into the build volume, the part cooling fan on the currently active hotend starts to spin while the one of the non-active hotend is isolated.

## Variant B: MOSFETs and Safety

An alternate source for the part cooling fan signals might be the SERVOS1/SERVOS2 group, where `D4` to `D6` and `D11` are accessible. This leaves the FAN and top-left 12 V pinnings free for the hotend cooling. The downside is, that these pins don't likely provide 12 V but at best a 5 V digital output. However, a 0 to 5 V signal can be used to control a separate MOSFET which outputs 0 to 12 V, which then can power the part cooling fans. Due to the power draw of the Fans, a simple step-up converter is not a solution it needs a separate power supply.

The Main benefit is, that this does draw less power from the board than Variant A and does not re-pin `D9`. The "Cooling Fan Board" could use a 6-line ribbon cable to connect to the `SERVOS1` pins, using the 5V as reference for the MOSFETs, `D4`/`D5` as the trigger signal and GND as return lines.

A pre-assembled board that could serve in this position would be a [L298N Driver](https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/). Due to how it is set up, one could run both part cooling fans, if their speed is set up to be always equal.

> **Comments:**
> **username_0**: WOW I missed that open one. Thank you!!! What circuit hardware would I need to extend this port into two controllable ports?  
> **username_2**: For your information, the MKS GEN L is basically a RAMPS board as the pin layout of the RAMPS configuration is used in the firmware of the MKS GEN L (see e.g. the [Marlin source code](https://github.com/MarlinFirmware/Marlin/blob/bugfix-1.1.x/Marlin/pins_MKS_GEN_L.h)).  
> **username_1**: @username_0 I am far better on the hardware side... The Code snippet linked by username_2 uses the pins in `AUX1`. The 5V fans spin slowly because the board only provides a very low current of the right voltage but the fans need considerably more.  

---

### Answer by username_4 on 2019-07-08. Score: 2

You can use the `M42` g-code to manually set any supported digital pin, which can then be used to either enable one of the on-board MOSFETs (D7, D8, D9, D10) or an external MOSFET.
For example, `M42 P9 S255` would enable the parts cooling fan at 100 %.

You should never run any fan or heater directly off of a microcontroller pin (the ATmega2560 on your board supports up to **40 mA**. Standard 5 V fans I found online tend to draw **100 mA** or more).

Your board supports up to four switchable "power" outputs - bed, heater 0, heater 1 and FAN.
Depending on what you use so far, one of those may be usable for your fans.

Note that on-board MOSFETs usually switch the ground side of the connected device.
This means that you for your 12 V fan, you can connect it directly to one of those connectors.
The 5 V would have to receive +5 V from elsewhere (like the +5 V pins near the bottom right mounting hole), but you can still control the fan by connecting its ground lead over one of the on-board MOSFETs.

If four MOSFETs are not enough for you, the L298N module provides an easy way to control four additional fans, while using normal digital pins to control the L298N.

> **Comments:**
> **username_2**: Please note that it is not advised to run a fan from a digital pin directly, the current can be too much for the microprocessor, instead connect the pin to a (external) MOSFET to schedule either a 12 V or 5 V load.  
> **username_0**: Thanks. Just to summarize so that I have it clear. I can connect a 12V fan to the "FAN" pin (D9). That's something I can do today, because it is one of the four "power" outputs.  
> **username_0**: But when I use the L298N module, I will also need to buy external MOFSETS? I can research this part separately.  
> **username_4**: Correct, you can connect a 12V fan to D9 / the fan connector and control it via firmware / g-code. The L298N essentially *is* a module with four external MOSFETs in it. It's suitable for driving one stepper motor, two DC motors (in either direction) or four "single direction" loads such as fans.  

---

