This repository implements a fan speed controller for a PWM fan connected to an Orange Pi 5 SBC. The controller runs as a long-running service which enables a PWM pin, periodically checks the SoC thermal zone's temperature, and updates the fan duty cycle. The fan is off below 50C and runs at full speed above 75C; between these two temperatures its duty cycle scales linearly.
This controller has been tested only using Armbian and a Noctua NF-A4x20 5V PWM fan.
The controller uses the following defaults:
- PWM pin: PWM15_IR_M2
- PWM frequency: 25kHz
- This is the required frequency for Noctua PWM fans, as specified in their whitepaper
- Since PWM periods and duty cycles are specified in nanoseconds, this corresponds to a period of 40,000ns
- Thermal zone: 0 (SoC temperature)
Requirements:
- Zig
- The PWM overlay for the PWM pin you want to use must be enabled
- In Armbian, this can be enabled using
armbian-config
:- Run
sudo armbian-config
- Select
System
- Select
Hardware
- Find the PWM pin you want to use (e.g., the default pin is
rk3588-pwm15-m2
) and select it using Space - Select
Save
- Save, exit, and reboot the Orange Pi.
- Run
- In Armbian, this can be enabled using
- SSH access to the Orange Pi if building and installing from another computer
- A 5V PWM fan connected to ground, 5V, and PWM15 (or another PWM pin)
-
Compile the binary. This can be done from another computer using Zig's cross compilation support:
zig build -Dtarget=aarch64-linux-musl -Doptimize=ReleaseSafe
The binary will now be at
zig-out/bin/op5-pwm-fan
. -
Copy the binary and systemd unit to the appropriate places on the Orange Pi 5. If you are using another computer, this can be done using
scp
or any other appropriate tool.zig-out/bin/op5-pwm-fan
->/usr/bin/op5-pwm-fan
fan-controller.service
->/etc/systemd/system/fan-controller.service
-
Run
sudo systemctl daemon-reload
to allow systemd to find the unit -
Enable and start the fan controller:
sudo systemctl start fan-controller.service sudo systemctl enable fan-controller.service
Your fan should now automatically adjust its speed as the temperature of your device changes.
This repository is licensed under the MIT license.