今天測試第一個sensor是DHT11 溫溼度感測
參考這篇文章
http://ming-shian.blogspot.tw/2014/05/arduino19dht...
DHT11的電壓從3v~5V,我選擇用3.3V
由於是數位訊號,就隨便選一個pin
我是定義pin 24
程式如下:
#include <dht.h>
#define dht_dpin 24 //定義訊號要從Pin 24 進來
dht DHT;
void setup() {
Serial.begin(9600);
delay(1000); //Let system settle
Serial.println("Humidity and temperature\n\n");
delay(1000); //Wait rest of 1000ms recommended delay before
//accessing sensor
}
void loop() {
DHT.read11(dht_dpin); //去library裡面找DHT.read11
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(2000); //每1000ms更新一次
}
上傳時又出問題了,錯誤訊息如下:
GetFileAttributesEx D:\arduino\libraries\DHT\dht.cpp D:\arduino\libraries\DHT\dht.h: The filename, directory name, or volume label syntax is incorrect.
只要將目錄的名稱DHT隨便改一個名字就OK
改成TemperatureandHumidity,
結果如下
留言列表