Automatic fan control based on CPU temperature using PWM signal.
Fan noise may be annoying but sometimes also might be useful. An automatic fan control is perfect for you if you want a nice passive cooled Raspberry Pi plus an available cooling boost when needed to keep your device at maximum performance or below desired temperature.
Circuit sketch:
Final circuit:
I chose the GPIO pin 18 (pin 12) as it is the closest to power pins. However you can use other GPIO pins as well.
Raspberry Pi 2/3 pinout:
I used Python 3.5 for my code. See the code in fancontrol.py
.
You will need to add startup script as root because of GPIO pins (more sophisticated permissions would be nice if you care more about security, e.g. create a group, allow GPIO pin access to the group, then add your user to the group). Now I want to keep it simple.
bana@banarpi:~ $ sudo su
Edit root´s crontab file:
root@banarpi:/home/bana# crontab -e
Add the following line to your crontab file which will always start to run in background on startup:
...
@reboot python /location/to/file/fancontrol.py /location/to/file/config.json
You can choose 2 different modes:
- PWM controlled fan - fan speeds for each temperature level are specified in config file
- Binary ON/OFF - turn ON/OFF temperature can be specified
Option 1 can handle variable speeds, however you may hear some PWM noise, which is a deaden with a capacitor, depends also on the fan, how annoying is this phenomenon, so you can choose the other mode if you want to.