標題: DIY的一個溫度報警器 [打印本頁]

作者: giatol    時間: 2022-10-20 15:44
標題: DIY的一個溫度報警器
自己做的一個溫度報警器,達到30度蜂鳴器就會響,新手勿噴

void setup() {
  
  Serial.begin(9600);         //使用9600速率進行串口通訊
}

void loop() {

  int n = analogRead(A0);    //讀取A0口的電壓值

  float vol = n * (5.0 / 1023.0*100);   //使用浮點數(shù)存儲溫度數(shù)據(jù),溫度數(shù)據(jù)由電壓值換算得到

  Serial.println(vol);                   //串口輸出溫度數(shù)據(jù)
  delay(2000);                           //等待2秒,控制刷新速度
  if (vol>=30)
{ for(int i=200;i<=800;i++)                    //用循環(huán)的方式將頻率從200HZ 增加到800HZ
{
  pinMode(4,OUTPUT);
  tone(4,i);                            //在四號端口輸出頻率
delay(5);                              //該頻率維持5毫秒   
}
delay(4000); //最高頻率下維持4秒鐘


for(int i=800;i>=200;i--)
{
  pinMode(4,OUTPUT);
  tone(4,i);
delay(10);
}
}

}







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1