1.1 Air temperature and humidity detection and alarm system based on stc89c51 series MCU

Air temperature and humidity detection and alarm system based on STC89C51 series microcontroller

overview

Today I will introduce to you an air temperature and humidity detection and alarm system based on the STC89C51 series microcontroller. This project combines single-chip microcomputer, DHT11 temperature and humidity module, LCD1602 display module, buttons, buzzer and other components to monitor the temperature and humidity of the environment in real time, and trigger an alarm when the set threshold is exceeded. Let's dig into the development process, hardware design, software implementation, and product introduction of this project.

Background of the project

In modern life, people pay more and more attention to the comfort and health of the indoor environment. Especially in alternating seasons or humid and rainy climates, the monitoring of ambient temperature and humidity is particularly important. In order to meet people's needs for indoor environment, we decided to develop a convenient and practical air temperature and humidity detection and alarm system. The system is designed to help users understand the ambient temperature and humidity conditions, and send out an alarm signal when the temperature and humidity are abnormal.

hardware design

1. STC89C51 microcontroller

STC89C51 is a cost-effective 8-bit microcontroller with powerful functions and stability, suitable for various application scenarios. We choose it as the control core, in order to process data and control peripherals.

2. DHT11 temperature and humidity module

DHT11 is a digital temperature and humidity sensor with the characteristics of low cost and easy to use. It communicates with the STC89C51 microcontroller through a single-wire serial interface, and can accurately measure the temperature and humidity of the environment.

3. LCD1602 display module

In order to facilitate the user to observe the temperature and humidity data intuitively, we use the LCD1602 display module. This is a 16x2 character liquid crystal display, which is connected to the STC89C51 single-chip microcomputer through a parallel interface, and can display information such as temperature and humidity.

4. Human-computer interaction module

In order to enhance the interactivity of the system, we have designed three buttons, which are mode switch button, threshold plus button and threshold minus button. Users can switch the working mode of the system and adjust the temperature and humidity alarm threshold by pressing the button. At the same time, we also added a buzzer as an alarm device.

5. Power module

In order to ensure the stable operation of the system, we have designed a suitable power module to provide stable voltage and current to each module in the system.

software design

1. Hardware initialization

In the early stage of software design, we carried out hardware initialization settings, including configuring STC89C51's I/O port, timer and serial port communication.

	F1602_init();
  	F1602_clear();
	timer0_init();
	DHT11_start();
	uart_init()	;
	TI = 1;
	SendString("welcome to temp sys");
	TI = 0;
	P22 = 0;

2. DHT11 data reading

In order to read the temperature and humidity data from the DHT11 sensor, we have written the corresponding function. The DHT11 sensor uses a single-wire serial communication protocol, so we need to send commands correctly and parse the data returned by the sensor.

void DHT11_receive()      
{
    
    
    uchar R_H,R_L,T_H,T_L,revise; 
    DHT11_start();
    if(Data==0)
    {
    
    
        while(Data==0);    
        DHT11_delay_us(40); 
        R_H=DHT11_rec_byte();   
        R_L=DHT11_rec_byte();   
        T_H=DHT11_rec_byte();      
        T_L=DHT11_rec_byte();    
        revise=DHT11_rec_byte(); 

        DHT11_delay_us(25);    

        if((R_H+R_L+T_H+T_L)==revise)      
        {
    
    
            RH=R_H;
            RL=R_L;
            TH=T_H;
            TL=T_L;
        } 

    }
}

3. Data display

The read temperature and humidity data need to be displayed on the LCD1602 display module. We have written a function to format the data and display it on the LCD screen, so that the user can observe the environmental information intuitively.

void display0()
{
    
    
		if(mode == 0)
		{
    
    
			gotoxy(1,0);			
			display_string("TH:");
			display_num(TH_set);	
			gotoxy(2,0);
			display_string("temp:");
			display_num(TH);	
			display_string(".");
			display_num(TL);	
		}
		if(mode == 1)
		{
    
    
			gotoxy(1,0);
			display_string("temp high:");					
			gotoxy(2,0);
			display_num(TH_set);			
		}
}

4. Alarm logic

In order to realize the alarm function, we have designed the corresponding alarm logic. When the temperature and humidity exceed the set threshold, the buzzer will send out an alarm signal to remind the user that the environment is abnormal.

		if(TH >= TH_set) P22 = 1;
		else P22 = 0;

5. Button function

In order to realize the key function, we have written a key scan function. By detecting the button state and processing the button event, the mode switching and threshold adjustment functions are realized.


void key0()
{
    
    
	if(k1 == 0)
	{
    
    
		while(k1 == 0);
		F1602_clear();
		mode++;
		if(mode >= 2)mode = 0;
	}
	if(k2 == 0)
	{
    
    
				while(k2 == 0);
		if(mode == 1)TH_set++;
		if(TH_set >= 100)TH_set = 100;
//		if(mode == 2)TL_set++;
//		if(TL_set >= TH_set)TL_set=TH_set;
	}
	

	if(k3 == 0)
	{
    
    
		while(k3 == 0);
		if(mode == 1)TH_set--;		
//		if( TH_set<= TL_set)TH_set= TL_set;	
//				if(mode == 2)TL_set--;

		if(TH_set <= 0)TH_set = 0;
		
		
		
	}	
}

6. Bluetooth function

In order to realize the bluetooth function, we wrote the serial port sending function. After the data is formatted and displayed on the mobile phone, the user can observe the environmental information intuitively.

void SendData(unsigned char dat)
{
    
    
		SBUF = dat;				
		while(!TI);				
		TI = 0;					
}
void SendString(unsigned char *s)
{
    
    
    while (*s)                  
    {
    
    
        SendData(*s++);         
    }
}

insert image description here

Function expansion

1. Data recording and storage

In order to better understand the changing trend of the environment, we can consider adding data recording and storage functions. By adding a memory module, the temperature and humidity data can be recorded and saved regularly, and curves can be drawn or statistical reports can be made to help users observe the temperature and humidity changes more intuitively.

2. Data upload and remote monitoring

If there is a network connection, we can consider uploading the data to the cloud platform for remote monitoring and management. Users can view environmental data through mobile phones or computers, and even set remote alarm functions, making the system more intelligent and convenient.

3. Temperature and humidity compensation

In order to improve the measurement accuracy of the system, we can consider adding a temperature and humidity compensation function. By calibrating sensor data and nonlinear compensation of temperature and humidity, the measurement results of the system are more accurate and reliable.

simulation

insert image description here

schematic diagram

insert image description here

product description

1. Appearance design

We designed a simple and practical shell, and put STC89C51 microcontroller, DHT11 sensor, LCD1602 display module, buttons, buzzer and other components into it. The shell is made of environmentally friendly plastic material, and the surface is treated with matte, which is comfortable to touch and can effectively prevent fingerprints and dirt.

2. Usage scenarios

The air temperature and humidity detection and alarm system is suitable for various places such as homes, offices, and laboratories. Users can place it on the desktop or wall to facilitate real-time monitoring of the temperature and humidity of the environment.

3. Instructions for use

Using the system is very simple. When the user uses it for the first time, the system will perform initial settings, including calibration and setting alarm thresholds. After that, the system will automatically monitor the ambient temperature and humidity, and display the data on the LCD screen. Users can switch modes and adjust thresholds by pressing the buttons. When the temperature and humidity exceed the set threshold, the buzzer will send out an alarm signal to remind the user that the environment is abnormal.

4. Security and Stability

In order to ensure the safety of users, we have conducted multiple safety tests on the product, including overvoltage protection, temperature protection and current protection. At the same time, we have conducted a long-term stability test on the system to ensure the reliability and durability of the product.

Experience summary

During the development of the project, we encountered some challenges and difficulties. For example, the calibration and precision processing of the DHT11 sensor, the debounce of the button and the issue of multiple triggers, etc. Through serious debugging and continuous trials, we finally overcome these problems and achieve a stable and reliable system.

Troubleshooting

In practical applications, some failures may occur. For example, display instability, inaccurate sensor data and other issues. We can solve these problems by checking hardware connections, adjusting software algorithms, and adding exception handling mechanisms.

Summarize

Through this project, we have a deep understanding of the usage and basic principles of STC89C51 series microcontrollers, and learned how to communicate and exchange data with peripheral modules. The air temperature and humidity detection and alarm system provides us with a good learning platform, allowing us to have a deeper understanding of the application of embedded systems and Internet of Things technology.

Thanks for reading this blog! If you are interested in the air temperature and humidity detection and alarm system based on STC89C51, you can try to make your own system and further expand the functions. Embedded system development is a field of unlimited creativity, looking forward to more wonderful creations from you!

These problems can be solved by checking hardware connections, adjusting software algorithms, and adding exception handling mechanisms.

Summarize

Through this project, we have a deep understanding of the usage and basic principles of STC89C51 series microcontrollers, and learned how to communicate and exchange data with peripheral modules. The air temperature and humidity detection and alarm system provides us with a good learning platform, allowing us to have a deeper understanding of the application of embedded systems and Internet of Things technology.

Thanks for reading this blog! If you are interested in the air temperature and humidity detection and alarm system based on STC89C51, you can try to make your own system and further expand the functions. Embedded system development is a field of unlimited creativity, looking forward to more wonderful creations from you!

Guess you like

Origin blog.csdn.net/qq_42704442/article/details/131755986