This fellow has prepared quite a nice video performing the same temperature and PWM control of fans.
Because I’m not a practiced EE, I kept trying different configurations, but nothing worked reliably. UNTIL I read Post #12 from Railroader at the arduino forum. I did not have 1K ohm resistors, so used 1.5K ohm. Wiring exactly as suggested below, using transistor BC548 for switching, and accounting for the PWM signal inversion, my two 12VDC Noctua NF-P12 redux fans are working reliably as desired.
frequency
value is 25000 Hz
speed count
value is 1000.
Off
: The relay connecting 12VDC to the fans is switched off.
Low
: The 12VDC relay is switched on and the PWM is set to 800.
Medium
: The 12VDC relay is switched on and the PWM is set to 500.
High
: The 12VDC relay is switched on and the PWM is set to 250.
Maximum
: The 12VDC relay is switched on and the PWM is set to 1.
Railroader [Feb '21] (Using ESP to drive a computer 4pin fan - #12 by Railroader - Project Guidance - Arduino Forum) post #12
I think a common bipolar NPN transistor would work. A signal transistor, not any power one.
From controller D4 a serial resistor of some 1 kOhm to transistor Base. From +5 volt a 1 kOhm to transistor Collector. From Collector connect to fan PWM pin. Emitter connects to GND.
PWM will be reversed. PWM 255 will give 0% fan and PWM 0 will give 100%.