(SKU:RB-02S014)DHT11溫濕度傳感器

來自ALSROBOT WiKi
2015年5月11日 (一) 11:1826wd討論 | 貢獻的版本

跳轉至: 導航搜索
P-789.jpg

目錄

概述

DHT11數(shù)字溫濕度傳感器是一款含有已校準數(shù)字信號輸出的溫濕度復合傳感器。它應用專用的數(shù)字模塊采集技術和溫濕度傳感技術,確保產品具有極高的可靠性與卓越的長期穩(wěn)定性。傳感器包括一個電阻式感濕元件和一個NTC測溫元件,并與一個高性能8位單片機相連接。因此該產品具有品質卓越、超快響應、抗干擾能力強、性價比極高等優(yōu)點。每個DHT11傳感器都在極為精確的濕度校驗室中進行校準。校準系數(shù)以程序的形式儲存在OTP內存中,傳感器內部在檢測信號的處理過程中要調用這些校準系數(shù)。單線制串行接口,使系統(tǒng)集成變得簡易快捷。超小的體積、極低的功耗,信號傳輸距離可達20米以上,使其成為各類應用甚至最為苛刻的應用場合的最佳選則。DHT11數(shù)字溫濕度傳感器模塊為3針PH2.0封裝,連接方便。

規(guī)格參數(shù)

  1. 供電電壓:3V-5.5V
  2. 供電電流:最大2.5mA
  3. 溫度范圍:0-50℃ 誤差±2℃
  4. 濕度范圍:當環(huán)境溫度在 0 ℃時為30~90%RH;當環(huán)境溫度在25℃時為20~90%RH ;當環(huán)境溫度在50℃時為20~80%RH
  5. 響應時間: 1/e(63%) 6-30s
  6. 測量分辨率分別為 8bit(溫度)、8bit(濕度)
  7. 采樣周期間隔不得低于1秒鐘
  8. 模塊尺寸:15mm×34mm

使用方法及例子程序

引腳定義

傳感器引腳的定義是

  • S:輸出信號
  • +:電源(VCC)
  • -:地(GND)
引腳的定義是

連接示意圖

P-33.jpg

示例代碼

使用傳感器連接線將濕度傳感器連接到Arduino傳感器擴展板的模擬口0 上如示意圖所示。然后將代碼編譯后下載到 Arduino里,就可以在串口助手窗口上顯示測得的當前值(注:Arduino串口助手波特率調到19200 )。Arduino實驗代碼如下。
式例代碼:
#define DHT11_PIN 0      // ADC0 UNO接到模擬口0   mega接PIN37
byte read_dht11_dat()
{
	byte i = 0;
	byte result=0;
	for(i=0; i< 8; i++){
	     while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
	     delayMicroseconds(30);
	     if(PINC & _BV(DHT11_PIN)) 
	     result |=(1<<(7-i));
             while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
	}
	return result;
}
void setup()
{
	DDRC |= _BV(DHT11_PIN);
	PORTC |= _BV(DHT11_PIN);
	  Serial.begin(19200);
Serial.println("Ready");
	}
	
void loop()
{
	byte dht11_dat[5];
	byte dht11_in;
	byte i;
	// start condition
	// 1. pull-down i/o pin from 18ms
	PORTC &= ~_BV(DHT11_PIN);
	delay(18);
	PORTC |= _BV(DHT11_PIN);
	delayMicroseconds(40);
	DDRC &= ~_BV(DHT11_PIN);
	delayMicroseconds(40);
	dht11_in = PINC & _BV(DHT11_PIN);
	if(dht11_in){
		Serial.println("dht11 start condition 1 not met");
		return;
	}
	delayMicroseconds(80);
	dht11_in = PINC & _BV(DHT11_PIN);
	if(!dht11_in){
		Serial.println("dht11 start condition 2 not met");
		return;
	}
	delayMicroseconds(80);
	// now ready for data reception
	for (i=0; i<5; i++)
		dht11_dat[i] = read_dht11_dat();
	DDRC |= _BV(DHT11_PIN);
	PORTC |= _BV(DHT11_PIN);
  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
	// check check_sum
	if(dht11_dat[4]!= dht11_check_sum)
	{
		Serial.println("DHT11 checksum error");
	}
	Serial.print("Current humdity = ");
	Serial.print(dht11_dat[0], DEC);
	Serial.print(".");
	Serial.print(dht11_dat[1], DEC);
	Serial.print("%  ");
	Serial.print("temperature = ");
	Serial.print(dht11_dat[2], DEC);
	Serial.print(".");
	Serial.print(dht11_dat[3], DEC);
	Serial.println("C  ");
	delay(2000);
}

程序效果

編譯代碼后下載到Arduino中,打開串口助手即可看見實際測量的溫度與濕度。

P-44.jpg

產品相關推薦

→視頻演示 運用Arduino DHT11溫濕度傳感器制作溫濕度報警器]
→購買地址 DHT11數(shù)字溫濕度傳感器 http://gharee.com/goods.php?id=72]