本實驗為了讓Arduino開發板簡化使用,使用了圖 42的DHT11溫濕度感測模組DHT11溫濕度感測模組,本模組只要將Vcc接到Arduino開發板+5V腳位,Gnd接到Arduino開發板Gnd腳位,DataVcc接到Arduino開發板Digital Input 腳位2,接腳圖見表 5(參考表 5之Arduino開發板外部插斷接腳圖,詳細內容請參閱http://arduino.cc/en/Reference/AttachInterrupt),並執行下列程式,若讀者想要自行阻立DHT11溫濕度感測器的線路,可以參閱圖 43的DHT11溫濕度感測器與單晶片開發板連接線路圖。
Board
|
int.0
|
int.1
|
int.2
|
int.3
|
int.4
|
int.5
|
Uno, Ethernet
|
2
|
3
|
|
|
|
|
Mega2560
|
2
|
3
|
21
|
20
|
19
|
18
|
Leonardo
|
3
|
2
|
0
|
1
|
7
|
|
DHT11溫濕度感測模組
|
Arduino開發板接腳
|
解說
|
Data
|
Arduino digital Input pin 2
|
DHT11資料輸出腳位
|
5V
|
Arduino pin 5V
|
5V 陽極接點
|
GND
|
Arduino pin Gnd
|
共地接點
|
其餘關於DHT11溫濕度感測器的細部資料,本書使用的DHT-11函式庫,是採用網路上Nicolas(niesteszeck@gmail.com)針對DHT11 Temperature and Humidity Sensor所攥寫的Arduino
library,Nicolas在GitHub, Inc.撰寫之程式碼(GitHub, 2013),其下載網址為:https://github.com/niesteszeck/idDHT11,特此感謝分享請參閱與單晶片開發板連接線路簡圖
本文中DHT測試程式,為參考Nicolas(niesteszeck@gmail.com)針對DHT11 Temperature and Humidity
Sensor所攥寫的Arduino librar,其中所附的範例程式idDHT11_Lib_example所改寫得程式,其下載網址為:https://github.com/niesteszeck/idDHT11,特此感謝分享
DHT11溫濕度感測器讀取溫濕度測試程式(DHT_11_test1)
|
/*
Board
int.0 int.1 int.2 int.3 int.4 int.5
Uno,
Ethernet 2 3
Mega2560 2
ZX
3 21 20 19 18
Leonardo 3 2 0 1
Due
(any pin, more info http://arduino.cc/en/Reference/AttachInterrupt)
This
example, as difference to the other, make use of the new method acquireAndWait()
*/
// use digital pin 2 to connect DHT-11 data pin
#include <idDHT11.h>
int idDHT11pin = 2; //Digital pin for
comunications
int idDHT11intNumber = 0; //interrupt number
(must be the one that use the previus defined pin (see table above)
//declaration
void dht11_wrapper(); // must be declared before
the lib initialization
// Lib instantiate
idDHT11
DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
void setup()
{
Serial.begin(9600);
Serial.println("idDHT11 Example program");
Serial.print("LIB version: ");
Serial.println(IDDHT11LIB_VERSION);
Serial.println("---------------");
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht11_wrapper() {
DHT11.isrCallback();
}
void loop()
{
Serial.print("\nRetrieving information from sensor: ");
Serial.print("Read sensor: ");
//delay(100);
int
result = DHT11.acquireAndWait();
switch
(result)
{
case
IDDHTLIB_OK:
Serial.println("OK");
break;
case
IDDHTLIB_ERROR_CHECKSUM:
Serial.println("Error\n\r\tChecksum
error");
break;
case
IDDHTLIB_ERROR_TIMEOUT:
Serial.println("Error\n\r\tTime out error");
break;
case
IDDHTLIB_ERROR_ACQUIRING:
Serial.println("Error\n\r\tAcquiring");
break;
case
IDDHTLIB_ERROR_DELTA:
Serial.println("Error\n\r\tDelta time to small");
break;
case
IDDHTLIB_ERROR_NOTSTARTED:
Serial.println("Error\n\r\tNot started");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println(DHT11.getHumidity(), 2);
Serial.print("Temperature (oC): ");
Serial.println(DHT11.getCelsius(), 2);
Serial.print("Temperature (oF): ");
Serial.println(DHT11.getFahrenheit(), 2);
Serial.print("Temperature (K): ");
Serial.println(DHT11.getKelvin(),
2);
Serial.print("Dew Point (oC): ");
Serial.println(DHT11.getDewPoint());
Serial.print("Dew Point Slow (oC): ");
Serial.println(DHT11.getDewPointSlow());
delay(2000);
}
|
資料來源:https://github.com/niesteszeck/idDHT11
由上述程式執行後,可以見到圖 44之DHT11簡單實驗畫面結果,也可以輕易讀到外界的溫度與濕度了。
有關於量測範圍、精確度對照表以及可校正性的資料嗎?
回覆刪除這個組件是自己包裝的,似乎我還沒有看到精確度對照表以及可校正性的資料
回覆刪除不過您可以看datasheet
http://www.adafruit.com/datasheets/DHT11-chinese.pdf
謝謝