https://github.com/mrabine/pifan
Raspberry Pi fan controller daemon
https://github.com/mrabine/pifan
cpu-temperature fan fan-controller linux raspberry-pi raspberry-pi-4b raspberry-pi-gpio systemd temperature-monitoring
Last synced: 3 months ago
JSON representation
Raspberry Pi fan controller daemon
- Host: GitHub
- URL: https://github.com/mrabine/pifan
- Owner: mrabine
- License: mit
- Created: 2021-02-28T00:17:34.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2026-03-28T18:31:08.000Z (3 months ago)
- Last Synced: 2026-03-28T18:31:39.428Z (3 months ago)
- Topics: cpu-temperature, fan, fan-controller, linux, raspberry-pi, raspberry-pi-4b, raspberry-pi-gpio, systemd, temperature-monitoring
- Language: C
- Homepage:
- Size: 28.3 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pifan
### Raspberry Pi fan controller daemon
[](https://github.com/mrabine/pifan/actions?query=workflow%3Acd+branch%3Amain)
[](https://github.com/mrabine/pifan/actions?query=workflow%3Aaudit+branch%3Amain)
[](https://app.codacy.com/gh/mrabine/pifan/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://github.com/mrabine/pifan/releases/latest)
[](https://github.com/mrabine/pifan/blob/main/LICENSE)
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.
## Dependencies
Pifan requires `libgpiod`, to install it do this:
```bash
sudo apt install libgpiod-dev
```
The `gpiod` package (CLI tools such as `gpiodetect`, `gpioinfo`) is optional but useful for troubleshooting:
```bash
sudo apt install gpiod
```
## Download
To download the latest source do this:
```bash
git clone https://github.com/mrabine/pifan.git
```
Move to `pifan` directory:
```bash
cd pifan
```
## Configuration
To configure pifan do this:
```bash
cmake --preset gcc-release -DCMAKE_INSTALL_PREFIX=/usr
```
## Build
To build pifan do this:
```bash
cmake --build --preset gcc-release
```
## Installation
To install pifan do this:
```bash
sudo cmake --install build/gcc-release
```
## Enabling
To enable pifan do this:
```bash
sudo systemctl enable --now pifan
```
## Usage
**pifan** [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
## Recommended thresholds
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:
```bash
pifan -l 55 -u 65
```
These are also the default values.
## License
[MIT](https://choosealicense.com/licenses/mit/)