Start fan when CPU temperature is high and stop it when CPU temperature is low.
Supports Raspberry Pi 4 and Raspberry Pi 5. The GPIO chip is auto-detected at startup and can be overridden with the -g option.
Note: tested on Ubuntu 24.04.
Pifan requires libgpiod, to install it do this:
sudo apt install libgpiod-devThe gpiod package (CLI tools such as gpiodetect, gpioinfo) is optional but useful for troubleshooting:
sudo apt install gpiodTo download the latest source do this:
git clone https://github.com/mrabine/pifan.gitMove to pifan directory:
cd pifanTo configure pifan do this:
cmake --preset gcc-release -DCMAKE_INSTALL_PREFIX=/usrTo build pifan do this:
cmake --build --preset gcc-releaseTo install pifan do this:
sudo cmake --install build/gcc-releaseTo enable pifan do this:
sudo systemctl enable --now pifanpifan [options]
-c
print the cpu temperature
-g chip
gpio chip device name (default: auto detection, "gpiochip0", "gpiochip4").
-h
show available options
-i interval
sleep interval in seconds (default: 2)
-l threshold
lower threshold in °C, fan stops below this value (default: 55)
-n
don't fork into background
-p pin
gpio pin number (default: 14)
-u threshold
upper threshold in °C, fan starts above this value (default: 65)
-v
print version
A 10°C hysteresis between lower and upper thresholds avoids rapid on/off cycling. The Raspberry Pi 5 begins thermal throttling at 80°C, so the following values provide a comfortable safety margin while keeping the fan off most of the time:
pifan -l 55 -u 65These are also the default values.