1, Product overview
DHT11 digital temperature and humidity sensor is a temperature and humidity composite sensor with calibrated digital signal output. It uses special digital module acquisition technology and temperature and humidity sensing technology to ensure the product has high reliability and excellent long-term stability. The sensor consists of a resistance type humidity sensing element and a NTC temperature measuring element, and is connected with a high-performance 8-bit single chip microcomputer. Therefore, the product has the advantages of excellent quality, super fast response, strong anti-interference ability and high cost performance. Each DHT11 sensor is calibrated in an extremely accurate humidity calibration chamber. The calibration coefficients are stored in OTP memory in the form of program, and these calibration coefficients are called in the process of detection signal processing inside the sensor. Single line serial interface makes system integration easy and fast. Ultra small volume, very low power consumption, signal transmission distance can be more than 20 meters, making it the best choice for all kinds of applications and even the most demanding applications. The product is 4-pin single row pin package. The connection is convenient, and the special packaging form can be provided according to the user's requirements.
2, Product parameters
2.1 schematic diagram
2.2 package information
2.3 pin description
2.4 sensor performance description
2.5 typical application circuit
3, Description of working sequence diagram of sensor
3.1 preparation before sending data
The idle state of the bus is high. The host pulls the bus low and waits for DHT11 to respond. The host pulls the bus low for more than 18 milliseconds to ensure that DHT11 can detect the starting signal. After receiving the start signal of the host, DHT11 waits for the end of the start signal of the host, and then sends 80us low-level response signal. After the end of the start signal of the host, it waits for 20-40us in delay, and reads the response signal of DHT11. After the host sends the start signal, it can switch to the input mode, or the output high-power average can be, and the bus is pulled high by the pull-up resistance.
3.2 communication process
A complete data transmission is 40 bit, high bit first out. Data format: 8bit humidity integer data + 8bit humidity decimal data + 8bi temperature integer data + 8bit temperature decimal data + 8bit check sum. When the data transmission is correct, the check sum data is equal to the last 8 digits of the result of "8 bit humidity integer data + 8 bit humidity decimal data + 8 Bi temperature integer data + 8 bit temperature decimal data".
After the user MCU sends a start signal, DHT11 switches from low-power mode to high-speed mode. After waiting for the host start signal to end, DHT11 sends a response signal, sends out 40 bit data, and triggers a signal acquisition. The user can choose to read part of the data. In the mode, DHT11 receives a start signal and triggers a temperature and humidity acquisition. If it does not receive a start signal sent by the host, DHT11 will not actively collect temperature and humidity. After collecting data, it will switch to low-speed mode.
4, Routine (routines are written by themselves and are verified to be successful)
/*The model of single chip microcomputer used is STC89C52RC, the crystal oscillator is 11.0592MHz *, and the measured temperature and humidity are displayed by 8 digital tubes from low position to high position/
4.1 header file, subfunction declaration, variable declaration, etc
#include<reg51.h> #include<intrins.h> #define ERROR 0 #define OK 1 typedef unsigned char unchar; typedef unsigned int unint; sbit Bus=P2^2;//data bus unchar value[5];//Store test values unint check; void Delay10us(void); void Delay20ms(void); void Delay1s(void); unchar Read_Temp(); void show(int x); //Power on needs to pass the instability period of 1s, and the test interval cannot be less than 1s //High first out when reading //The check sum is equal to the lower octet of the first four bytes //The decimal part of temperature and humidity is used for expansion, and the current output is 0
4.2 temperature and humidity reading function
unchar Read_Temp() { unchar i,j=0,mask; Bus=0;//The host is pulled down actively and lasts for 20ms (more than 18ms) Delay20ms(); Bus=1;//The main engine then actively raises 40us (20-40us) Delay10us(); Delay10us(); Delay10us(); Delay10us(); if(Bus==1)//If the bus is not responding { return ERROR; } else //If the bus responds { while(!Bus);//Waiting for low response of bus (80us) while(Bus);//Waiting for high response of bus (80us) while(j<5) { mask=0x80; for(i=0;i<8;i++)//Receive one byte at a time { while(!Bus);//Waiting for a low level gap Delay10us();//0 keeps the high level of 26-28us, 1 keeps the high level of 70us, and the level monitoring at 40us is taken Delay10us(); Delay10us(); Delay10us(); if(Bus==0) { value[j]&=(~mask); } else { value[j]|=mask; } mask>>=1; while(Bus);//Wait for the bit transfer to end } j++;//Continue to accept next byte } } check=(value[0]+value[2])&0x00ff;//Check Summing if(check==value[4])//If the checksums are correct { return OK; } else { return ERROR; } }
4.3 digital tube display subfunction
void show(int x) { while(x>0) { switch(x%10) { case 0:P0=0xc0;break; case 1:P0=0xf9;break; case 2:P0=0xa4;break; case 3:P0=0xb0;break; case 4:P0=0x99;break; case 5:P0=0x92;break; case 6:P0=0x82;break; case 7:P0=0xf8;break; case 8:P0=0x80;break; case 9:P0=0x90;break; } x=x/10; Delay1s(); P0=0xff; Delay1s(); } }
4.4 delay subfunctions
/*10us Delay subfunction*/ void Delay10us() { unchar i; i=2; while(--i); } /*20ms Delay subfunction*/ void Delay20ms(void) //Error -0.000000000005us { unsigned char a,b,c; for(c=1;c>0;c--) for(b=222;b>0;b--) for(a=40;a>0;a--); } /*1s Delay subfunction*/ void Delay1s(void) //Error -0.000000000227us { unsigned char a,b,c; for(c=13;c>0;c--) for(b=247;b>0;b--) for(a=142;a>0;a--); _nop_(); //if Keil,require use intrins.h }
4.5 main function
int main() { unchar result,temp,hum; Delay1s();//Over 1s unstable period while(1) { result=Read_Temp(); if(result==OK) { temp=value[2]; hum=value[0]; show(temp); Delay1s(); show(hum); Delay1s(); Delay1s(); Delay1s(); } else { continue; } } return 0; }
Left shoulder ideal right shoulder responsibility, gentleman does not complain never stop!