Weekend Project. Fan controll for the new Raspberry PI 4. No programming just bash and cron. Based on https://hackernoon.com/raspberry-pi-temperature-controlled-fan-2aa0de72a564 with change for on/off tresholds.
#!/bin/sh timestamp() { date +"%Y-%m-%d %T" } LOGDIR="/var/log/fan.log" VALUE_ON=55 VALUE_OFF=50 TEMP=`vcgencmd measure_temp | cut -c6,7` STATUS=`cat /sys/class/gpio/gpio2/value` echo `timestamp` " Info: Temperature: $TEMP">>$LOGDIR if [ $TEMP -ge $VALUE_ON ] && [ $STATUS -eq 0 ] then echo `timestamp` " Warning: Fan started.">>$LOGDIR echo "1">/sys/class/gpio/gpio2/value elif [ $TEMP -le $VALUE_OFF ] && [ $STATUS -eq 1 ] then echo `timestamp` " Warning: Fan stopped.">>$LOGDIR echo "0">/sys/class/gpio/gpio2/value fi
Add the following add the end of /etc/rc.local to enable the GPIO port after reboot.
# Set GPIO 2 to "out" mode to enable fan control echo "2" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio2/direction












