Phyton script that monitors the temperature and adjusts the speed of the cooling fan.
For Raspberry and 5V FAN.
Davide Mencarelli - d.mencarelli@outlook.com
First release: 18/01/2021
Script for Raspberry Pi
Required modules: RPi, gpiozero (pip install gpiozero)
The phyton file is fan_by_pwm.py
Script for Phyton 3.7+
Configuration file: fancontrol.cfg
Optional: copy fancontrol.sh in /etc/init.d/ for starting at boot
Logging messages which are less severe than level will be ignored (/fancontrol.log)
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
GPIO PWM Frequency
The GPIO PIN connect to the base of the transistor
Each x seconds check the CPU Temperature
Above this temperature the FAN start.
When it drops below this value it switches off.
This two array indicate temperature interval and fan speed to set.
Example:
Temps: [ 45, 55, 9999 ]
Speeds: [ 50, 75, 100 ]
ON_THRESOLD < T < 45 => SPEED 50%
45 < T < 55 => SPEED 75%
55 < T < 9999 => SPEED 100%
+5V to the FAN
GPIO_PIN to the base of 2N222 transistor
GND to the collector of 2N222 transistor
Emitter of 2N222 transistor to GND of the FAN