An automatic fan speed control for RPI4 depending upon the temprature using python script.
Simple hardware using FET to control fan switching.
R1 to discharge the gate capacitance of the MOSFET, and R2 to limit the current which is created if you change the signal at the gate. R1 is usually a few k Ohms, and R2 a few 100 ohms.
- Power up the RPI and open terminal and create a new directory named scripts
cd
mkdir Scripts
- Change directory to Scripts
cd Scripts
- Now copy
fancontroll.py
&launcher.sh
from PC to RPIScripts
folder, this can be done using many methods here I will useSCP
command for sending files over SSH
scp fancontroll.py root@192.168.43.112:Scripts/
scp launcher.sh root@192.168.43.112:Scripts/
note that ssh client should be installed on both sides (PC & RPI) use the below code to install.
apt-get install openssh-client
-
Now run the python code using the command
python fancontroll.py
-
Now we add a directory to store the error log files
cd
mkdir logs
- Now to automatically start the python script on rpi reboot use the following commands
The below code makes
launcher.sh
files executable
cd
cd Scripts/
bash launcher.sh
sh ./launcher.sh
chmod 755 launcher.sh
Now open crontab to add launcher.sh
path to automaticaly start after reboot
sudo crontab -e
At the end of the file add the following line and save the file
@reboot sh /root/Scripts/launcher.sh >/root/logs/cronlog 2>&1
Note to add the directory loaction according to your RPI, to get the path of directory use the command
pwd
- Now reboot the RPI to get the changes saved
References :