Design of MQ-5 Natural Gas Monitoring and Alarming System Based on 51 Single Chip Computer

Design of natural gas monitoring and alarm system based on 51 single-chip microcomputer

video

Design of MQ-5 Natural Gas Monitoring and Alarming System Based on 51 Single Chip Computer

1 Development environment

Simulation diagram: proteus8.9 or above

Program code: KEIL4/KEIL5

Schematic: AD

Design number: A0008

2 Function Description Introduction

Combined with the actual situation, a natural gas monitoring and alarm system design is designed based on 51 single-chip microcomputer. The functional requirements that the system should meet are:

Physical function:

This design consists of 51 single-chip microcomputer + MQ-5 sensor module circuit + 3 LED indicator circuits + buzzer alarm circuit + PCF8591AD module + fan control circuit + relay circuit + power supply circuit.

1. MQ-5 detects the gas concentration in real time. The concentration is divided into low, medium and high levels, which are indicated by green, yellow and red lights respectively. When the concentration reaches the corresponding level, the corresponding light will be on, and the indicator light will indicate the safe state.

2. When the concentration reaches a high level, the buzzer will alarm, the fan will start to evacuate the gas, and the relay will work to drive the load to disconnect the gas valve;

3. When the concentration reaches the mid-range, the relay works to drive the load to disconnect the gas valve.

Simulation function:

This design consists of 51 single-chip microcomputer + MQ-5 sensor module circuit + LED indicator circuit + buzzer alarm circuit + ADC0832 module + fan control circuit + relay circuit + power supply circuit.

1. MQ-5 detects the gas concentration in real time. The concentration is divided into 2 levels, which are indicated by green and red lights respectively. When the concentration reaches the corresponding level, the corresponding light is on, and the indicator light indicates the safe state.

2. When the concentration reaches a high level, the buzzer will alarm, the fan will start to evacuate the gas, and the relay will work to drive the load to disconnect the gas valve; the red light will flash.

3. When the concentration reaches a low level, the fan is turned off, the gas valve works normally, and the green light flashes.

3 Simulation diagram

AT89C51 can be replaced by AT89C52, and the real product can be replaced by STC89C51, STC89C52

AT89C51 is a low-voltage, high-performance CMOS 16-bit single-chip microcomputer produced by ATMEL Corporation of the United States. It contains 4k bytes of rewritable read-only program memory and 128 bytes of random access data memory. Produced with volatile storage technology, compatible with standard MCS-51 instruction system, built-in general-purpose 16-bit CPU and Flash storage unit, powerful AT89C51 single-chip microcomputer can be flexibly used in various control fields.

AT89C51 provides the following standard functions: 4k bytes of Flash memory, 128 bytes of internal RAM, 32 I/O lines, two 16-bit timers/counters, a 5-vector two-level interrupt structure, and a full-duplex serial Line communication port, on-chip oscillator and clock circuit. At the same time, AT89C51 can drop to 0Hz static logic operation, and supports two software-selectable power-saving operating modes. The idle mode stops the work of CPU, but allows RAM, timer/counter, serial communication port and interrupt system to continue to work. The power-down mode saves the content in RAM, but the oscillator stops working and prohibits all other components from working until the next hardware reset.

The central controller of this system adopts AT89C51 single-chip microcomputer, and the reset circuit adopts power-on reset circuit. The external crystal oscillator is a 12MHz crystal oscillator.

img

4 programs

The project file is opened with Keil4/keil5. Compile and generate hex and load it into the corresponding microcontroller. The physical code and the simulated code are slightly different. Separate project files.

img

the code

#include <reg52.h> 
#include <intrins.h>
#include <stdio.h>
#include "i2c.h"
#include "delay.h"

sbit fengshan = P1^0;  //接口定义
sbit buzzer = P1^1;
sbit relay = P1^2;  
sbit LED_GRE = P1^3;  
sbit LED_YEL = P1^4;
sbit LED_RED = P1^5;

unsigned long time_20ms=0;	//定时变量
unsigned char dis0[16];		//数组暂存
unsigned char midVolt ;		//ad采集电压
unsigned char i; 

void Init_Timer0(void);//函数声明
void UART_Init(void);
void uartSendByte(unsigned char dat);
void uartSendStr(unsigned char *s,unsigned char length);
 
void main (void)
{
    
    

	Init_Timer0();        //定时器0初始化
	
	UART_Init();
	DelayMs(120);
	uartSendStr("ready ok!",9);
	while(1)         //主循环
	{
    
    
			midVolt=ReadADC(0)*99/255;				//读取AD检测到的转化为数值
			sprintf(dis0,"NongDu:%2d\n",(unsigned int)midVolt);	 //发送
			uartSendStr(dis0,10);
			if(midVolt<30)		
			{
    
    
				fengshan = 1;//关 风扇
				buzzer = 1;//关 蜂鸣器
				relay = 1;//关 继电器
				LED_GRE = 0;//开 绿灯
				LED_YEL = 1;//关 黄灯
				LED_RED = 1;//关 红灯			
			}
			else if(midVolt<50)		
			{
    
    
				fengshan = 1;//关 风扇
				buzzer = 1;//关 蜂鸣器
				relay = 0;//开 继电器
				LED_GRE = 1;//关 绿灯
				LED_YEL = 0;//开 黄灯
				LED_RED = 1;//关 红灯			
			}
			else
			{
    
    
				fengshan = 0;//开 风扇
				buzzer = 0;//开 蜂鸣器
				relay = 0;//开 继电器
				LED_GRE = 1;//关 绿灯
				LED_YEL = 1;//关 黄灯
				LED_RED = 0;//开 红灯			
			}
			for(i=0;i<5;i++) DelayMs(100);
	}
}

void Init_Timer0(void)
{
    
    
 TMOD |= 0x01;	  //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响		     
 TH0=(65536-20000)/256;		  //重新赋值 20ms
 TL0=(65536-20000)%256;
 EA=1;            //总中断打开
 ET0=1;           //定时器中断打开
 TR0=1;           //定时器开关打开
}

void Timer0_isr(void) interrupt 1 
{
    
    
 TH0=(65536-20000)/256;		  //重新赋值 20ms
 TL0=(65536-20000)%256;

 time_20ms++;
}
void UART_Init(void)
{
    
    
    SCON  = 0x50;		        // SCON: 模式 1, 8-bit UART, 使能接收  
    TMOD |= 0x20;               // TMOD: timer 1, mode 2, 8-bit 重装
    TH1   = 0xFD;               // TH1:  重装值 9600 波特率 晶振 11.0592MHz  
    TR1   = 1;                  // TR1:  timer 1 打开                         
    EA    = 1;                  //打开总中断
    ES    = 1;                  //打开串口中断
}

void uartSendByte(unsigned char dat)
{
    
    
	unsigned char time_out;
	time_out=0x00;
	SBUF = dat;			  //将数据放入SBUF中
	while((!TI)&&(time_out<100))  //检测是否发送出去
	{
    
    time_out++;DelayUs2x(10);}	//未发送出去 进行短暂延时
	TI = 0;						//清除ti标志
}

void uartSendStr(unsigned char *s,unsigned char length)
{
    
    
	unsigned char NUM;
	NUM=0x00;
	while(NUM<length)	//发送长度对比
	{
    
    
		uartSendByte(*s);  //放松单字节数据
		s++;		  //指针++
		NUM++;		  //下一个++
  	 }
}

void UART_SER (void) interrupt 4 //串行中断服务程序
{
    
    
	unsigned char u_buf;
    if(RI)                        //判断是接收中断产生
    {
    
    
	  RI=0;                      //标志位清零
	  u_buf = SBUF;
	}
   if(TI)  //如果是发送标志位,清零
	TI=0;
}

The flowchart is shown in the figure below.

img

5 Schematic

The schematic diagram is drawn by AD, and there are differences between the schematic diagram and the simulation diagram. The schematic diagram requires a power supply and a power switch module. The design information is detailed, the hardware manual information and pictures are detailed, and I am not responsible for hardware debugging, and some basic skills are required to make the real thing. The main control chip can be replaced by STC89C51/STC89C52

img

This design consists of STC89C52 microcontroller + natural gas sensor module circuit + 3 LED indicator circuits + buzzer alarm circuit + fan control circuit + relay control circuit + power supply circuit.

1. MQ-5 detects the gas concentration in real time. The concentration is divided into low, medium and high levels, which are indicated by green, yellow and red lights respectively. When the concentration reaches the corresponding level, the corresponding light will be on, and the indicator light will indicate the safe state.

2. When the concentration reaches a high level, the buzzer will alarm and the fan will start to evacuate the gas.

3. When the concentration reaches the mid-range, the relay is disconnected.

img

6 video explanation

Code explanation + simulation explanation + simulation demonstration + schematic diagram explanation

7 Design report

People can't survive without air. About 80% of people's life is spent indoors. The quality of indoor environment affects people's physical and mental health. The sources of indoor harmful gases come from the release of formaldehyde, ammonia, radon, benzene, and radioactive substances caused by improper decoration. If these gases are paid attention to during decoration, their emissions can be completely reduced, so that they will not affect people's health. . Another major source of harmful gases in the room is the leakage of flammable gases, which can be mainly divided into natural gas leakage, liquefied petroleum gas leakage and coal gas leakage.

The main components of gas leakage are carbon monoxide and hydrogen. The reason for carbon monoxide poisoning is that after carbon monoxide enters the human body, it will combine with hemoglobin in the blood, resulting in hypoxia. It is common in the case of poor ventilation in the family room, inhalation of carbon monoxide in the coal gas generated by the coal stove or the leakage gas of the liquefied gas pipeline will lead to carbon monoxide poisoning. The hazards of liquefied petroleum gas leakage are not easy to underestimate. Liquefied petroleum gas is one of the petroleum products. It is a colorless, volatile gas obtained by pressurizing, cooling and liquefying refinery gas or natural gas (including oilfield associated gas). The liquefied petroleum gas obtained from refinery gas is mainly composed of propane, propylene, butane and butene, and also contains a small amount of pentane, pentene and trace sulfur compound impurities. The composition of the liquefied gas obtained from natural gas is substantially free of olefins. Liquefied petroleum gas is mainly used as petrochemical raw material, used for hydrocarbon cracking to produce ethylene or steam reforming to produce synthesis gas, and can be used as industrial, civil and internal combustion engine fuel. Its main quality control indicators are evaporation residue and sulfur content, etc., and sometimes olefin content is also controlled. Liquefied petroleum gas is a flammable substance. When the content in the air reaches a certain concentration range, it will explode when it encounters an open flame.

The main component of natural gas is alkanes, of which methane content is more than 95%. There are about 20% oxygen in the air that people live on. If the living space of people is a closed space with thin oxygen, people will suffocate and coma due to lack of oxygen. People with cardiovascular and cerebrovascular diseases will endanger their lives. Leakage of indoor natural gas will make the oxygen in the indoor air relatively thin. Because natural gas is colorless and odorless, it is difficult for people to detect it. Especially when people are sleeping, the leakage of natural gas is even more dangerous, and it may even cause people to suffocate. Another danger of natural gas is that when the content of natural gas in the air reaches a certain level, it will explode when encountering an open flame, endangering human life.

Is there a thorough solution for people to face the life-threatening and health-threatening situation of flammable gas leakage? According to relevant experts, combustible gas leakage alarm is one of the important preventive means to deal with gas leakage. In order to prevent the occurrence of poisoning incidents, an effective preventive measure using the single-chip microcomputer system is proposed. So how to prevent gas poisoning and explosion has become an urgent need for people. Based on this reality, the purpose of this design is to design a device for home users that can prevent natural gas, liquefied petroleum gas and coal gas leakage, so as to reduce unnecessary accidents, protect people's lives and health, and reduce unnecessary losses.

7.1 Design purpose

(1) Consolidate and deepen the understanding of microcontroller principles and interface technology knowledge;

(2) Cultivate the ability to select reference books, consult manuals and literature according to the needs of the subject;

(3) Learn the comparative methods of program demonstration, broaden knowledge, and initially master the basic methods of engineering design;

(4) Master the correct use of commonly used instruments and meters, and learn how to design and debug software and hardware;

(5) Able to write course design reports according to the requirements of course design, correctly reflect design and experimental results, and draw circuit diagrams, simulation diagrams and flow charts by computer.

7.2 Overview

With the massive use of natural gas, every residential building is "shrouded" by natural gas. The popularity of natural gas has brought convenience to public life, reduced urban pollution, and improved the quality of life and efficiency, but at the same time, natural gas is also a potential "dangerous product". Once a large area leaks, it may cause a big explosion if it is not disposed of in time. , which poses a huge threat to the safety of residents' lives and properties. Faced with various accident threats caused by gas leakage, we need a solution. The use of natural gas alarms is one of the important means to deal with invisible gas killers.

The gas alarm designed in this paper based on the semiconductor gas sensor and single-chip microcomputer technology can realize the sound and light alarm function. It is a gas alarm with simple structure, stable performance, convenient use, low price, and intelligence. value.

Among them, the MQ-5 sensor is used to detect the gas, which has the advantages of high sensitivity, fast response, strong anti-interference ability, etc., and is low in price and long in service life. The data collected by the sensor is processed by the single chip microcomputer after A/D conversion, and the processed data is analyzed to see if it is greater than or equal to a certain preset value (that is, the alarm limit). If it is greater than the alarm limit, the alarm circuit will be automatically activated. Alarm sound and fan, otherwise it is normal state,

7.3 Research status at home and abroad

Flammable gas leakage alarms are mostly used in various gas alarms and systems in large apartments, restaurants, hospitals, schools, and factories. There are single-separated alarms, external alarm systems, centralized monitoring systems, and blocking linkage systems. , Anti-poisoning alarm protection system, etc. The flammable gas leakage alarm can send out sound and light alarm, or accompanied by digital display, or linked with external equipment. Some flammable gas leakage alarms can automatically turn on the exhaust fan to discharge the gas outside; some flammable gas leakage alarms can automatically close the gas valve when the alarm is issued to prevent the gas from continuing to leak. Currently the most widely used flammable gas leakage alarms and gas sensor sensors have been widely used in gas leakage detection and monitoring, and are only used for safety protection of household gas leakage alarms. And other requirements to install the corresponding alarm. The rapid development of flammable gas leakage alarms in foreign countries is due to the enhanced safety awareness of people and higher requirements for environmental safety and living comfort; on the other hand, the growth of the gas leakage alarm market is driven by government safety regulations. Therefore, foreign gas alarm technology has developed rapidly. According to relevant statistics, the average annual growth rate of gas alarms in the United States from 1996 to 2002 was 27% to 30%. In these respects, domestic security awareness should be enhanced.

The development trend of flammable gas leakage alarms is mainly manifested in the following aspects: one is to improve sensitivity and performance, reduce power consumption and cost, reduce size, simplify circuits, and integrate with the application of the whole machine, which is also the goal that gas leakage alarms have been pursuing. ; The second is to enhance reliability, realize the integration and multi-function of components and application circuits, develop MEMS technology, and develop field-applicable transmitters and intelligent flammable gas leakage alarms. For example, in the United States, a microprocessor is embedded in the gas leakage alarm, so that the gas leakage alarm has the functions of controlling calibration and monitoring fault conditions, realizing intelligence and multi-function.

img

8 Download link of data list

See the video at the beginning of the article

img

Guess you like

Origin blog.csdn.net/Jack_0220/article/details/128823795