Overview
The DHT11 temperature and humidity sensor features a temperature and humidity sensor
complex with a calibrated digital signal output. By using the exclusive digital-signal-acquisition
technique and temperature and humidity sensing technology, it ensures high reliability and
excellent long-term stability. This sensor includes a resistive-type humidity measurement
component and an NTC temperature measurement component, and connects to a high performance 8-bit micro-controller, offering excellent quality, fast response, anti-interference
ability and cost-effectiveness.
DHT11 Humidity & Temperature Sensor |
Parameters
Relative Humidity
Resolution: 16Bit
Repeatability: ±1%RH
Accuracy: 25℃ ±5%RH
Interchangeability: Fully interchangeable
Response time: 1/e (63%)25℃ 6s
1m/s Air 6s
Hysteresis: <±0.3%RH
Long-term stability: <±0.5%RH/yr
Temperature
Resolution: 16Bit
Repeatability: ±1℃
Accuracy: 25℃ ±2℃
Response time: 1/e (63%) 10S
Electrical Characteristics
Power supply: DC 3.3~ 5.5V
Supply current: Measure 0.3mA Standby 60μA
Sampling period: Secondary Greater than 2 seconds
Micro-controller Interfacing
This sensor uses only one bidirectional pin to accept a start signal from the micro-controller. It will send back its serial data with 40 bits length to the micro-controller.
Typical Application |
Bi-directional Serial Communication
The micro-controller output pin is in normal high logic standby mode. It must issue a start command by putting its data pin to low level around 18 milliseconds, and then the data pin must be pull up to high logic for 30 microseconds. DHT11 will send a low to high logic respond signal to micro-controller.
Overall Communication Process |
Micro-controller's data pin must be assigned to input direction to accept serial data from DHT11 sensor.
MCU sends out start signal and DHT11 responses
|
After this response signal, the sensor will send its serial data with 40 bits length. A low logic level of 50 microseconds indicates a start of each data bits. After that is a high logic level with two distinct duration that identify between 0's and 1's logic value of each data bits.
Data"0" Indication
|
Data "1" Indication |
Logic high with a duration around microseconds indicates a 1's data bit.
logic 0's and 1's values |
To sample this signal, the micro-controller should use a timer or a simple delay function to detect the duration of high logic signal.
Data Timing Diagram |
After the transmission of its 40 bits data, a low end time with a duration of 50 microseconds indicate the end of transmission. It will turn to logic high due to a pull up resistor.
Data Format
Its total data is 40 bits wide that include these data bytes,
- byte 0 - decimal humidity value
- byte 1 - empty humidity value
- byte 2 - decimal temperature value
- byte 4 - empty temperature value
- byte 5 - parity.
This sensor has only decimal humidity and temperature value. Its empty value data bytes are ignore.
It parity byte is useful for error checking. We can calculate as follow,
parity(byte 5) = byte 0 + byte 1 + byte 2 + byte 3
If this calculation is not verified then the micro-controller must read this sensor data again. For example, the sensor is read 53RH (humidity) and 24 degree Celsius (temperature) with a parity of 77 (in binary 0100 1101). We can calculate it as below,
Parity Check |
0011 0101 + 0000 0000 + 0001 1000 + 0000 0000 = 0100 1101
This 40-bit data is correct. So we can use it.
Micro-controller Interfacing And Programming
A simple 8-bit micro-controller could command and decode the serial data from this sensor easily. A 8051 micro-controller could interface with this sensor with a simple display output. The firmware require a little space of micro-controller program memory space.
Program Simulation |
A simple 8-bit PIC micro-controller is suitable for this task, due to a little amount of I/O, small footprint, and a reasonable amount of RAM and ROM space. I use a PIC16F84A micro-controller. This controller has only digital I/O, without analog I/O and communication module. We don't need these peripheral here. I use Proteus VSM to simulate this sample program because this micro-controller was burn out a long time ago. I will not buy it more. Currently there are a lot of newly designed controllers from Microchip Technology with rich peripherals and low cost.
Sample Serial Data |
We can see its serial data transmission over the virtual DSO screen of the simulator. To check this serial signal without a micro-controller we can use a switch instead with an oscilloscope. We just press the switch to make low signal and the release it. The output serial data of this sensor will be sent out.
/* * PIC16F84A DHT11 Temperature and Humidity Sensor Interfacing * With HD44780 Character LCD * MPLABX IDE v1.51 * XC8 v2.36 */ #include <xc.h> #include "LCD4Bits.h" #define _XTAL_FREQ 4000000UL #define DATA_PIN RA4 #define DATA_DIR TRISA4 uint8_t data[5]; void readDHT11(void){ for(uint8_t i=0;i<5;i++) data[i]=0; DATA_DIR=0; DATA_PIN=1; __delay_ms(10); DATA_PIN=0; __delay_ms(18); DATA_PIN=1; __delay_us(30); DATA_PIN=0; DATA_DIR=1; __delay_us(10); while(DATA_PIN==0); __delay_us(10); while(DATA_PIN==1); __delay_us(10); //Start of Transmission for(uint8_t i=0;i<5;i++) { for(uint8_t j=0;j<8;j++){ __delay_us(5); while(DATA_PIN==0); __delay_us(50); if(DATA_PIN==1) { data[i]|=(1<<7-j);} } __delay_us(10); } /*CRC Calculation - the last byte data[4] is check sum*/ uint8_t crc = data[0]+data[1]+data[2]+data[3]; if(crc!=data[4]) {for(uint8_t i=0;i<4;i++) data[i]=0; return;} __delay_us(10); } int main(void){ PORTA=0; TRISA=0; PORTB=0; TRISB=0; lcdInit(); lcdXY(1,1); lcdString("Humidity : "); lcdXY(1,2); lcdString("Temperature: "); while(1){ readDHT11(); lcdXY(13,1); /*Humidity is below 90RH*/ if(data[0]>=10) lcdData(48+(data[0]%100)/10); lcdData(48+(data[0]%10)); lcdData('R'); lcdData('H'); /*Temperature is below 50 degree Celsius*/ lcdXY(13,2); if(data[2]>=10) lcdData(48+data[2]/10); lcdData(48+(data[2]%10)); lcdData(223); lcdData('C'); __delay_ms(500); } return 0; }
Built program uses only 50% of program memory. We can add a few switches and an output relay or transistor to set the a temperature condition with an output device (an AC or DC fan).
MPLABX IDE Build Output |
No comments:
Post a Comment