Is that the complete YAML for the node?
I ordered NPN transistor BC548. As I understand, any NPN transistor that switches on with a base voltage of 3v3 should work. (I mentioned BC548 in my post above.)
No, it does not include the first several segments necessary for ESPHome. These are typically unique to each individualās environment/configuration.
esphome:
name: computer-rack-fans
esp8266:
board: d1_mini
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
password: !secret api_password
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
i2c:
scl: D1
sda: D2
scan: true
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%.
The āreversalā of the PWMās effect is because the fanās PWM control line is pulled-down, so if the wire is left dangling, the fan will run at full speed. Pull it to 5V to stop.
(Or, maybe itās exactly the other way 'round. Either way, itās so that a disconnected control line will cause the fan to run, not stop.)