Introduction
Raspberry Pi configuration allows you to set the temperature to control raspberry pi fan on/off. But there is a limitation to it. It only allows you to set temperature from 60 degree to 120 degree. What if you need to switch on the fan at a lower temperature like 40 degree? We can do so by writing custom script.
How to do it?
- Connect Raspberry PI fan to GPIO PIN 14(default). Other 2 pin is to +5v and GND.
- Download the python script from https://github.com/pintushaw/raspberrypifancontrol
- Set up in cron. To do so, copy the script to /home/pi/bin (assumes ‘pi’ is user name). Add this entry to crontab (adjust pin and temp as needed):
*/1 * * * * /home/pi/bin/fantemp.py --p 14 -t 60
Note: to update crontab run using crontab -e command as shown below:
Note: If you get error like “ImportError: No module named vcgencmd“. This means that either the module vcgencmd is not installed or the PATH variable is not set to bin of vcgencmd.
After setting up crontab reboot and you are all done.
Dear sirs;
I have a pi4 with latest bullseye os and I did the procedure that you mentioned and set the temp to 45 degrees and reboot but the fan didn’t start at 45 and nor in the pi configuration menu the temperature control set point does not go below 60 degrees
Please inform me of any things that fix this. Meanwhile during the programing I have not received any error notification.
Can you recheck your wiring and also the cron job?
Hello,
I’ve followed the instructions as stated above but when I test run the cron job it throws the following message: line 43, in
from vcgencmd import Vcgencmd
ModuleNotFoundError: No module named ‘vcgencmd’
I see you mention this type of message that could occur in your note but I don’t know how to resolve it. Any help would be appreciated. Thanks in advance.
Try installing vcgencmd module using following command.
pip3 install vcgencmd or reinstall libraspberrypi-bin
apt-get –reinstall install libraspberrypi-bin
Restart and it should work. If you already have installed but still not working then try setting PATH variable. You can follow the instruction from below which helped me.
https://raspberrypi.stackexchange.com/questions/112043/vcgencmd-not-found
Thanks, Pintu! Installing the vcgencmd module (pip3 install) did the trick. It works great.