#Use case-1# How to supervise the temperature around your house

Product Picture:

System block diagram:

Hardware connection:



Summary:

Today, I would like to introduce the DHT11 sensor which is a very low-cost temperature and humidity composite sensor, it's very appropriate to supervise the temperature and humidity around your house.

Hardware Preparation:

  1. STM32F030 
  2. DHT11 DHT11 Datasheet
    • DHT11 digital temperature and humidity sensor is a composite Sensor contain 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.
  3. NRF24L01 NRF24L01 Datasheet (2.4G ISM module)
  4. ST-LINK V2 (Debugging)
  5. MicroUSB male cable (Power source)
Code architecture:


dht11.c
#include "dht11.h"
#include "delay.h"


 /*Reset DHT11*/
void DHT11_Rst(void)    
{                 
    DHT11_IO_OUT();  //Setting output
    DHT11_DQ_OUT(0);  //DQ pull down
    delay_ms(20);     //delay at least 18ms
    DHT11_DQ_OUT(1);  //DQ pull high
    delay_us(30);      //delay 20~40us
}

 /*Check DHT11*/
 /*Return 1:STM32 Can't detect DHT11 or other issues*/
 /*Return 0:DHT11 workable*/
u8 DHT11_Check(void)     
{   
    u8 retry=0;
    DHT11_IO_IN();      //Setting Input  
    while (DHT11_DQ_IN&&retry<100)//DHT11 PD at least 40~80us
 {
    retry++;
    delay_us(1);
 };  
    if(retry>=100)return 1;
    else retry=0;
    while (!DHT11_DQ_IN&&retry<100)//DHT11 will PD and PU 40~80us
 {
    retry++;
    delay_us(1);
 };
 if(retry>=100)return 1;     
 return 0;
}

 /*Read bit from DHT11*/
 /*Return 1/0*/
u8 DHT11_Read_Bit(void)     
{
    u8 retry=0;
    while(DHT11_DQ_IN&&retry<100)//wait for low level
 {
  retry++;
  delay_us(1);
 }
    retry=0;
    while(!DHT11_DQ_IN&&retry<100)//wait for high level
 {
  retry++;
  delay_us(1);
 }
    delay_us(40);//waitting 40us
    if(DHT11_DQ_IN)return 1;
    else return 0;     
}





















留言