Python Forum
If/ Or if/ temp controlled fan.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If/ Or if/ temp controlled fan.
#3
pin = 18 # The pin ID, edit here to change it
maxTMP = 75 # The maximum temperature in Celsius after which we trigger the fan
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
GPIO.setwarnings(False)
return()
def getCPUtemperature():
res = os.popen(‘vcgencmd measure_temp’).readline()
temp =(res.replace(“temp=”,””).replace(“’C\n”,””))
#print(“temp is {0}”.format(temp)) #Uncomment here for testing
return temp
def fanON():
setPin(True)
return()
def fanOFF():
setPin(False)
return()
def getTEMP():
CPU_temp = float(getCPUtemperature())
if CPU_temp>maxTMP:
fanON()
else:
fanOFF()
return()
def setPin(mode): # A little redundant function but useful if you want to add logging
GPIO.output(pin, mode)
return()
try:
setup() 
while True:
getTEMP()
sleep(5) # Read the temperature every 5 sec, increase or decrease this limit if you want
except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt 
GPIO.cleanup() # resets all GPIO ports used by this program
Now, instead of using else: fanoff, on row 23, could I use
or
if CPU_tmp<minTMP
fanoff()
Reply


Messages In This Thread
If/ Or if/ temp controlled fan. - by clueless - Dec-24-2017, 03:58 PM
RE: If/ Or if/ temp controlled fan. - by squenson - Dec-24-2017, 04:30 PM
RE: If/ Or if/ temp controlled fan. - by clueless - Dec-24-2017, 05:20 PM
RE: If/ Or if/ temp controlled fan. - by bogo10 - Dec-24-2017, 06:36 PM
RE: If/ Or if/ temp controlled fan. - by clueless - Dec-24-2017, 07:03 PM
RE: If/ Or if/ temp controlled fan. - by DeaD_EyE - Dec-25-2017, 03:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Deleting Windows temp folder Raysz 7 592 Apr-02-2024, 12:36 PM
Last Post: Raysz
  Print controlled with global-var fmr300 3 1,505 Feb-05-2022, 03:09 PM
Last Post: fmr300
  pyspark creating temp files in /tmp folder aliyesami 1 5,155 Oct-16-2021, 05:15 PM
Last Post: aliyesami
  Help with storing temp data for each day then recording min/max in app. trthskr4 3 2,474 Sep-10-2021, 10:51 PM
Last Post: trthskr4
  How to save Matplot chart to temp file? Morkus 2 4,612 Jun-12-2021, 10:52 AM
Last Post: Morkus
  Get system info from PI (cpu load and temp) korenron 2 2,139 Aug-04-2019, 08:45 AM
Last Post: korenron
  temp analysis Simba 13 5,977 Apr-25-2019, 09:13 PM
Last Post: Simba
  Temp folder creation ste1605 7 5,383 Oct-03-2018, 10:39 AM
Last Post: buran
  Problem with remove Temp Files karlo_ds 1 3,189 Oct-26-2017, 11:42 PM
Last Post: wavic
  How to create a value system with a temp/humidity sensor? Tacoon 2 3,486 Feb-13-2017, 03:11 PM
Last Post: Tacoon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020