3 pin pc fan control via mosfet

Seems there is leakage through the 10k resistor (U5 in the schema).

I removed the BC337 completely off the board. The fan is connected using L, N and PWM. And now it’s showing the exact behaviour as I described before; slow at 100% PWM and a bit faster when at 1% PWM.

Now I don’t follow you…?
Also, are you sure you have solid common GND between 12V supply and Esp?
And even if you are sure, take your multimeter and verify it. :wink:

I’ve never used a fan on the esp8266, but reading the documentation I got a little confused.

Component Fan:
speed (Optional, int, templatable): Set the speed level of the fan. Can be a number between 1 and the maximum speed level of the fan.
1 to 100???

And in the output component, as far as I know, it uses a range from 0.0 to 1.0.

In my understanding, when you select 100% on the fan, you are sending 100 to the output and it should be 1.0.

This is the code I use to control a 12v fan using esp32 using the number component:


sensor:
  # RPM Signal from Fan
  - platform: pulse_counter
    name: Ryzen Fan RPM
    pin:
      number: GPIO26 # verde
      inverted: true
      mode:
        input: true
        pullup: true
    accuracy_decimals: 0
    id: ryzen_fan_rpm
    unit_of_measurement: 'RPM'
    update_interval: 5s
    filters:
      - multiply: 0.5
      - or:
        - throttle: 60s
        - delta: 50.0


output:
  - platform: ledc
    pin: GPIO18 # azul
    frequency: 25000 Hz
    id: pwm_output_pc

number:
  - platform: template
    name: "Ryzen Fan Speed"
    unit_of_measurement: '%'
    id: ryzen_fan_speed
    internal: false
    max_value: 100
    min_value: 25 # ^900 RPM
    restore_value: false
    initial_value: 100
    step: 1
    optimistic: true
    mode: slider
    on_value:
      then:
        - output.set_level:
            id: pwm_output_pc
            level: !lambda "return x/100;"

Maybe it helps in some way

I’m not an expert. So feel free to point that out when I’m saying something stupid :slight_smile:

I think the ground of the ESP is ok. Looks stable at 4.94v measured at the pin (5v and gnd) of the D1 Mini.

D5 (GPIO14) is between 0.4 and 3.3v, depending on the fan_speed setting. Measuring the same at the fan connector itself.
D6 (GPIO12) is at 3.3v. That’s tach, but currently not connected.

Regarding when you lost me @Karosm (my previous post). My thoughts were that the fan shouldn’t be able is spin when there is no ground connected. As I removed the BC337, the grounding has been broken. But it still does spin (but slowly). It’s not the 10K like I said before.

Could it be the 1N4007?

@walberjunior I believe ESPHome takes care of the 1-10 and 0-1 differences between the fan-component and the output-component

No issue with “stupid” questions, it’s stupid to not make questions…
I mean, measure esp ground to 12V supply ground.

I find these extremely useful for any time i need pwm and dont feel like warming up the iron and digging out components… I keep these on hand, grab 1, done!
https://www.amazon.com/Anmbest-High-Power-Adjustment-Electronic-Brightness/dp/B07NWD8W26/ref=asc_df_B07NWD8W26/?tag=hyprod-20&linkCode=df0&hvadid=693270340065&hvpos=&hvnetw=g&hvrand=10699271867239376745&hvpone=&hvptwo=&hvqmt=&hvdev=m&hvdvcmdl=&hvlocint=&hvlocphy=9016042&hvtargid=pla-728501932453&psc=1&mcid=945eb247e25e32d4a8e467ef1b46e651&gad_source=1

Ground between 12v (input pin of the Buck-converter) and the GND-pin of the ESP is about 3mV…

So you have common gnd.
Anyway if I follow you, your fan is spinning with only +12V and PWM wires connected ?

Here’s the current setup.

On the fan connector:
N=ground
L= line
T= tach (disconnected)
S=PWM

BC337 is removed (should be between de power plug and fan connector).

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