Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize CPU temperature control fan for raspberry pie

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the raspberry pie how to achieve CPU temperature control fan, the article is very detailed, has a certain reference value, interested friends must read it!

Raspberry pie temperature control fan

Transistor mode J13009 transistor (used as a switch), pin description, in the face of the written description side, from left to right: B C E less 1k capacitance (pull-down resistance, protection), DuPont wire wiring sequence must be correct:

B (base)-pull 1K resistor-GPIO 40 (you can choose any other control port)

E (emitter)-GND

C (collector)-fan black line

Fan red line-5V

Relay version (JDQ) mode:

+ 5V-JDQ input positive

JDQ output-Fan Red Line

GND-JDQ control line negative-fan black line

Positive pole line of GPIO40-JDQ control coil

Code:

# read the temperature sensor inside the CPU every 2 seconds and display the CPU temperature # turn on the fan when the temperature exceeds 45 °C # turn off the fan below 38 °C: import sysimport timetry: import RPi.GPIO as GPIOexcept RuntimeError: print ("Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script ") def cpu_temp (): with open (" / sys/class/thermal/thermal_zone0/temp ",' r') as f: return float (f.read ()) / 1000def main (): channel = 40 # rightmost lower foot pin GPIO.setmode (GPIO.BOARD) # GPIO.setmode (GPIO.BCM) # it is recommended to use GPIO.BOARD mode (on-board pin) to adapt to different versions of raspberry pie. GPIO.setwarnings (False) # close air fan first GPIO.setup (channel, GPIO.OUT, initial=GPIO.HIGH) is_close = True while True: temp = cpu_temp () if is_close: if temp > 45.0: print (time.ctime (), temp, 'open air fan') GPIO.output (channel 1) is_close = False else: if temp < 38.0: print (time.ctime (), temp, 'close air fan') GPIO.output (channel, 0) is_close = True time.sleep (2.0) print (time.ctime () Temp) if _ _ name__ = ='_ _ main__': main () Raspberry pie boot runs the Python script method

Create a folder under / home/pi/.config named autostart, and create a xxx.desktop file under that folder (the file name ends with .folders, which can be customized earlier), with the following contents:

[Desktop Entry] Name=example Comment=My Python Program Exec=python / home/pi/example.py Icon=/home/pi/example.png Terminal=false MultipleArgs=false Type=Application Categories=Application;Development; StartupNotify=true

The above Name, Comment, and Icon can be customized to indicate the name of the startup project, the comments, and the icon displayed. Exec indicates the instruction to be invoked, which is in the same format as the instruction entered at the terminal to run the script, and Linux can also refer to this code.

The above is all the contents of the article "how to realize CPU temperature control fan in raspberry pie". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report