風(fēng)扇速度由溫度和Arduino控制
出處:維庫(kù)電子市場(chǎng)網(wǎng) 發(fā)布于:2024-08-01 17:41:32 | 389 次閱讀
LM35 數(shù)據(jù)表
Arduino草圖
#include <LiquidCrystal.h>
//source: https://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/
LiquidCrystal lcd(7,6,5,4,3,2);
int tempPin = A1; // the output pin of LM35
int fan = 11; // the pin where fan is
int led = 8; // led pin
int temp;
int tempMin = 30; // the temperature to start the fan
int tempMax = 70; // the maximum temperature when fan is at 100%
int fanSpeed;
int fanLCD;
void setup() {
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
lcd.begin(16,2);
}
void loop() {
temp = readTemp(); // get the temperature
if(temp < tempMin) { // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
digitalWrite(fan, LOW);
}
if((temp >= tempMin) && (temp <= tempMax)) { // if temperature is higher than minimum temp
fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan
fanLCD = map(temp, tempMin, tempMax, 0, 100); // speed of fan to display on LCD
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
}
if(temp > tempMax) { // if temp is higher than tempMax
digitalWrite(led, HIGH); // turn on led
} else { // else turn of led
digitalWrite(led, LOW);
}
lcd.print("TEMP: ");
lcd.print(temp); // display the temperature
lcd.print("C ");
lcd.setCursor(0,1); // move cursor to next line
lcd.print("FANS: ");
lcd.print(fanLCD); // display the fan speed
lcd.print("%");
delay(200);
lcd.clear();
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125; }
我使用LCD屏蔽來(lái)顯示風(fēng)扇的當(dāng)前溫度和速度,但是您可以使用沒(méi)有LCD顯示器的電路。您還需要根據(jù)您使用的風(fēng)扇類(lèi)型來(lái)選擇晶體管。就我而言,我使用著名的 BD139 晶體管和 9V 電池為風(fēng)扇和晶體管供電。LM35 溫度傳感器和紅色 LED 由 Arduino 板的 5V 電壓供電。
電路是如何工作的?
正如您在第一行的草圖中看到的,我包含了 LiquidCrystal 庫(kù)(標(biāo)頭),其中包含在將 LCD 連接到 Arduino 板時(shí)可以使用的有用功能。然后,我為傳感器、LED 和風(fēng)扇設(shè)置了引腳。
最重要的部分是使用所需的值設(shè)置變量 tempMin 和 tempMax。tempMin 是風(fēng)扇開(kāi)始旋轉(zhuǎn)的溫度,tempMax 是紅色 LED 燈警告您已達(dá)到最高溫度時(shí)的溫度。例如,如果將 tempMin 設(shè)置為 30,將 tempMax 設(shè)置為 35,則風(fēng)扇將在 30°C 時(shí)開(kāi)始旋轉(zhuǎn),并在 35°C 時(shí)達(dá)到其最高速度。
將溫度值存儲(chǔ)在 temp 變量中,然后使用一些 if() 函數(shù)來(lái)檢查溫度是否低于 tempMin,如果是,則讓風(fēng)扇關(guān)閉 (LOW)。下一個(gè) if() 是檢查溫度是否高于 minTemp 并低于 tempMax,如果是,則使用 map() 函數(shù)將溫度值從一個(gè)值重新映射到另一個(gè)值。在我們的例子中,fanSpeed 在 tempMin 的值為 32,在 tempMax 的值為 255。這些值用于通過(guò) PWM 和 analogWrite() 控制風(fēng)扇的速度。
風(fēng)扇LCD 重新映射溫度,允許在 0 到 100% 范圍內(nèi)顯示風(fēng)扇速度,因此您可以說(shuō)風(fēng)扇的速度直接取決于 LM35 的溫度。當(dāng)溫度達(dá)到 tempMax 中設(shè)置的值時(shí),風(fēng)扇將處于其最大旋轉(zhuǎn)速度,并且 LCD 將顯示 FANS:100%,即使溫度可能會(huì)升高到 tempMax 以上。
版權(quán)與免責(zé)聲明
凡本網(wǎng)注明“出處:維庫(kù)電子市場(chǎng)網(wǎng)”的所有作品,版權(quán)均屬于維庫(kù)電子市場(chǎng)網(wǎng),轉(zhuǎn)載請(qǐng)必須注明維庫(kù)電子市場(chǎng)網(wǎng),http://www.udpf.com.cn,違反者本網(wǎng)將追究相關(guān)法律責(zé)任。
本網(wǎng)轉(zhuǎn)載并注明自其它出處的作品,目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點(diǎn)或證實(shí)其內(nèi)容的真實(shí)性,不承擔(dān)此類(lèi)作品侵權(quán)行為的直接責(zé)任及連帶責(zé)任。其他媒體、網(wǎng)站或個(gè)人從本網(wǎng)轉(zhuǎn)載時(shí),必須保留本網(wǎng)注明的作品出處,并自負(fù)版權(quán)等法律責(zé)任。
如涉及作品內(nèi)容、版權(quán)等問(wèn)題,請(qǐng)?jiān)谧髌钒l(fā)表之日起一周內(nèi)與本網(wǎng)聯(lián)系,否則視為放棄相關(guān)權(quán)利。
- 如何使用多相轉(zhuǎn)換器平衡電流
- 液晶電視機(jī)電路結(jié)構(gòu)的關(guān)鍵要點(diǎn)
- LTC4365 如何實(shí)現(xiàn)敏感電路過(guò)壓與反接保護(hù)
- 單鍵開(kāi)關(guān)機(jī)電路與輕觸開(kāi)關(guān)的創(chuàng)新設(shè)計(jì)解析
- MOS 管邏輯電路五種門(mén)電路特性
- LM317:高效構(gòu)建電壓源及電流源電路方案
- 3.3V - 1.8V 電平雙向轉(zhuǎn)換:多場(chǎng)景配置及獨(dú)特優(yōu)勢(shì)剖析
- 詳解防反接電路實(shí)現(xiàn)過(guò)程,聚焦電路電流回路核心
- 雙聲道揚(yáng)聲器保護(hù)電路:設(shè)計(jì)要點(diǎn)與電路圖詳解
- 深度剖析 2.4W 功耗的 LED 交流節(jié)能燈電路設(shè)計(jì)