# How can I add an extra fan, controlled by a microcontroller, to my board?

I recently discovered this kit after reading this Instructables, Adding More Extruders to Any 3d Printer:

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:

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.

• 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 Jul 7 '19 at 18:20
• I could use the LCD pins somehow? – K Mmmm Jul 7 '19 at 18:21
• I was wrong, you'll just need custom firmware. Your wiring diagram is wrong though. – Trish Jul 7 '19 at 18:28
• 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 Jul 8 '19 at 10:34
• 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 Jul 8 '19 at 15:41

The MKS Gen L v1.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.

## 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. Due to how it is set up, one could run both part cooling fans, if their speed is set up to be always equal.

• WOW I missed that open one. Thank you!!! What circuit hardware would I need to extend this port into two controllable ports? – K Mmmm Jul 7 '19 at 18:30
• 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). – 0scar Jul 8 '19 at 12:23
• @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 Jul 8 '19 at 17:26

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.

• 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 Jul 8 '19 at 10:27
• 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 Jul 8 '19 at 14:44
• But when I use the L298N module, I will also need to buy external MOFSETS? I can research this part separately. – K Mmmm Jul 8 '19 at 14:44
• 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 Jul 8 '19 at 14:48