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.
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:
I’m not an expert. So feel free to point that out when I’m saying something stupid
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.
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?
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.
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…?
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.