第1步:您需要的零件
我用來執(zhí)行此操作的零件
·Genuino UNO
·溫度傳感器–關(guān)鍵部件
·1KΩ電阻器
·100μF/16V電容器
·PN2222A NPN晶體管–打開風扇的關(guān)鍵部分
·12V DC無刷風扇–關(guān)鍵部分
·1N4007二極管
·AC – DC插入適配器120VAC至12VDC
·液晶顯示器
·額外面包板
步驟2:示意圖
步驟3:源代碼//注釋
#include
// library for LCD LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float temp; // set temp as a whole number
int tempPin = A0; //arduino pin used for temperature sensor
int tempMin = 23; // the temperature to start the buzzer
int tempMax = 26; // temperature full speed
int fan = 6; // the pin where fan is connected
int fanSpeed = 0; // fan speed variable void setup() {
pinMode(fan, OUTPUT); // declaring fan pin 6 as output
pinMode(tempPin, INPUT); // declaring tempPin A0 as input
lcd.begin(16, 2); // LCD intialize
lcd.clear(); // clears lcd
lcd.print(“Fan Speed:”); // prints “Fan Speed” 50-255 PWM
lcd.setCursor(0,1); // Sets cursor for next line
lcd.print(“Temperature:”); // Prints “Temperature” below “Fan Speed”
Serial.begin(9600); // begins the serial monitor
} void loop() {
float voltage = (temp/1024)*5.0;
float temperature = (voltage - 0.5) * 100; // formula for degrees celcius
Serial.println(temperature); // prints temp in serial monitor
lcd.setCursor(12,1); // 12 character to the right on the first column
lcd.print(temperature); // prints the number on the 12 character
delay(1000); // delay in between reads for stability
if(temp 《 tempMin) { // if temp is lower than minimum temp
fanSpeed = 0; // fan is not spinning
digitalWrite(fan, LOW); // pin 6 output is low
}
if((temperature 》= tempMin) && (temperature 《= tempMax)) //if temperature is higher than the minimmum range
{
fanSpeed = map(temperature, tempMin, tempMax, 50, 255); // the actual speed of fan
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed
Serial.println(fanSpeed); // prints fan speed in serial monitor
lcd.setCursor(12,0); // sets cursor
lcd.print(fanSpeed); // prints
lcd.print(“ ”); // fixes an error of random number display
}
}
責任編輯:wv
-
溫控
+關(guān)注
關(guān)注
0文章
69瀏覽量
18810 -
風扇
+關(guān)注
關(guān)注
4文章
413瀏覽量
37422
發(fā)布評論請先 登錄
相關(guān)推薦
評論