Raspberry Pi Temperature Controlled Fan
Icy Berry.
So my Raspberry Pi has a fan that runs constantly and it annoys me, time to fix that. I am going to show you how to make a fan that only turns on when the raspberry pi is on and the CPU is above a certain temperature threshold. We’ll be using rpi-fan-controller for this task.
Bill of Materials
1x Raspberry Pi (Available at Sparkfun)
1x 1kΩ resistor (Available at Sparkfun)
1x NPN transistor (Available at Sparkfun)
Circuit
The circuit uses an NPN transistor as a switch. The transistor allows the fan to draw a high current from the 5V pin, and lets us control it from another pin.
I also built a circuit board to fit on the pi:
Once you have built this circuit, we need to install the software.
Software
Open a terminal and run the following commands:
This will install the rpifan tool and remove the installation files.
The tool will now run with the default settings, which means it will check the temperature every 10 minutes and turn on the fan if the CPU is hotter than 40 °C.
The tool will be run periodically but you can run it at anytime by typing rpifan
into the console.
Configuring
Temperature Threshold and Trigger Pin
We can optionally configure the temperature threshold and the trigger pin of the rpifan program, to do that run this:
You should see the following lines:
The GPIO pin is the GEN pin number, so GEN1 would be GPIO 18.
The temperature is in degrees Celsius, so adjust accordingly if you live in a country that has a tendency to lose French scientists to pirates.
Frequency
We can also change the frequency of which the tool is run by typing crontab -e
into the terminal. You should see the following lines:
The */10
signifies the tool will be run every 10 minutes, this could be changed to */5
for example to run it every 5 minutes.