Automatically Control Your Raspberry Pi Fan (and Temperature) with Python
Since the Raspberry Pi 4 was released, many have noticed that it can get pretty hot, especially when the CPU is under heavy load.
A Raspberry Pi enthusiast, Jeff Geerling, released a pretty cool video showing how to add a fan to the Raspberry Pi to help keep the temperature under control. That project was pretty great but I wanted to take it to the next level and add the ability to only turn the fan on when needed by monitoring the core temperature. This way, a noisy fan isn't running all the time.
In this guide, I'll cover the whole project from start to finish. First, we'll install the fan onto the official Raspberry Pi case and wire it up so it can be activated by a GPIO pin. Then we'll write some Python code to monitor the temperature and activate the Pi when the temperature reaches a certain threshold.
Requirements
In order to complete this guide, you'll need a Raspberry Pi 4 with the latest version of Raspbian installed. The scripts I've included are written for Python 3.7, which is the default Python 3 version in the September 2019 version of Raspbian. Newer Raspbian versions will work as well :)
Update 11/30/20: An official Raspberry Pi 4 case fan was recently released. This is ideal for anyone who wants to cool their Pi with name-brand hardware. It's specifically designed to fit the official Raspberry Pi 4 case.
Raspberry Pi 4 Model B | × | 1 | ||
Official Raspberry Pi 4 case | × | 1 | ||
Pi-Fan Raspberry Pi fan | × | 1 | ||
Drill bit, 7/64" | × | 1 | ||
Hole saw bit, 1-1/8" | × | 1 | ||
Cordless drill | × | 1 | ||
Soldering Iron | × | 1 | ||
Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.