The KY-015 Temperature and Humidity Sensor Module is based on the DHT11
DHT11 digital temperature and humidity sensor is a composite Sensor contains a calibrated digital signal output of the temperature and humidity. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability.
The sensor includes a resistive sense of wet components and an NTC temperature measurement devices, and connected with a high-performance 8-bit microcontroller.
Relative humidity
Resolution: 16Bit
Repeatability: ±1% RH
Accuracy: At 25℃ ±5% RH
Interchangeability: fully interchangeable
Response time: 1 / e (63%) of 25℃ 6s
1m / s air 6s
Hysteresis: <± 0.3% RH
Long-term stability: <± 0.5% RH / yr in
Temperature
Resolution: 16Bit
Repeatability: ±0.2℃
Range: At 25℃ ±2℃
Response time: 1 / e (63%) 10S
Electrical Characteristics
Power supply: DC 3.5~5.5V
Supply Current: measurement 0.3mA standby 60μ A
Sampling period: more than 2 seconds
Connection
Connect the Power line (middle) and ground (-) to +5 and GND respectively. Connect signal (S) to pin A0 on the Arduino.
| KY-015 | Arduino | 
| S | Pin A0 | 
| middle | +5V | 
| – | GND | 
Code
[codesyntax lang=”cpp”]
#define dht_dpin A0
byte bGlobalErr;
byte dht_dat[5];
void setup(){
InitDHT();
Serial.begin(9600);
delay(300);
Serial.println("Humidity and temperature\n\n");
delay(700);
}
void loop(){
 ReadDHT();
 switch (bGlobalErr){
 case 0:
 Serial.print("Current humdity = ");
 Serial.print(dht_dat[0], DEC);
 Serial.print(".");
 Serial.print(dht_dat[1], DEC);
 Serial.print("% ");
 Serial.print("temperature = ");
 Serial.print(dht_dat[2], DEC);
 Serial.print(".");
 Serial.print(dht_dat[3], DEC);
 Serial.println("C ");
 break;
 case 1:
 Serial.println("Error 1: DHT start condition 1 not met.");
 break;
 case 2:
 Serial.println("Error 2: DHT start condition 2 not met.");
 break;
 case 3:
 Serial.println("Error 3: DHT checksum error.");
 break;
 default:
 Serial.println("Error: Unrecognized code encountered.");
 break;
 }
 delay(800);
}
void InitDHT(){
 pinMode(dht_dpin,OUTPUT);
 digitalWrite(dht_dpin,HIGH);
}
void ReadDHT(){
bGlobalErr=0;
byte dht_in;
byte i;
digitalWrite(dht_dpin,LOW);
delay(20);
digitalWrite(dht_dpin,HIGH);
delayMicroseconds(40);
pinMode(dht_dpin,INPUT);
//delayMicroseconds(40);
dht_in=digitalRead(dht_dpin);
if(dht_in){
 bGlobalErr=1;
 return;
 }
delayMicroseconds(80);
dht_in=digitalRead(dht_dpin);
if(!dht_in){
 bGlobalErr=2;
 return;
 }
delayMicroseconds(80);
for (i=0; i<5; i++)
 dht_dat[i] = read_dht_dat();
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,HIGH);
byte dht_check_sum =
 dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];
if(dht_dat[4]!= dht_check_sum)
 {bGlobalErr=3;}
};
byte read_dht_dat(){
 byte i = 0;
 byte result=0;
 for(i=0; i< 8; i++){
 while(digitalRead(dht_dpin)==LOW);
 delayMicroseconds(30);
 if (digitalRead(dht_dpin)==HIGH)
 result |=(1<<(7-i));
 while (digitalRead(dht_dpin)==HIGH);
 }
 return result;
}
[/codesyntax]
Links
37 in 1 box Sensor Kit For Arduino Starters brand in stock

