How to control Raspberry Pi fan

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?

  1. Connect Raspberry PI fan to GPIO  PIN 14(default). Other 2 pin is to +5v and GND. 
  2. Download the python script from https://github.com/pintushaw/raspberrypifancontrol
  3. 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.

5 Comments

  1. 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.

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.