Counting a fan’s tachometer pulses is a useful introduction to measuring a rotating machine without attaching anything to its shaft. The important first step is identifying the electrical signal. A fan power wire, speed-control input and speed-reporting output do three different jobs, even when they share one connector.

Use a documented four-wire fan
This circuit specifies the Noctua NF-A4x10 5V PWM. The similar-looking 12 V and 24 V versions need different motor supplies; the name’s 5V suffix is part of the design. PWM means pulse-width modulation, a control method that varies how long a repetitive signal is high. We leave that input disconnected and measure the resulting rotation; the project is a tachometer, not a closed-loop speed controller.
Noctua documents two tachometer cycles per revolution and an open-collector output. Open collector means a transistor pulls the signal low or releases it; an external pullup establishes the high level. This lets the motor use 5 V while the signal pullup uses Pico’s 3.3 V. It does not make an unknown fan’s output automatically compatible with a Pico.
Parts and equipment
- Noctua NF-A4x10 5V PWM, specifically the 5 V four-wire version; original Pico RP2040 with MicroPython 1.26.0.
- Regulated 5 V fan supply rated at least 0.5 A, a 10 kΩ resistor, suitable connector breakout, short wires and secure fan mounting with guard. Pico powered separately by USB.
Every connection
| Pin or part | Connection and purpose |
|---|---|
| Fan motor supply | Fan pin 1 black → external supply ground; pin 2 yellow → external +5 V. Do not power the motor from Pico 3V3. Verify keyed connector orientation from manufacturer drawing. |
| Common reference | External supply ground → Pico GND physical 23. Only grounds join; external +5 V does not connect to Pico VBUS or 3V3. |
| Tach signal | Fan pin 3 green → Pico GP16 physical 21; 10 kΩ from that signal to Pico 3V3 OUT physical 36. |
| Speed-control input | Fan pin 4 blue PWM left unconnected. This lesson reads speed at the fan’s default full-speed command; it does not generate PWM. |
Keep power and signal roles separate
The fan’s motor current comes from its external 5 V supply. Pico is powered from USB. Joining their grounds gives the signal a shared reference, but the two positive supply rails remain separate. Do not connect a fan motor to a programmable pin. Check the keyed connector and manufacturer’s pin numbering; wire colour alone is not sufficient evidence for an unidentified replacement fan.
The 10 kΩ signal resistor limits low-state pullup current to 3.3/10000 = 0.33 mA, below the documented 5 mA tach output limit for this 5 V fan family. A smaller resistor would increase current and can improve a long line’s rise time, but this short bench connection has no reason to approach the limit. Long cables and electrically noisy environments need a separate signal-integrity review.
Secure the small fan and use a guard. Keep loose wires and the breadboard clear of its blades. For a no-pulse experiment, remove motor power using the supply control; do not jam the rotating blades. Leave the blue control wire isolated so it cannot accidentally short to another pin.
Count one kind of edge
RPM means revolutions per minute. With two cycles per revolution, counting falling edges gives two events for each turn. Counting both rising and falling edges without changing the divisor would double the displayed RPM. The supplied program attaches a hard interrupt to GP16’s falling edge and increments a small bounded counter.
Every approximately two seconds, the main loop briefly disables interrupts, copies and clears the count, and records the actual elapsed milliseconds. It then restores the previous interrupt state. The callback performs no printing and keeps its integer bounded; these choices reduce inappropriate work in an interrupt. They do not guarantee perfect capture during every possible interpreter or electrical disturbance.
The equation is RPM = count × 60000/(elapsed_ms × pulses_per_revolution). For 320 pulses in 2000 ms with two pulses per turn, the result is 4800 RPM. One additional counted pulse changes a two-second result by 15 RPM. That is count quantization, the smallest count step for this window, before oscillator error, missed edges and real speed variation.
Complete program
"""Pico RP2040 + Noctua NF-A4x10 5V PWM. Tach only, no speed control."""
def rpm(count, elapsed_ms, pulses_per_rev=2):
if count < 0 or elapsed_ms <= 0 or pulses_per_rev <= 0:
raise ValueError('invalid sample')
return count * 60000 / (elapsed_ms * pulses_per_rev)
def main():
from machine import Pin, disable_irq, enable_irq
from time import ticks_ms, ticks_diff, sleep_ms
import micropython
micropython.alloc_emergency_exception_buf(100)
count = [0]
def pulse(pin):
# Bounded small integer; no printing/allocation in hard interrupt.
count[0] = (count[0] + 1) & 0xffff
tach = Pin(16, Pin.IN)
tach.irq(handler=pulse, trigger=Pin.IRQ_FALLING, hard=True)
last = ticks_ms(); empty_windows = 0
while True:
sleep_ms(2000)
irq_state = disable_irq()
now = ticks_ms(); n = count[0]; count[0] = 0
enable_irq(irq_state)
duration = ticks_diff(now, last); last = now
empty_windows = empty_windows + 1 if n == 0 else 0
print('pulses:', n, 'window_ms:', duration, 'RPM:', round(rpm(n,duration),1))
if empty_windows >= 2:
print('NO TACH PULSES: stopped, unpowered, disconnected or faulty; not a diagnosis')
if __name__ == '__main__':
main()
Interpret a quiet wire carefully
The loop counts empty windows. After two consecutive zero-count windows it prints NO TACH PULSES and lists several possible causes. An unpowered fan, disconnected signal, wiring fault and stopped rotor all produce no useful pulse stream. A flat signal is therefore an observation, not a complete diagnosis of a mechanical stall.
The first window after starting or stopping the fan can contain a mixture of states. It represents an average pulse rate over that whole interval. This program does not claim an instantaneous speed. A longer window produces smaller count steps but slower response; a period measurement between edges is an alternative with different behavior at very low speed and at startup.
A reproducible first run
- With both supplies disconnected, check connector orientation, positive rails, common ground and pullup. Confirm the exact 5 V fan marking. Install MicroPython 1.26.0 on an original Pico and save the listing as main.py.
- Power Pico first. With fan power absent, observe zero pulse windows and the explicit no-pulse message. This is a communication observation; it is not a fault in a motor that has no supply.
- Apply the regulated 5 V motor supply. Record at least ten windows, including pulse counts and actual durations. Compare the settled readings with the manufacturer’s nominal speed range, allowing its tolerance and the measurement limits.
- Remove motor power through the supply control while leaving the Pico and common ground connected. Record the coast-down and the delay before two empty windows appear.
- Power everything down before disconnecting the tach wire. Restart the controller with the pullup still fitted and confirm the same no-pulse observation. Reconnect before further rotation tests.
What to record before using it for supervision
Save the fan’s full part number, supply voltage under load, count window, interpreter version, pulse polarity and pulses-per-revolution assumption. If you have a logic analyser or oscilloscope suitable for 3.3 V signals, compare waveform edge counts with software counts. A host calculation cannot establish that every physical edge reached the interrupt.
The counter wraps at 65536. At the intended roughly 167 pulses per second and two-second windows this is far away, but it is still a design bound: do not attach a high-frequency source and assume it is a general counter. The tests validate conversion and bad-argument handling, while callback capture remains a target bench check. This circuit has not been physically tested.
Challenge: the display reads twice the expected speed. What two assumptions should you check first?
Check whether you counted both edges and whether the fan really supplies two pulses per revolution. Correct wiring does not compensate for the wrong event divisor.
Sources and related lessons
- Noctua NF-A4x10 5V PWM exact specifications
- Noctua PWM specifications: connector, tach output and control behavior
- Raspberry Pi Pico-series official documentation
- MicroPython 1.26.0 interrupt pin API
Continue with why a voltage divider drops under load, measuring current through a resistor with a voltmeter, and the interactive circuit lessons.



