1. 程式人生 > >樹莓派風扇散熱自動控制

樹莓派風扇散熱自動控制

前言:

樹莓派3b 發熱量很大,需要加風扇以及散熱片散熱降溫,

但是市面上的風扇都很簡陋不能自動隨溫度變化而自動開啟或關閉降溫,浪費電能,且有不小的噪音。

為了解決以上問題,上網搜尋,發現有前人制作的經驗,雖能滿足以上要求,但又略顯不足,所以決定diy改進這個可以實現自動控制的簡單電路。

正文:

     使用的三極體是在萬能充上卸下來的 型號是8550


從舊電腦上拆下來的杜邦線母頭帶線

像這樣連線起來                                                           我使用了5V正極 GND gpio14(wiringpi 15)三個引腳


接線方法


以下是驅動程式碼(注意縮排)


#!/usr/bin/python2
#coding:utf8
 #自動風扇控制程式,使用wiringPi的gpio命令來操作GPIO
import commands,time
#控制風扇的GPIO
FAN_GPIO = 15
commands.getoutput('sudo gpio mode '+str(FAN_GPIO)+' OUTPUT')
while True:
     # 獲取CPU溫度
    tmpFile = open( '/sys/class/thermal/thermal_zone0/temp' )
    cpu_temp_raw = tmpFile.read()
    tmpFile.close()
    cpu_temp = round(float(cpu_temp_raw)/1000, 1)
    print (cpu_temp)
 
    #如果溫度大於47`C,就啟動風扇
    if cpu_temp >= 47 :
        commands.getoutput('sudo gpio write '+str(FAN_GPIO)+' 0')
    #如果溫度小於40`C,就關閉風扇
    if cpu_temp <= 40 :
        commands.getoutput('sudo gpio write '+str(FAN_GPIO)+' 1')
    
    time.sleep(10)

參考資料

PNP型              我用的就是S8550 pnp型三級管

前人部落格

gpio控制風扇轉速 pwm方案

 
設計草稿
友情連結:、https://blog.newnius.com/raspberry-control-fan-with-transistor.htmlhttp://blog.csdn.net/qq_37887537/article/details/78396555