Raspberry Pi Cooling Fan Controlled via Temperature

Switch a cooling fan on or off for your Raspberry Pi-based on processor temperature using a Bash script.

Jeremy Cook
4 years ago3D Printing / Sensors

Keeping your Raspberry Pi sufficiently cool is important to allow it to function optimally. After seeing a high temperature warning on the Pi that controls my 3D printer in a rather hot garage, I decided it was finally time to add a heat sink of some sort. While a small passive solution would have probably been fine — for this Pi 3B, running OctoPrint — I chose to instead install a rather massive ICE tower cooling fan assembly.

This was used simply as a passive solution for some time, but when I finally got around to powering it, plugging it in to the constant 5V output seemed a little silly. However, my solution was to use a 2N2222 transistor to enable a Raspberry Pi GPIO pin to switch the fan on and off as needed. A Bash script was then used to automate this via processor temperature, set up to run once every minute per cron.

The disadvantage here is that the fan switches on or off rather slowly, but it’s by far the simplest method I’ve seen from a coding standpoint. The controlling script is found on GitHub, along with a small PCB designed to accommodate the transistor, resistor, as well as a diode that is meant to dissipate power as the fan spins down.

The video below explains things in more detail, giving an option for breadboard, heat shrink, and PCB implementations.

Jeremy Cook
Engineer, maker of random contraptions, love learning about tech. Write for various publications, including Hackster!
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles