Control your Raspberry Pi FAN using hardware PWM
If you’re a Raspberry Pi enthusiast, you may have encountered the need to control the fan speed for cooling your Pi when it’s under heavy load.
Here I’ll show you how to do that using a simple Python script and a library that controls the PWM signal using a hardware driver, that way we can use higher frequencies and there’s no CPU load.
The Python library that is needed in this case: rpi-hardware-pwm.
Python hardware PWM FAN control script
This is the script, and if you want to add it on the startup of the Raspberry Pi, then scroll at the bottom for installing instructions 🥳.
Installing instructions and run at the startup
These instructions will automatically put the script into the /usr/local/bin/fan_control.py and get the service to run it at startup:
Here’s the fan_control.service, if you want to take a quick look: