Skip to content

Instantly share code, notes, and snippets.

@Kalvisan
Created February 22, 2019 19:11
Show Gist options
  • Save Kalvisan/0036c59c5b1aa7801d96672e9bdf516e to your computer and use it in GitHub Desktop.
Save Kalvisan/0036c59c5b1aa7801d96672e9bdf516e to your computer and use it in GitHub Desktop.
Super simple fan controller. I'm using WiringPI library for gpio command
#/bin/bash
MAX_TEMP=40
PIN=1
temp_mili=$(cat /sys/devices/virtual/thermal/thermal_zone0/temp)
temp=$((temp_mili/1000))
echo "Current temperature: ${temp}C"
echo "Given max temp value ${MAX_TEMP}C"
# prepare GPIO pins
gpio mode $PIN out
if [ "$temp" -ge "$MAX_TEMP" ] ; then
echo "Turning on fan! ${temp}C"
gpio write $PIN 1
else
echo "Turning OFF fan! ${temp}C"
gpio write $PIN 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment