Following this tutorial you’ll be able to assemble a fan using a transistor to draw 5V current into the fan’s motor. Then you’ll write a Python script to activate the fan when the CPU reaches a certain temperature. Finally, you’ll be able to run the script automatically at boot time.

Scope

I use the latest RaspBerryPi 3 for a lot of things. Plex is one one of them. The RPI3 is very fast in indexing all my media files but it struggles in transcoding .mkv files: it works well but the movie has frequent interruptions, which is not a great user experience. Fortunately, Plex has the built-in converter that enables free .mp4 to browser streaming. To do that in the background, the CPU reaches 380% and the temperature increases greatly over 80C. So I thought: time to add some cooling.

Hardware setup

First things first: I have bought this fan on Amazon. All the fans that I’ve seen are DC 5V with a maximum of 200mA: therefore the active power is 1W. However, the GPIO pins on the pi can only deliver 3.3V with a maximum of 16mA each: we cannot — and should not — feed the motor with the pin’s power. Huston, we have a problem (?).

What we need is some sort of relay that can be activated by a standard pin to draw current at full throttle to our fan. Meet the transistor. More specifically, an NPN Transistor (S8050). The final setup is the following (the fan is represented as a DC motor, this is NOT a real DC motor):