GERMAN AMATEUR RADIO STATIONBERLIN / JO62PM / DMR-ID 2621039 / TETRA-ID 2636912
DL7OLG – Amateur radio Berlin
← Homebrew projectsHomebrew · PWM & cooling

Quiet fan control for the Raspberry Pi 4

A MacBook fan on the Pi: hardware PWM, BC547B and tachometer feedback on a small perfboard. With a photo, schematic and parts list.

Quiet fan control for the Raspberry Pi 4

A salvaged MacBook fan cools the Raspberry Pi 4 in my station. Its control circuit fits on a small piece of perfboard: a BC547B, four resistors and an electrolytic capacitor. The Pi controls the fan using hardware PWM and reads back its tachometer signal.

5 V · four wires21 kHz hardware PWMBC547B3.3 V tachometer
MacBook blower with a hand-built fan-control circuit on perfboard beside the Raspberry Pi and SXceiver
The current build: the small perfboard circuit sits directly on the fan. I filed the mounting points to fit. Open full-size photo.

A MacBook fan on the Pi

The fan is a four-wire Delta KSB0505HB-8F36, labelled 5 V / 0.40 A. This blower fits my heatsink well and runs quietly at low speed. I adapted the mounting by hand; this is my own experimental build.

The four connections are +5 V, GND, PWM and tachometer. The schematic identifies these functions. It does not establish a universal connector order or wire-colour scheme for other fans.

Complete wiring

Pi fan-control schematic with BC547B, 2.2-kilohm base resistor, 10-kilohm pulldown, 3.3 V tachometer wiring and 1000-microfarad capacitor
All Pi pin numbers refer to physical positions on the 40-pin header. Click to enlarge. Download the SVG schematic.
Pi pinFunctionConnection
2+5 VFan supply and positive terminal of C1.
6GNDFan ground, emitter and negative terminal of C1.
33 · GPIO13PWM outputThrough R1, 2.2 kΩ, to the BC547B base.
1+3.3 VThrough R3, 2.2 kΩ, to the tachometer node.
36 · GPIO16Tachometer inputThrough R4, 2.2 kΩ, to that same node.

The collector connects to the fan PWM wire; the emitter connects to ground. R2, 10 kΩ, goes directly between base and emitter. For the TO-92 BC547B shown here, viewed with its flat, marked face toward you and the leads pointing down, the order is C on the left, B in the middle, E on the right. See the onsemi BC547 datasheet.

The motor receives a continuous 5 V supply. The transistor pulls only the PWM control wire to ground. This inverts the signal: GPIO HIGH → fan PWM LOW. The software accounts for that inversion.

Tachometer pull-up to 3.3 V

R3 pulls the tachometer node up to 3.3 V; R4 connects it to GPIO16. These two resistors are not a voltage divider. This circuit requires an open-collector tachometer output without an internal pull-up to 5 V. It does not level-shift an actively driven 5 V output. Pi GPIOs use 3.3 V logic and are not 5 V tolerant.

GPIO16 is configured as an input with its internal pull resistors disabled. Speed is calculated from pulse frequency and the number of pulses per revolution: RPM = 60 × f / pulses per revolution. The assumption of two pulses per revolution has not been independently confirmed for this exact fan variant, so the absolute RPM reading remains approximate.

Perfboard components

PartValue / typePurpose
Q1BC547BNPN transistor for the PWM control wire
R12.2 kΩ · SMD 222Base resistor
R210 kΩ · SMD 103Base-to-emitter pulldown
R32.2 kΩ · SMD 222Tachometer pull-up to 3.3 V
R42.2 kΩ · SMD 222Series resistor to the tachometer input
C11000 µF / 25 VAcross +5 V and GND, positive terminal to +5 V

The capacitor sits close to the fan supply connection. I used a 25 V part because it was in my parts box; it operates at 5 V here. The Pi power supply must also accommodate the fan current.

Quiet running without repeated restarts

At low speed I initially heard noises that coincided with Pi activity. Adding the capacitor alone did not remove them. After switching to hardware PWM on GPIO13 at 21 kHz, the fan ran quietly in the test. The 21 kHz setting is a tested value for this build, not a claimed manufacturer specification.

My fan can sustain a low speed but does not reliably start from rest at the same setting. Automatic control therefore keeps it running at a minimum of 16% and follows a smoothed temperature curve above that. After an intentional stop it briefly receives 35% to start, then settles to the requested setting. Manual control still allows a complete stop. These percentages apply to my particular fan.

On my SX board, the existing D2 LED also connects to GPIO13 through its original 1 kΩ resistor. It can remain connected there and follows the inverted control signal. Its HDMI indicator is now labelled PWM: it shows sampled GPIO levels, not RPM. This shared connection applies to my verified board wiring, not to every HAT.

The rest of the Pi, SXceiver, Si570 and GPS/PPS station is documented in Si570 and GPS/PPS as the SXceiver reference.