Intelligent fire alarm system temperature smoke light based on 51 single chip microcomputer

wx Gong Zhonghao: Chuangxiang diary
Dialog box sending: fire alarm
Get complete source code source file + circuit diagram + simulation file + paper report, etc.
insert image description here


Function introduction

51 single-chip microcomputer + MQ-2 smoke sensor + ADC0832 analog-to-digital conversion chip + DS18B20 temperature sensor + digital tube display + key module + sound and light alarm module

Specific functions:
1. Real-time monitoring and display of temperature value and smoke concentration;
2. Smoke alarm value and temperature alarm value can be set through three buttons;
3. Manual emergency alarm and manual cancel alarm functions can be realized;
4. When the temperature exceeds the threshold , the buzzer sounds and the yellow light flashes; when the smoke exceeds the threshold, the buzzer sounds and the red light flashes;
5. Ranging range: smoke concentration: 0-9 levels; temperature range: 0-99 degrees.

insert image description here


schematic diagram

insert image description here


PCB diagram

insert image description here


Simulation diagram

insert image description here


Software and hardware design block diagram

insert image description here
insert image description here
insert image description here
See the download for the rest of the complete details!


design background

The development of intelligent fire alarm system has changed rapidly, and the development of new technologies has further expanded the application field of fire alarm system, providing an effective means for some environments where the alarm system is not competent. Our country's fire alarm has grown from scratch, from existence to the present intelligence. The fire alarm system has taken a faster pace in the direction of early detection, multi-sensor composite detection and detector miniaturization and intelligence.

With the innovation of technology, single-chip microcomputer has been deeply applied to various fields of industrial and agricultural production and people's daily life. Therefore, various types of single-chip microcomputers are also developed according to the needs of society. A microcontroller is a device-level computer system that is actually a microcontroller or microprocessor. Because of its complete functions, small size and low cost, it can be applied to any electronic system. Similarly, it is also widely used in the field of alarm technology, which makes the functions of various alarm devices more perfect and the reliability is greatly improved, so as to meet the needs of social development.


hardware design

The principle of the intelligent fire alarm system is based on the fact that when the smoke concentration or temperature reaches the set value, the signal sensed by the smoke sensor and the temperature sensor is processed by the ADC0832 for analog-to-digital conversion and then processed by the single-chip microcomputer, and the horn sends out an alarm sound. The system is divided into control circuit, detection circuit, display and alarm circuit.


software design

First, start to execute the initialization subroutine. The functions realized by initialization are I/O port input and output state setting, register initialization, interrupt function, etc. Set the initial value of timing to 50ms, and use IAP to write to EEPROM as the value interval. Then, set timer 0 and select mode 1. In the mode 1 state, the working registers TH1 and TL1 of the timer are all 16 bits involved in the operation. Next, set the enable bit of timer 0 interrupt to 1, turn on timer 0, turn off the buzzer, turn on the green light, and set the initial value of the alarm. Part of the source code is as follows.

#include <reg51.h>	         //调用单片机头文件
#define uchar unsigned char  //无符号字符型 宏定义	变量范围0~255
#define uint  unsigned int	 //无符号整型 宏定义	变量范围0~65535
#include <intrins.h>
#include "eeprom52.h"

//数码管段选定义      0     1    2    3    4    5	 6	 7	  8	   9	
uchar code smg_du[]={
    
    0x5f,0x44,0x9d,0xd5,0xc6,0xd3,0xdb,0x45,0xdf,0xd7,0x40,0xfd/*-*/};
//数码管位选定义
uchar code smg_we[]={
    
    0x7f,0xbf,0xdf,0xef};

uchar dis_smg[8]  = {
    
    0xa0,0x84,0x62,0x2a,0x39,0x2c,0x24,0xba};	

sbit CS=P2^3;		//CS定义为P3口的第2位脚,连接ADC0832CS脚  PCB
sbit SCL=P2^0;		//SCL定义为P3口的第3位脚,连接ADC0832SCL脚
sbit DO=P2^1;		//DO定义为P3口的第4位脚,连接ADC0832DO脚

sbit ledy = P1^6;   //温度报警指示灯
sbit ledr = P1^7;   //烟雾报警指示灯 x
sbit dq   = P1^5;	//18b20 IO口的定义
sbit beep = P3^6;   //蜂鸣器IO口定义
uint temperature,s_temp ;  //温度的变量
uchar dengji,s_dengji;     //烟物等级
uchar shoudong;            //手动报警键

bit flag_300ms = 1;
uchar key_can;		 //按键值的变量
uchar menu_1;        //菜单设计的变量

/*************读取18b20内的数据***************/
uchar read_18b20()
{
    
    
	uchar i,value;
	for(i=0;i<8;i++)
	{
    
    
		dq = 0;			 //把总线拿低读时间隙开始 
		value >>= 1;	 //读数据是低位开始
		dq = 1;			 //释放总线
		if(dq == 1)		 //开始读写数据 
			value |= 0x80;
		delay_uint(5);	 //60us	读一个时间隙最少要保持60us的时间
	}
	return value;		 //返回数据
}

/****************按键处理数码管显示函数***************/
void key_with()
{
    
    
	if(key_can == 4) 	 //紧急报警键  手动报警
	{
    
    
		if(menu_1 == 0)
			shoudong = 1;
	}
	if(key_can == 1)	 //设置键
	{
    
    
		menu_1 ++;
		if(menu_1 >= 3)
		{
    
    
			menu_1 = 0;
		}
	}
	if(menu_1 == 0)
	{
    
    
		if((key_can == 2) || (key_can == 3))
			shoudong = 0;          //取消手动报警
	}
	if(menu_1 == 1)			//设置高温报警
	{
    
    
		if(key_can == 2)
		{
    
    
			s_temp ++ ;		//高温报警值加1 
			if(s_temp > 99)
				s_temp = 99;
		}
		if(key_can == 3)
		{
    
    
			s_temp -- ;		//高温报警值减1 
			if(s_temp <= 10)
				s_temp = 10 ;
		}
		dis_smg[0] = smg_du[s_temp % 10];	           //取个位显示
		dis_smg[1] = smg_du[s_temp / 10 % 10];  //取十位显示
		dis_smg[2] = 0x80;
		dis_smg[3] = 0x1b;	//显示c
		write_eeprom();			   //保存数据
	}	
	if(menu_1 == 2)			//设置烟物报警
	{
    
    
		if(key_can == 2)
		{
    
    
			s_dengji ++ ;	  //烟物报警值加1 
			if(s_dengji >= 9)
				s_dengji = 9;
		}
		if(key_can == 3)
		{
    
    
			s_dengji --;	  //烟物报警值减1 
			if(s_dengji <= 1)
				s_dengji = 1;
		}
		dis_smg[0] = smg_du[s_dengji % 10];	           //取个位显示
		dis_smg[1] = 0x80 ;  
		dis_smg[2] = 0x80;
		dis_smg[3] = 0xc7;	//显示q
		write_eeprom();			   //保存数据
	}	
}  

/***************主函数*****************/
void main()
{
    
    
	beep = 0;				    //开机蜂鸣器叫一声
	delay_1ms(200);
	P0 = P1 = P2 = P3 = 0xff;   //初始化IO口为高电平
	temperature = read_temp();  //读取温度值
	init_eeprom();  //开始初始化保存的数据
	delay_1ms(650);				
	temperature = read_temp();  //读取温度值
	time_init(); //初始化定时器 		
	while(1)  
	{
    
    
		key();					//独立按键程序
		if(key_can < 10)
		{
    
    
			key_with();			//按键按下要执行的程序
		}
		if(flag_300ms == 1)
		{
    
    		
			flag_300ms = 0;
			clock_h_l();
			temperature = read_temp();  //读取温度值
			dengji = ad0832read(1,0);	
			dengji = dengji * 10 / 250;
			if(menu_1 == 0)
			{
    
    
				if(temperature >= 99)
					temperature = 99;
				dis_smg[3]=smg_du[dengji];	    //显示烟物报警等级
				dis_smg[2]= 0x80;	            // -		
				dis_smg[1]=smg_du[temperature/10%10];	//十位
				dis_smg[0]=smg_du[temperature%10];	    //个位	ADC0832为8位ADC,数值为0~255,我们将其分开放入l_tmpdate数组中显示
			}
		} 
		delay_1ms(1);
	}
}

/*************定时器0中断服务程序***************/
void time0_int() interrupt 1
{
    
    	
	static uchar value;
	TH0 = 0xf8;
	TL0 = 0x30;     // 2ms
	value ++;	 
	display();	  //数码管显示函数
	if(value % 150 == 0)
	{
    
    
		flag_300ms = 1;	   //300ms
		value = 0;
	}
}

See the download for the rest of the complete details!

Guess you like

Origin blog.csdn.net/m0_46653805/article/details/131152592