51 single-chip temperature smoke alarm system

Design function

(1) Mainly adopts 51 single-chip microcomputer + minimum system + LCD1602 liquid crystal display module + MQ-2 smoke module + ADC0832 module + DS18B20 temperature module + buzzer module + LED indicator module + relay drive module + fan module + button module.
(2) LCD1602 liquid crystal display, DS18B20 temperature sensor, MQ-2 smoke sensor or MQ-5 combustible gas sensor and ADC0832 analog-to-digital conversion chip constitute a fire control system design;
(3) Display the current smoke value and temperature value in real time; the alarm value of temperature and smoke can be set by pressing the button;
(4) When the current temperature value exceeds the upper limit, the red light is on and the buzzer sounds; when the current smoke value exceeds the upper limit, the yellow light is on and the buzzer sounds;
(5) Four button functions: minus, set, plus, and a single reset button;

Schematic:

The schematic drawing software adopts AD2013. The smoke concentration is converted from non-electricity to electricity by the MQ-2 smoke sensor. The sensor outputs a voltage value of 0-5 volts, and the voltage value is stable and the external interference is small. Therefore, the sensor output voltage value can be directly converted by the A/D converter to get the data and send it to the single-chip microcomputer for processing. In addition, the temperature sensor adopts the digital temperature sensor DS18B20, no complicated circuit is required, just connect the sensor to the power supply, and connect the signal line to the pin of the single-chip microcomputer, and the temperature value can be read out through the sensor control sequence.

The overall hardware schematic diagram is shown in the figure.

 

Simulation design

The simulation software adopts Protues7.8. The smoke sensor is replaced with a potentiometer analog.

 

programming

The program uses C as the programming language and Keil5 as the programming software;

void main (void)
{
	u8 key;
	wendu=check_wendu();		  //Call the temperature read function during initialization to prevent booting at 85°C
	Init1602();			  //Call the initialization display function
	LCD_Write_String(0,0,"SET T:00   E:000");  //Boot interface
	LCD_Write_String(1,0,"NOW T:00.0 E:000");  
	delay_ms(1000);
	wendu=check_wendu();		  //Call the temperature read function during initialization to prevent booting at 85°C
	while (1)        					//main loop
	{
		key=Key_Scan();					//key scan
		yanwu=Adc0832(0);				//read smoke value
		wendu=check_wendu();	  //read temperature value
		
		if(key==KEY_SET)
		{
			Mode++;
		}
		
		switch(Mode)						//Judgment mode value
		{
			case 0:								//monitor mode
			{
				Display_1602(yushe_wendu,yushe_yanwu,wendu,yanwu);  //Display preset temperature, preset smoke, temperature value, smoke value
				if(yanwu>=yushe_yanwu)	  //When the smoke value is greater than or equal to the preset value
				{
					Led_Reg=0;		  			//smoke light on
					Fan=0;
					Buzzer=0;			  			//Buzzer alarm
				}
				else					  					//When the smoke value is less than the preset value
				{
					Led_Reg=1;		  			//Turn off the warning light
					Fan=1;
				}
				if(wendu>=(yushe_wendu*10))	  //When the temperature is greater than or equal to the preset temperature value (why is it greater than the preset value*10: because the temperature we want to display has one decimal place, it is a 3-digit number, and the actual reading number at 25.9°C is 259, so judge When the preset value is set, the preset value will be *10)
				{
					Buzzer=0;			  			//Turn on the buzzer alarm
					Led_Yellow=0;		  			//Turn on the temperature warning light
				}
				else					  					//When the temperature value is less than the preset value
				{
					Led_Yellow=1;		  			//Turn off the warning light
				}
				if((yanwu<yushe_yanwu)&&(wendu<(yushe_wendu*10)))	  //When the smoke is less than the preset value and the temperature is also less than the preset value (&&: logical AND, the expressions on the left and right sides are established (both are true, that is, 1), the if statement is established)
				{
					Buzzer=1;			  			//stop alarm
				}
				break;
			}
			case 1://Preset temperature mode
			{
				SelectPosition(0,5) ;					//specified location
	   		write_com(0x0d);							//shadow flicker
				if(key==KEY_ADD)							//plus key pressed
				{
					yushe_wendu++;					    //Preset temperature value (threshold) plus 1
					if(yushe_wendu>=99)			 		//When the threshold is added to greater than or equal to 99
					yushe_wendu=99;					 		//The threshold is fixed at 99
					LCD_Write_Char(0,6,yushe_wendu,2) ;//Display preset temperature
				}
				if(key==KEY_MINUS)				 		//minus key pressed
				{
					if(yushe_wendu<=1)					//When the temperature upper limit value is reduced to 1
					yushe_wendu=1;          		//fixed at 1
					yushe_wendu--;							//The preset temperature value minus one, the minimum is 0
					LCD_Write_Char(0,6,yushe_wendu,2) ;//Display preset temperature
				}
				break;			  								//Jump out of switch after execution
			}
			case 2:				//Preset Smoke Patterns
			{
				SelectPosition(0,12) ;				//specified location	
	   		write_com(0x0d);							//On display No cursor Cursor blinking
				if(key==KEY_ADD)							//plus key pressed
				{
					if(yushe_yanwu>=255)        //When the threshold is added to greater than or equal to 255
					yushe_yanwu=254;            //The threshold is fixed at 254
					yushe_yanwu++;					    //The preset smoke value (threshold) is increased by 1, the maximum is 255
					LCD_Write_Char(0,13,yushe_yanwu,3) ;//Show preset smoke
				}
				if(key==KEY_MINUS)						//minus key pressed
				{
					if(yushe_yanwu<=1)					//When the upper smoke limit value is reduced to 1
						yushe_yanwu=1;          	//fixed at 1
					yushe_yanwu--;							//The preset temperature value minus one, the minimum is 0	  
					LCD_Write_Char(0,13,yushe_yanwu,3) ;//Show preset smoke
				}
				break;
			}
			default	:	
			{
				write_com(0x38);//screen initialization
				write_com(0x0c);//On display No cursor No cursor blinking
				Mode=0;			//return to normal mode
				break;
			}
		}
		
	}

}

Pay attention to the official account-Single chip example design, and send "smoke temperature" to obtain information;

download link

Tags: Embedded system Single-Chip Microcomputer stm32

Posted by SocomNegotiator on Wed, 14 Sep 2022 21:33:33 +0300