PC fan, 4-pin PWM
A 12 V computer case fan with the 4-pin connector: a duty cycle on PWM sets its speed and TACH pulses twice a turn.
Aliases: PC fan, computer fan, case fan, cooling fan, 4-pin PWM fan, CPU fan, 3-pin 12 V fan. It runs off its own 12 V supply, and a board only talks to its two signal wires, so it needs no transistor at all.
Pins
The connector's pins 1 to 4, with the wire colors most fans use:
| Pin | Wire | What it does |
|---|---|---|
GND |
black | Ground, shared with the board. |
+12V |
yellow | The 12 V supply. A fan draws its rated current at full speed (0.1 to 0.15 A for a 120 mm one). |
TACH |
green | Open collector: pulls low twice per revolution. It needs a pull-up, which INPUT_PULLUP on the board's pin is. |
PWM |
blue | The speed input, pulled up inside the fan. Open or high is full speed. |
Setting the speed
Intel's 4-wire fan specification asks for a 25 kHz PWM. At or under the fan's
min_duty it turns at min_rpm, and from there the speed rises in a line to
max_rpm at 100 %. A fan with stop_below set stops below that duty instead.
On an Uno, Timer1 gives 25 kHz on pin 9:
TCCR1A = (1 << COM1A1) | (1 << WGM11);
TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS10);
ICR1 = 639; // 16 MHz / 640 = 25 kHz
OCR1A = 320 - 1; // 50 %
analogWrite()'s 490 Hz works here too, because the model averages the duty
whatever the frequency. A real fan usually follows it, but its coils sing at
490 Hz and some controllers misread it, so 25 kHz is the right way.
Reading the speed
Count falling edges on TACH with attachInterrupt() for a second: rpm is the
count times 30. The open collector is pulled to whatever the board's pull-up is,
so it is safe on a 3.3 V board too.
Models
| Model | Speed | Floor | At 0 % | Current |
|---|---|---|---|---|
custom (a generic 120 mm fan) |
1800 rpm | 600 rpm at 30 % | 600 rpm | 0.15 A |
Noctua NF-A12x25 PWM |
2000 rpm | 450 rpm at 20 % | stops | 0.14 A |
Arctic P12 PWM PST |
1800 rpm | 200 rpm at 5 % | stops under 5 % | 0.1 A |
3-pin 12V DC fan |
2000 rpm at 12 V | none | no PWM pin | 0.1 A |
The three-pin fan (wires 3) has no PWM input: its speed follows its supply
instead, in proportion to 12 V. Switching its ground with a MOSFET and PWM
slows it, and the model averages that, but its tachometer only reads while the
ground is connected.
Properties
| Property | What it sets |
|---|---|
max_rpm, min_rpm |
Top speed, and the floor speed at low duty. |
min_duty |
The duty, in percent, at and under which it turns at min_rpm. |
stop_below |
Under this duty, in percent, it stops. 0 never stops. |
current |
The current at full speed, in amps. |
inertia |
How slowly the rotor follows a change, 1500 ms. |
wires |
4 for a PWM fan, 3 for a plain DC fan. |
While it runs
The rotor turns and the readout shows the speed in rpm.
What the model gets right
Open is full speed. Nothing on PWM runs it flat out, as the spec requires.
Two pulses a turn. 1800 rpm is 60 pulses a second on TACH.
The starting voltage. Under 7 V across it, the figure 12 V fan datasheets print, it does not turn.
What it does not model
The PWM frequency (any frequency is averaged), the noise, the air, the start-up
surge, and the exact current curve: the draw is 15 % of current for the
electronics plus the rest times the speed cubed, an approximation.
Common mistakes
Reading TACH with no pull-up: the pin floats and the count is noise.
Feeding the fan's 12 V into a board pin. Only PWM and TACH go to the board.
See it in action
PC fan speed and tachometer steps the duty and reads the rpm back. Open it at /templates.