};

void setup() {     
   lcd.begin(16, 2);                       // 設定LCD有2列16欄  
      Serial.begin(9600);                  //包率
}
void loop(){
  int chk = DHT11.read(DHT11PIN);          //檢查DHT感測器的回應  

  switch (chk){                   
     case 0:
     lcd.print("Humidity:");   
      lcd.print((float)DHT11.humidity, 1);       
     lcd.print("%");       
     lcd.setCursor(0, 1);       
     lcd.print("Tempure:");       
     lcd.print((float)DHT11.temperature, 1);       
     lcd.print("oC");     // 無法顯示度,只好用小寫的O表示       
           break;     
   case -1:       
     lcd.print("Checksum error");
     break;     
   case -2:       
     lcd.print("Time out error");
     break;     
   default:       
     lcd.print("Unknown error");
     break;   
    }  
   delay(1000);                         //延遲

if(  DHT11.temperature > 30){            //如溫度>30  發出單音
tone(BUZZER_PIN, NOTE_C5, 3000/4);
}
if( 10 < DHT11.temperature){                      //如溫度>10 做以下動作
                                                  //為了實驗此處修改溫度低標為10
                                                      //此處有音樂
  for (int thisNote = 0; thisNote < 8; thisNote++) {
      // 在 pin13 上輸出聲音,每個音階響 0.5 秒
        tone(13, melody[thisNote], duration);         
        // 間隔一段時間後再播放下一個音階
        delay(1000);
      }       
      // 兩秒後重新播放
      delay(2000);
}
if(50 < DHT11.humidity){                 //如濕度>50  發出單音
tone(BUZZER_PIN, NOTE_E5, 3000/4);
 }
}

arrow
arrow
    全站熱搜

    lkj2000168 發表在 痞客邦 留言(0) 人氣()