This project provides examples of fan control based on the current CPU temperature.
It includes implementations of a relay controller and a proportional controller.
The fan is connected via a transistor switch to the 4th pin of the I/O ports. The fan connection pin can be changed in scripts. The remaining parameters can be set at startup.
Clone repository:
git clone https://github.com/Nkeramov/raspberry_pi_fan_control.git
Switch to repo directory
cd raspberry_pi_fan_control
Сreate new virtual environment:
python -m venv .venv
Activate the virtual environment with the command:
source .venv/bin/activate
Install dependencies from the requirements file:
pip install -r requirements.txt
Run relay fan controller with command (args for example):
python3 relay_controller.py --lower 45 --upper 50 --delay 5
Run proportional fan controller with command (args for example):
python3 proportional_controller.py --temp 45 --delay 5 --p 15.0 --dmin 50 --dmax 100
Or use a launch script run.sh
, making it executable first
chmod +x run.sh
Script arguments can be changed.
You can set up automatic script launch at system startup.
Open the /etc/rc.local file in editor:
sudo nano /etc/rc.local
Add to the end of file this line:
/home/pi/raspberry_pi_fan_control/run.sh &
Press Ctrl+O → Enter → Ctrl+X to save and exit. With these few easy steps, you now have automatic fan control.
If you want to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push to your fork and create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.