raspberry-pi-temp-control

Linux Ubuntu Raspberry PI temperature control script

Today I am sharing my simple and at the same time useful Linux script which checks the temperature and depends by result, sends 1 or 0 to the interface. This turns the cooling on or off.

#!/bin/sh
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
echo $temp
if [ $temp -gt 45000 ]
then
gpio mode 7 out
gpio write 7 1
echo "Temp bolshe max poroga $temp > 45000 - vkluchau kuler"
fi
if [ $temp -lt 35000 ]
then
gpio mode 7 out
gpio write 7 0
echo "Temp menshe min poroga  $temp < 35000 - vikluchau kuler"
fi

This is a shell script written in the Bash language. Here’s what it does:

  1. It reads the current temperature from the thermal sensor file located at /sys/class/thermal/thermal_zone0/temp and stores it in a variable called “temp”.
  2. It then echoes the value of “temp” to the standard output.
  3. If the value of “temp” is greater than 45000, the script sets the GPIO pin 7 as an output and sets it to high (1), which will turn on a fan or cooling system. The script then echoes a message indicating that the temperature is above the maximum threshold and the fan has been turned on.
  4. If the value of “temp” is less than 35000, the script sets the GPIO pin 7 as an output and sets it to low (0), which will turn off the fan or cooling system. The script then echoes a message indicating that the temperature is below the minimum threshold and the fan has been turned off.
See also  How to get the length of a cursor from mongodb using Python?

In summary, this script monitors the temperature of the system and turns on or off a cooling system depending on whether the temperature is above or below a certain threshold.

Author: admin

Leave a Reply

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