Arduino温度传感器之继电器控制风扇程序代码
//模拟信号端⼝
int tempPin= 1;
//数字输出端⼝
int outpoint = 8;
//温度预定值
int temperature = 30;
void setup()
{
Serial.begin(9600);
pinMode(outpoint,OUTPUT);
html代码转链接}
void loop()
{
int val;
val =analogRead(tempPin);
float cel=val/9.31;
float farh=(cel*9)/5+32;
Serial.print("TEMPERATURE in CELCIUS="); //摄⽒温度
Serial.print(cel);
Serial.print("*C");
delay(5000);
Serial.println();
Serial.println("TEMPERATURE in FARHENHITE="); //华⽒温度
Serial.print(farh);
Serial.print("*F");
delay(5000);
Serial.println();
if (cel>temperature) {
Serial.println("Its a hot day");
//开启风扇
digitalWrite(outpoint, HIGH);
}
else {
Serial.println("Good day to be alive");
//关闭风扇
digitalWrite(outpoint, LOW);
}
delay(2000);
Serial.println();
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论