(SKU:RB-02S014)DHT11温湿度传感器

来自ALSROBOT WiKi
2015年5月11日 (一) 11:0526wd讨论 | 贡献的版本

跳转至: 导航搜索
P-789.jpg

目录

概述

DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器。它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。传感器包括一个电阻式感湿元件和一个NTC测温元件,并与一个高性能8位单片机相连接。因此该产品具有品质卓越、超快响应、抗干扰能力强、性价比极高等优点。每个DHT11传感器都在极为精确的湿度校验室中进行校准。校准系数以程序的形式储存在OTP内存中,传感器内部在检测信号的处理过程中要调用这些校准系数。单线制串行接口,使系统集成变得简易快捷。超小的体积、极低的功耗,信号传输距离可达20米以上,使其成为各类应用甚至最为苛刻的应用场合的最佳选则。DHT11数字温湿度传感器模块为3针PH2.0封装。连接方便。

规格参数

  1. 供电电压:3V-5.5V
  2. 供电电流:最大2.5mA
  3. 温度范围:0-50℃ 误差±2℃
  4. 湿度范围:当环境温度在0℃时为30~90%RH
           当环境温度在25℃时为20~90%RH
当环境温度在25℃时为20~90%RH
当环境温度在25℃时为20~90%RH

产品图片和引脚定义

传感器引脚的定义是

  • 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数字温湿度传感器 http://www.alsrobot.cn/goods.php?id=72]