A Bash-based installer for a Python-powered fan controller on Raspberry Pi, designed for Debian-based systems (e.g. Raspberry Pi OS). It sets up a systemd service to automatically manage your fan based on CPU temperature.
- Installs a lightweight Python script to control a GPIO-connected fan
- Automatically starts the fan controller using systemd
- Monitors CPU temperature and toggles fan based on thresholds
- Logs installation output to
/var/log/pi_fancontroller.log - Includes a clean uninstall option
- Raspberry Pi running a Debian-based OS (e.g. Raspberry Pi OS)
- GPIO-connected fan (default GPIO pin: 17)
NOTE: Do NOT connect the fan directly to the GPIO pins β a transistor circuit must be used - Python 3 installed
gpiozeroPython library (installed automatically if missing)- Must be run as root (use
sudo)
The fan is controlled via GPIO17 using a transistor switch. This protects the Raspberry Pi and allows it to safely drive the fan.
- Raspberry Pi 3 Model B+
- GPIO 17: Controls the fan via transistor
- 2N2222A NPN Transistor: Acts as a switch
- 880Ξ© Resistor: Limits current to the transistor's base
- 5V Fan: Powered from the Pi's 5V rail
- Ground (GND): Shared by all components
- When GPIO17 is HIGH, the transistor turns ON, grounding the fan and allowing it to spin.
- When GPIO17 is LOW, the transistor turns OFF, and the fan is disconnected from ground.
- The Python script reads CPU temperature and toggles GPIO17 accordingly.
Follow these steps to install the Pi Fan Control script on your Raspberry Pi:
-
Create a new script file
Open a terminal and run:
nano pi_fancontrol.sh -
Copy the script contents
Paste the contents from the following GitHub file into your new script:
https://github.com/SilentWoof/Scripts/tree/main/shell_scripts/pi_fancontrol/pi_fancontrol.sh -
Make the script executable
Run:
sudo chmod +x pi_fancontrol.sh -
Execute the installer
Run:
sudo ./pi_fancontrol.sh
Your Pi Fan Control script should now be installed and running!
The script contains an uninstaller. To run it use --uninstall:
Run:
sudo pi_fancontrol.sh --uninstall
This project was inspired by Howchoo's Raspberry Pi Fan Controller, which introduced a simple and effective way to manage fan speed using GPIO and Python.
Huge thanks to the Howchoo team for their original work β this installer builds on their concept by automating setup and integrating systemd for persistent fan control.

