# 參考連結

# 溫度與濕度感測器

溫度與濕度感測器參考連結
#include <DHT.h> // 匯入程式庫 DHT sensor library
#include <DHT_U.h>
#define DHTPIN 2 // DHT pin 2 連接 Arduino pin 2
#define DHTTYPE DHT11 // 適用 DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(9600);
  Serial.println(F("DHT11 test!"));
  dht.begin();
}
void loop() {
  delay(2000);                     // 等 2 秒鐘
  float h = dht.readHumidity();    // 讀取濕度值 h
  float t = dht.readTemperature(); // 讀取攝氏溫度值 t
  if (isnan(h) || isnan(t)) {      // 如果讀不到數值,印出讀取失敗訊息
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print("Humidity: "); // 在序列埠螢幕中印出濕度、攝氏溫度
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C \n");
}

# LED 閃燈

用程式控制LEDArduino入門第三篇
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
  digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                // wait for a second
  digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
}
Edited on