(SKU:RB-02S014)DHT11 Temperature Humidity Sensor

From ALSRobot-Wki
Jump to: navigation, search
P-789.jpg

Contents

An overview of the

DHT11 digital temperature and humidity sensor is a contains has been calibrated digital composite signal output of the temperature and humidity sensor. It dedicated digital module acquisition technology and the temperature and humidity sensor technology, ensure that the product has a very high reliability and excellent long-term stability. Sensor consists of a resistance type moisture element and a NTC temperature measuring element, and connected to a high-performance 8-bit microcontroller. So the product has excellent quality, super fast response, strong anti-interference ability, extremely high performance-price ratio. Every DHT11 sensor in extremely precise humidity calibration laboratory calibration. Calibration coefficient in the form of a program stored in the OTP memory, inside the sensor in the process of detecting signal processing to invoke the calibration coefficient. Single wire serial interface, the system integration becomes simple and fast. Super small volume, low power consumption, signal transmission distance of 20 meters, making it a all kinds of optimal choice of even the most demanding applications. DHT11 digital temperature and humidity sensor module for 3 needle PH2.0 encapsulation, convenient connection.

specification

  1. power supply voltage:3V-5.5V
  2. Power supply current: the biggest 2.5 mA
  3. Temperature range: 0-50 ℃ of error of plus or minus 2 ℃
  4. Humidity range: when the temperature 0 ℃ for 30 ~ 90% RH; When the environment temperature at 25 ℃ for 20 ~ 90% RH; When the environment temperature 50 ℃ for 20 ~ 80% RH
  5. response time: 1/e(63%) 6-30s
  6. Measurement resolution respectively 8 bit (temperature), 8 bit (humidity)
  7. Sampling time interval is not less than 1 second
  8. Module size:15mm×34mm

Using the method and example program

Pin definition

Is the definition of sensor pin

  • S:output signal
  • +:(VCC)
  • -:(GND)
P-22.jpg

Connection diagram

Dht11jiexian.jpg

sample code

Using the sensor cable of the extension of the humidity sensor is connected to the Arduino board simulation on port 0 as shown in the diagram. And then download the compiled code to the Arduino, could be on the serial port assistant window displays the current value of measured (note: Arduino assistant serial port baud rate is set to 19200).
Arduino experimental code is as follows:
#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);
}

Application effect

Download after compile the code to the Arduino, open the serial port assistant to see the actual measurement of the temperature and humidity.

Application of routine

We use the Arduino controller to do a test to use hardware equipment as follows:

  1. Arduino x 1 controller
  2. Arduino sensor extension plate x 1
  3. DHT11 temperature and humidity sensor moduleX 1
  4. Buzzer sound module x 1 和 LED Light module×1
  5. General 3 p sensor cable×3
  6. USB data communication line×1
Dht13.jpg

As shown, using sensors extension cable connect humidity sensor to the Arduino board simulation on port 0. For testing when you arrive at a certain temperature and humidity alarm can take our company buzzer and LED module is connected to the Numbers on the mouth. DHT11 library files to your first Arduino installation directory inside the hardware \ libraries (such as need DHT11 library file, please contact our customer service). And then download the compiled code to the Arduino, could be on the serial port assistant window displays the current value of measured (note: Arduino assistant serial port baud rate is set to 19200).

Arduino experimental code is as follows:
#define DHT11_PIN 0
int  Led=8;//定义数字口8为LED灯
int  Buzzer=7;//定义数字口7为蜂鸣器    
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);
  pinMode(Led,OUTPUT);//定义数字口Led为输出模式
  pinMode(Buzzer,OUTPUT); //定义数字口Buzzer为输出模式
	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  ");
  if(dht11_dat[0]==25) 判断湿度是否为25%
digitalWrite(Led,HIGH);//当湿度等于25%时LED灯亮
else
digitalWrite(Led,LOW); //当湿度不等于25%时LED灯灭

if(dht11_dat[0]==28) 判断温度是否为28度
digitalWrite(Buzzer,LOW); //当温度等于28度时蜂鸣器响
else
digitalWrite(Buzzer,HIGH); //当温度不等于28度时蜂鸣器不响
	delay(2000);
}

This code function is to detect the current environment of humidity and temperature. Set when the humidity is equal to 25% of LED lights, buzzer rang when the temperature is equal to 28 degrees. As shown in the figure below, a serial port assistant window on the left side of a column shows the right one for the current temperature value for the current humidity value.

Dht12.jpg

Products related to recommend

Buy address:DHT11

Personal tools
Namespaces

Variants
Actions
Navigation
Tools