How to use 5V PWM from PIC to control 12V fan


I'm not sure if that title explains it well enough, but I have a 12V PWM PC fan which I want to drive using a 5V PIC.

The fan has 4 pins, GND, +12V, PWM and TACH. The TACH is a speed sense pulse from a Hall effect sensor, and I won't be using that.

The PWM is pulled up internally in the fan so that it will run at full speed if that pin is not connected (e.g. for motherboards that only support 3-pin fans). Therefore, to control the speed, I need to drive the fan's PWM pin from the PWM output of the PIC.

When testing with a couple of spare fans, I just applied +12V to get the fan running at full speed and then measured the voltage between the fan's PWM pin and GND. On some fans, it seems to be pulled up internally to 3.3V but on the fan I want to use, it's pulled up to 12V. (So I'm glad I measured it rather than assuming they were all the same).

According to the specifications I've found, the fan's PWM should not source more than 5mA (I measured it at only 0.68mA) but having said that the spec also says that the PWM should be pulled up to a maximum of 5.25V within the fan and I measured 12V. The fan manufacturer gives minimal information.

Can I just drive the gate of a MOSFET directly from the PIC's PWM output and connect the drain to the fan's PWM and source to common ground? Is that the "right" way to do it? Is it appropriate to use a MOSFET rather than a BJT? (I'm thinking of 2N7000, just because I have some handy).

Best Answer

You can easily use a MOSFET if the Fan specifies a weak internal pull-up and a 2N7000 fits a 12V low current application.

Whether you should worry about the fan supplying more than officially specified, is another thing. If you have shorted the pin to ground for your measurement and 0.68mA came out, that's so incredibly well within the reach of a 2N7000 that you shouldn't worry about the FET too much. You're welcome to worry about the Fan itself, if that helps you in any way, but a quick test with an arbitrary PWM signal will show if it is broken, or just built different to (EDIT:) the official prescribed spec.

All in all, I say, go for it. If you are really doubtful, you can limit some FET damage by adding a resistor in the drain path, like so:


simulate this circuit – Schematic created using CircuitLab

The 2N7000 has an absolute worst case drain-source resistance of 13.5Ohm (the one Fairchild makes, at least) and I expect in your use-case that it will not exceed 3Ohm even when hot.


Sunday made my maths go wobbly, changed the voltage drop and the conclusion to it in the following block:)

So at the very worst the resistor and the FET will share the risk, normally the resistor will catch the brunt of it. At 5mA maximum the resistor will only waste 0.05V, which is negligible, you can even increase it to 20 or 30 ohm and it should still be interpreted as low. In the worst kind of failure (PWM shorted to 12V in the fan) the 10Ohm will effectively limit the current through the FET to about 1A (if the FET also is at least 2 ohm then), which is an acceptable very short-term limit. 30Ohm would probably keep the FET fully safe until the resistor itself burns through.

9999 out of 10000 times the resistor is completely redundant and pointless. But it is an option if it helps you sleep better (2 cents for good sleep, I call a steal)