当前位置:网站首页>树莓派实现温控风扇智能降温
树莓派实现温控风扇智能降温
2022-06-27 23:58:00 【BluePROT】
树莓派带外壳,但是他一直转挺吵的,然后可以通过改造一下,让他可以变成一个可控的风扇,实现一个温控的功能
需要的材料
- 三极管S8550 PNP型:两块多五十个
- 杜邦线母对母
- 杜邦线公对母
这些tb都可以买到,有包邮的店铺
然后介绍一下这些东西
三极管把平面对着自己,有三个引脚,左到右分别是E、B、C。通俗说E是正极,C是负极,相当于二极管,基级B低电平才导通电路。
然后是树莓派引脚,有四十个引脚,这里可以看到有两种编码,在写代码的时候需要指定有什么编码方式,引脚的对应是把树莓派的网线插口朝下,对应的引脚顺序
接线方式
风扇的红色是正极,接在5V,4号引脚上
这里把三极管接在风扇的负极上,即风扇的黑色线连接三极管的C级
三极管的E级连接6号引脚,接地
三极管的基级B连接8号接口,也就是BCM编码的GPIO 14号引脚
连接好以后开机,在开机的过程中风扇好像会间歇性通电,问题不大。
开机以后,在python终端执行命令试试,首先需要安装一下库apt install RPi.GPIO
执行python
GPIO_OUT=14
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(GPIO_OUT,GPIO.OUT,initial=GPIO.HIGH)
self.Status=False
#启动
GPIO.output(GPIO_OUT,GPIO.LOW)
#关闭
GPIO.output(GPIO_OUT,GPIO.HIGH)
然后可以执行下面的命令查看树莓派的温度,输出的值除以1000就是当前的温度值
cat /sys/class/thermal/thermal_zone0/temp
最后,这是一个脚本,可以根据温度对风扇进行控制,温度超过50的时候开启,低于45的时候关闭,可以自行设置,这里还可以设置一个
import subprocess
import RPi.GPIO as GPIO
import time
class FanController:
def __init__(self,GPIO_PIN):
self.GPIO_OUT=GPIO_PIN
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(self.GPIO_OUT,GPIO.OUT,initial=GPIO.HIGH)
self.Status=False
def action(self,flag):
if flag=='start':
GPIO.output(self.GPIO_OUT,GPIO.LOW)
self.Status=True
elif flag=='stop':
GPIO.output(self.GPIO_OUT,GPIO.HIGH)
self.Status=False
def getTemp():
Temp=subprocess.getoutput('cat /sys/class/thermal/thermal_zone0/temp')
Temp=int(Temp)/1000
print(time.strftime('%Y-%m-%d %H:%M-%S')+'\ttemp is %s oC' % (str(Temp)))
return Temp
Fan=FanController(14)
print('start temp controller program')
while True:
Temp=getTemp()
if Temp>50 and not Fan.Status:
print('temp is higher than 50 , fan will start')
Fan.action('start')
elif Temp<45 and Fan.Status:
print('temp is less than 45 , fan will stop')
Fan.action('stop')
time.sleep(15)
参考链接
树莓派—利用三极管控制散热风扇
边栏推荐
猜你喜欢
评价——灰色关联分析
N methods of data De duplication using SQL
要搞清楚什么是同步,异步,串行,并行,并发,进程,线程,协程
9. Openfeign service interface call
万字长文看懂商业智能(BI)|推荐收藏
The research group of Xuyong and duanwenhui of Tsinghua University has developed an efficient and accurate first principles electronic structure deep learning method and program
什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?
基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
Interviewer asked: Inheritance of JS
Esxi based black Qunhui DSM 7.0.1 installation of VMware Tools
随机推荐
PV operation primitive
Meituan dynamic thread pool practice idea has been open source
AI+临床试验患者招募|Massive Bio完成900万美元A轮融资
pytorch_ lightning. utilities. exceptions. MisconfigurationException: You requested GPUs: [1] But...
【说明】Jmeter乱码的解决方法
Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known
Overview of drug discovery-01 overview of drug discovery
[description] solution to JMeter garbled code
Qu'est - ce que la numérisation? Qu'est - ce que la transformation numérique? Pourquoi les entreprises choisissent - elles la transformation numérique?
Esxi based black Qunhui DSM 7.0.1 installation of VMware Tools
面试官问:JS的this指向
Some habits of making money in foreign lead
Ten thousand words long article understanding business intelligence (BI) | recommended collection
The practice of dual process guard and keeping alive in IM instant messaging development
Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)
面试官问:能否模拟实现JS的new操作符
How to read a paper
9. Openfeign service interface call
Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
1382. 将二叉搜索树变平衡-常规方法