Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


A simple thermal fan controller for Raspbian.



Required parts

  • 5V DC fan x1, 3mm / 4mm or any other size suitable for your Raspberry Pi.
  • 2N2222 NPN transistor x1.
  • 680ohm resistor x1.
  • (Optional) small piece of PCB. If you don't have one, it is also possible to solder all parts directly to the fan wires..

The circuit

the circuit

Or you could reference to this post for connecting your parts together.

Choose any GND / VCC (5V) pin to supply power. For the controller pin, use GPIO 8 (AKA BCM 14).


Install dependencies

  • First of all update apt cache: sudo apt update.
  • Install cmake, gcc and git, as you would do for all other C projects: sudo apt install cmake build-essential gcc git.
  • Install the MRAA lilbrary for accessing GPIO:
    • Clone MRAA project: git clone
    • Enter the cloned repository: cd mraa
    • Prepare to build: mkdir build && cd build
    • Generate makefiles: cmake ..
    • Build: make
    • Install the built tools: sudo make install
    • Refresh linker related stuff so MRAA library can be located by gcc: sudo ldconfig -v
    • To verify you have correctly installed the MRAA library, run mraa-gpio version, it should print the model of your Raspberry Pi

Build this project

  • Clone this project: git clone
  • Enter the cloned repository: cd fanctl
  • Prepare to build: mkdir build && cd build
  • Generate makefiles: cmake ..
  • Build: make
  • Install: sudo make install

Start service

  • Reload systemd units: sudo systemctl daemon-reload
  • To verify you have correctly installed the service, run sudo systemctl status fanctl, it should print some information about this tool
  • To start the service: sudo systemctl start fanctl

When the chip temperature reaches 60°C, the fan will be started by pulling FAN_VCC_PIN to high (causing the transistor to close). When the chip temperature drops to 45°C or below, the fan will be stopped by pulling FAN_VCC_PIN to low. When the fan is started or stopped, the corresponding temperature value will be written to journald logs, to follow the log: sudo journalctl -u fanctl -f.


Edit the installed service file (in /etc/systemd/system), use THRESHOLD_ON and THRESHOLD_OFF to set temperature limits. ON is the upper limit, fan starts when chip temperature reaches above it; OFF is the lower limit, fan stops when chip temperature drops below it.

# ...

You'll need to reload the daemon before restarting the service:

sudo systemctl daemon-reload
sudo systemctl restart fanctl

To use a different pin for controlling the fan, modify FAN_VCC_PIN (Notice: MRAA library uses the physical pin number). Then rebuild and reinstall again. Service will need to be restarted.

Why C

Well, I've actually written a Python script and installed that as a service, it kept working for almost 6 months. But I don't think such a simple job is worth using 15MB of memory. The memory footprint dropped under 400KB after transforming to C.


No releases published


No packages published