Smooth 12V fan control

Hi,
I have an ESP32 with esphome played, I want to control smoothly the NZXT 12V fan, I connected it through XY-MOS relay,


what should I write in yaml to make smooth control work either no weak, medium, strong and full speed ?
I suggest this topic PWM Fan control with ESP32 - #16 by 0rn0lf but the fan responds very poorly to the change of speed, does not go below about 50% and does not turn off.
Thank you for your help.

Translated with www.DeepL.com/Translator (free version)

Hi, what voltage are you supplying to the fan and what is the fan rated at in volts (12v)?
Also is the power supply able to drive the fan at 100% without the MOS?

What platform are you using in the YAML code?
I was using this on the exact same MOS driver without any problems:

  - platform: ledc
    pin: GPIO25
    frequency: 10000 Hz
    id: ventilation_fan_pwm

I use a 12V fan At maximum speed the fan gets 10.85V and at minimum 8.54V
My yaml below

output:
  - platform: ledc
    pin: GPIO19
    frequency: 10000 Hz
    id: ventilation_fan_pwm

fan:
  - platform: speed
    output: ventilation_fan_pwm
    name: "Basement Ventilation Fan"

I don't know if it's important, I'm using ESP32 module not ESP 8266

You’re possibly hitting a limitation on the MOS.
Looking at my MOS module, it’s using MOS D4184 device. I can see from datasheets that this has a “Low 8.5mΩ Rds(on) resistance”
If you use ohms law and the specification of around 0.2A to 0.3A for the fan to calculate the “voltage drop” over the MOS, you get:
V = I * R
0.3 * 8.5 = 2.55V.
0.2 * 8.5 = 1.7V
That means that you’ll get a drop of between 1.7V and 2.55V with a current of 200mA to 300mA to the fan. That’s roughly in-line with what you are seeing.

You might be able to obtain a better MOS with a lower Rds(on), or the other option is to drive the circuit with a higher voltage, such as 14v perhaps.

This calculation is missing important parameter: Rds resistance 8.5mohm is stated at 4.5V, not at 3.3V which is ESP’s output. At 3.3V on gate mosfet will have quite bigger resistance, while some of mosfets won’t even open at such low voltage. I bet that this is real problem here…
So, either different mosfet (logic gate model) or mosfet driver between ESP and mosfet.

Those FETs are sensitive to high voltages. I always put a diode in parallel to the switching fan (just like with a relay). Please look for the right polarity. This could also help in a better PWM performance (since the excessive energy in the coil is shorted out by this diode). So it protects the FETs and probably a better performance.

8.5mΩ is not the same as 8.5Ω

Yes, so I noticed when I re-read it. My calculation is incorrect then.