Thursday 01 April, 2021 | RSS Feed

  • news/images_small/fan1.jpg

    Fan.sh

    1. #!/bin/bash
    2.  
    3. #Define GPIO pin 18 as PWM
    4. gpio -g mode 18 pwm
    5.  
    6. num=true
    7. while [ $num ];
    8. do
    9. # Print CPU temp
    10. temp=$(cat /sys/class/thermal/thermal_zone0/temp)
    11. temp=$(($temp/1000))
    12. clear
    13. printf "Temperature: $tempºCnTurning on fan."
    14.  
    15. # Variable temperature control
    16. if [ $temp -gt 40 ] && [ $temp -lt 69 ];
    17. then
    18. vartemp=$(echo $[ temp * 13 ])
    19. gpio -g pwm 18 $vartemp
    20.  
    21. # Maximum fan RPM
    22. elif [ $temp -ge 69 ];
    23. then
    24. gpio -g pwm 18 1024
    25.  
    26. # Switch off the fan
    27. else
    28. gpio -g pwm 18 0
    29. clear
    30. printf "Temperature: $tempºCnFan off."
    31. sleep 60
    32. fi
    33.  
    34. #Pause 1 second
    35. sleep 1
    36.  
    37. done
    38. exit 0
    by Administrator

  • News archive