The repo is based on: https://github.com/bastilmr/opi5-fan-control
This script written in C language reads the CPU temperature and toggle the fan 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 Fan (e.g. Noctua)
- PNP/NPN transistor
- 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/ASDosjani/opi5-fan-control.git
- Compile the script using the following command:
gcc -o fan-control 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.
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.THRESHOLD_TEMP
: The minimum CPU temperature at which the fan start spinning.PNP
: 1 if PNP transistor used, 0 if NPN
In this example, the fan 5V pin was connected to 5V on OPi, Ground to a BC327 emitter pin, collector to Ground and base to GPIO4_A3 (UART0_TX_M2) Pin of the Orange Pi 5. Like in the picture:
This script has been successfully tested on an Orange Pi 5. However, it should also work on other Orange Pi's. I use this small fan included with the heatsink like this: