3 pin pc fan control via mosfet

Ok, and what’s the behavior?
Sorry for my question, but I lost you in certain point…

The issue is that the fan doesn’t completely stop spinning:

  • When fan_speed is set to 100%, the fan stops spinning, spins up, stops again, etc;
  • When fan_speed is set to 70%, the fan spins slowely but continiously;
  • When fan_speed is set to 1%, the fan runs slowely and continiously, but faster than at 70%.

Why are you running at 25000Hz? The default that works for most lights and fans is only 1000Hz. This is definitely something that can cause the type of symptoms your having right now.

Did you already start with 1000HZ and incrementally raise it that high? Or did you pull that number out of thin air?

So If I follow your earlier posts, this is when you disconnect GND from your fan??

You dont think using 25000Hz and being off the charts might have something to do with that?

You didnt answer my questions either. Where did you come up with that sky high frequency 3x too high?

Correct. With only PWM and line connected (no ground), the fan keeps running with the behavior as described before.

@Fallingaway24 I read somewhere that the default for PWM is 25Khz. Changed that back to 1000hz, but no change.

Not a nice thing. Esp pwm gpio pin is sinking some unknown current from fan.
So this is not anyhow related to transistor circuit.
Did you ever try that fan just without any external components (just esp+fan)? Do you have some documentation about fan speed control circuit? For sure it’s not optocoupler, but to understand better if it’s defective or just crap.

The fans I use are Artic F12 PWM

So digging a little deeper got me on the Arduino Forum, where they say the fan is working as designed; it should be always spinning. When ungrounded, it uses the PWM connection for ground (post 13 in that thread).

So the solution would be to put a transistor on the PWM line. However, the proposed solution is a bit out of my comfort zone…

There is another thread which discusses the same issue. If I understand correctly, they advise using a PNP-transistor to switch the 12v line, but later say this is a bad idea…

Then it’s not well designed for 3.3V control. It should use optocoupler for pwm.
Anyway, I don’t remember the reason why you wanted to cut gnd from fan in a first place…?

I didn’t :slight_smile:

I thought that was the best way to go with the BC337, and probably found an example where they did that. Don’t remember exactly.

But from my point of view, there is no preference for cutting ground instead of Line

Anyway, I wouldn’t try to switch off that pwm pin with transistor because there is possibility that tach pin is becoming ground path.
So PNP is the way to go. In addition to NPN that you already have you just need another 500ohm resistor and PNP transistor.

image

Understood. Is the BC557 the correct choice for the PNP transistor?

Something like this:

Bc557 is only ok if your fan current is below 100mA
Anyway, if you don’t have any pnp on hands and need to order, I would go with BC327 (current max 800mA).

Your circuit for pnp is not correct, remove the connection on the right side.
Also why you have 5v pullup for tach? Esp doesn’t like it.

Edit: And your diode is in short again…

Not sure if I can follow you now. But is this what you mean? Or is the grounding of the fan still incorrect?

Fixed the diode… my bad…

On the tach:
If I connect that directly to the ESP, I’m getting weird results. Fan at 60% results in 4500 RPM. While according to spec the fan cannot run faster than 1350 rpm.

I found I wasn’t the only one and followed @MrFusion 1st suggestion in this thread

In your circuit there is no ground at the moment! Or maybe there is, but not visible. So fan gnd directly to gnd, not through transistor.
For tach, you obviously pull it up to 3.3V, not 5V. Makes sense?

Yes, starting to make sense. But I am still struggling the understand how the NPN and PNP transistors are working. As I understand, the ESP switches the NPN. When the NPN is on, it switches the PNP. Is it correct that this is necessary because the ESP can’t directly switch 12v?

Here’s another overview with colored lines:

  • Brown = line
  • blue = ground
  • green = data

I rerouted the 3.3v pull-up to the 3.3v pin of the ESP. But at the same time, I am wondering why I am powering the ESP and DS18B20 over 5v. There is no reason, is there? But at the same time, this is not ‘wrong’ either?

Edit: fixed typo on the tach-line. Is indeed pullup

If you want, I can make a circuit simulation for you on falstad.com, you don’t need to create any account.
That way it’s easier to understand.

Yes, very much! Alway happy to learn!

Pullup, right?

1 Like