This script written in C language reads the CPU temperature and adjusts the fan speed based on that information. Before the script can work, wiringOP needs to be downloaded and installed from Git to enable the use of GPIO pins. Additionally, the script needs to be compiled after it's downloaded.
- Orange Pi 5
- wiringOP (https://github.com/orangepi-xunlong/wiringOP.git)
- 5V PWM Fan (e.g. Noctua)
- Download wiringOP from Git:
git clone --branch next https://github.com/orangepi-xunlong/wiringOP.git
- Navigate to the wiringOP directory and run the installation command:
cd wiringOP
./build clean
./build
- Download the C script and save it to the directory of your choice.
git clone https://github.com/bastilmr/opi5-fan-control.git
- Compile the script using the following command:
gcc -o fan-control fan-control.c -lwiringPi
Or for binary fan control (no PWM):
gcc -o fan-control binary-fan-control.c -lwiringPi
- Make the script executable:
chmod +x fan-control
- Add the script to your crontab to run at boot using the following command:
crontab -e
- Add the following line to your crontab to run the script at boot:
@reboot /path/to/fan-control
Be sure to replace /path/to/
with the actual path to the directory where the script is located.
The script is configured by default to control the fan speed based on the CPU temperature. However, you can customize the configuration to your needs by changing the following variables in the script:
FAN_PIN
: The GPIO pin where the fan is connected.CPU_TEMP_FILE
: The file that contains the CPU temperature.MIN_TEMP
: The minimum CPU temperature at which the fan runs at the minimum speed.MAX_TEMP
: The maximum CPU temperature at which the fan runs at the maximum speed.MIN_PWM
: The minimum fan speed.MAX_PWM
: The maximum fan speed.
In this example, the fan was connected to the 5V, Ground, and GPIO4_A3 (UART0_TX_M2) Pin of the Orange Pi 5.
This script has been successfully tested on an Orange Pi 5 and Orange Pi 5b. However, it should also work on other Orange Pi's.