This guide will help you set up automatic fan control for your Raspberry Pi 5.
-
Copy your working script to a system location:
sudo cp fanspeed.py /usr/local/bin/fan_control.py sudo chmod +x /usr/local/bin/fan_control.py
-
Create the systemd service file:
sudo nano /etc/systemd/system/fan-control.service
Copy and paste the following service configuration into this file:
[Unit] Description=Raspberry Pi 5 Fan Control Service After=multi-user.target [Service] ExecStart=/usr/bin/python3 /usr/local/bin/fan_control.py Restart=always RestartSec=10 User=root StandardOutput=syslog StandardError=syslog SyslogIdentifier=fan-control [Install] WantedBy=multi-user.target
-
Enable and start the service:
sudo systemctl enable fan-control.service sudo systemctl start fan-control.service
-
Verify that it's running:
sudo systemctl status fan-control.service
You can customize the fan behavior if needed. Here are some options:
-
To make the fan quieter, you can adjust the temperature thresholds in the script. Open the script:
sudo nano /usr/local/bin/fan_control.py
-
Find the
calculate_fan_speed
function and modify the thresholds as needed. For example, for an even quieter operation:def calculate_fan_speed(temp):
-
After making any changes, restart the service:
sudo systemctl restart fan-control.service
-
To view the logs of the fan control service:
journalctl -u fan-control.service
-
To stop the service temporarily:
sudo systemctl stop fan-control.service
-
To disable the service from starting at boot:
sudo systemctl disable fan-control.service