Building a fan controller for your Raspberry Pi

Torben Dury · November 27, 2021

Learn how to build a simple and affordable fan controller for your Raspberry Pi to connect a simple fan with temperature control.

What you will need

What we will build

To connect with our Raspberry Pi, we will use a 5V output. Also, we’ll utilize the GND of our Pi. To control our fan, we will use GPIO14 as a data output which controls the transistor.

Our fan is connected to the 5V output and to the transistor.

In between our Pi and our transistor, we put a 4,7k Ohm resistor.

All in all, your setup could look like this on a breadboard:

Configuring your Raspberry Pi

When you’re all hooked up, connect to your Raspberry Pi via SSH and type:

  sudo raspi-config

From there on, head to the “Performance” tab and enable the “Fan control”. You can set a target temperature (e.g. 80°C) at which the Raspberry Pi is going to power the fan on to cool itself down. When asked to put in a pin number, we will choose our connected GPIO14 pin. Hit Enter and you’re done!

Extra: Testing our setup with a stress-test

When you’re all built and set up, you can run a simple test directly on your Raspberry Pi. When connected via SSH, type the following:

  # Update our repository first and upgrade installed software (generally recommended)
  $ sudo apt update && sudo apt upgrade -y
  # Install `stress`
  $ sudo apt install stress
  # Install an easy to use Python module made for stress-testing Raspberry Pis
  $ pip3 install stressberry

When you’re done installing everything, you can run a test and generate some report output:

  stressberry-run output.dat

Soon, you will start to hear your fan running to cool the Raspberry Pi down.

It is proven that external fans help cooling down your Pi system - especially Pi 4 boards which tend to get a little hotter than previous boards. Any doubts? Disable your fan control in your raspi-config and run the stressberry test again. Compare the data outputs and convince yourself!

Conclusion

Building your own fan control is cost-effective and can be done in less than half an hour. It is very helpful to learn more about transistors and how to control circuits with it on a very high level.

XING, LinkedIn, Twitter, Facebook