Natural gas gas detection and alarm simulation design based on STM32 (simulation + program + explanation)

Natural gas gas detection and alarm simulation design based on STM32


Simulation diagram proteus 8.9

Program compiler: keil 5

Programming language: C language

Design number: C0081

Demo video

Simulation design of natural gas and combustible gas detection and alarm based on STM32

1. Main functions

Function Description:

1. Design a combustible gas (natural gas) detection and alarm design using the STM32 microcontroller as the control core;

2. Display the gas concentration through the liquid crystal screen LCD1602;

3. You can set the fan to turn on automatically or manually by turning the switch. The indicator light is on in manual mode and off in automatic mode.

4. Manual mode controls the fan switch through buttons. In automatic mode, the fan automatically starts when the gas concentration is detected to be higher than 2.0mg/L.

5. The buzzer will alarm when the gas concentration is detected to be higher than 2.0mg/L.

Main hardware equipment: STM32F103 microcontroller

The following is a display of this design information:

2. Simulation

Overall design plan

The purpose of this experiment is to use the advanced digital-to-analog converter (ADC), general-purpose input and output (GPIO) and timer resources of the STM32 microcontroller to effectively combine software and hardware to achieve AD on the input analog natural gas sensor. Accurate identification of values ​​and correct display of relevant data through the 1602 liquid crystal display (LCD1602). In addition, we also hope that the system can alarm gas concentration through peripherals such as buzzers and fans based on preset alarm values.

In this experiment, it is worth noting that the Proteus software does not have a built-in concentration sensor for harmful gases such as natural gas. Therefore, to simulate changes in combustible gas concentration, a sliding rheostat is used. Although this approach cannot be directly applied to actual hardware design, it is very useful for understanding and testing the basic behavior of the algorithm. For users who need to carry out physical design, it is recommended to conduct corresponding debugging and modification based on the actual sensor.

In general, this experiment provides a basic framework and shows how to use the STM32 microcontroller combined with resources such as ADC, GPIO and timer to collect and process the simulated natural gas sensor signals, and display them through the LCD1602 and alarm device. Display and alarm. Although it cannot be directly used in physical design, it is of great value for understanding and mastering the basic principles and applications of related technologies.

This test looks like this:

Simulation running status:

After starting the simulation, LCD1602 displays the detected gas concentration in real time, and the measured value can be changed through the sliding rheostat. The operating mode of the fan can be selected via a switch. If the switch is closed, the fan works in automatic mode. When the gas concentration is higher than the alarm value, the fan starts. When the gas concentration is lower than the alarm value, the fan does not rotate. If the fan is in manual mode, control the fan switch by pressing the button. The buzzer alarm circuit starts when the gas concentration is higher than the alarm value, and there is a beeping alarm sound, and it does not start when the gas concentration is lower than the alarm value.

In the picture below, the detected gas concentration is 1.5 mg/L, which is lower than the alarm value of 2.0 mg/L. The fan and buzzer circuit do not work.

img

The picture below detects that the gas concentration is 2.0 mg/L, which is greater than or equal to the alarm value. The buzzer alarms and the fan rotates to simulate exhaust ventilation.

img

3. Procedure

The program is opened with the keil5 mdk version. If there are problems opening it, check the keil version. The program is written in the firmware library version, and there are comments that can be combined with the explanation and understanding.
mian.c code

#include "stm32f10x.h"
#include "bsp-lcd1602.h"
#include "delay.h"
#include "sys.h"
#include "adc.h"
#define LED PAout(3)
#define BEEP PAout(4)
#define KEY1 PAin(8)
#define KEY2 PAin(9)
#define KEY3 PAin(10)
void LED_Init(void)
{
    
    
 
 GPIO_InitTypeDef  GPIO_InitStructure;
 	
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);	 //使能P端口时钟
	
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4;				 //LED0 端口配置
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 GPIO_SetBits(GPIOA,GPIO_Pin_3);						 //输出高
 GPIO_SetBits(GPIOA,GPIO_Pin_4);						 //输出高

}
void KEY_Init(void)
{
    
    
	GPIO_InitTypeDef GPIO_InitStructure; //定义结构体变量	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	
	
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;	//上拉输入
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
}
int main(void)
{
    
    
int a,b,c,d;
	float temp;
	int count;
	delay_init();	    	 //延时函数初始化	  	
	LCD1602_Init();
  ADC1_GPIO_Config();		
  ADC_Config();  
	LCD1602_ShowStr(2,0,"Qiti=0.0mg/L",13);
	LED_Init();		//风扇控制引脚
	KEY_Init();		//按键初始化
	while(1)
	{
    
    
		count++;
		if(count>5000){
    
    //用于计数,防止系统执行转换太频繁
			count = 0;
			b=ADC_GetConversionValue(ADC1);//获取ADC的值
			temp=(float)b*(3.4/4096);//换算ADC的值
			a=temp/1;
			c=temp*10;
			d=c%10;
			LCD_ShowNum(7,0,a);
			LCD_ShowNum(9,0,d);//显示检测到的AD值

				if(KEY3==0){
    
    //按键控制
					if(temp>2) LED=1;//LED1是风扇控制引脚,1打开 0关闭
					else LED=0;
				}	else{
    
    
					if(KEY1==0) LED=1;
					if(KEY2==0) LED=0;
				}	
			if(temp>2) BEEP=0;//蜂鸣器报警值判断,BEEP==0蜂鸣器报警 1蜂鸣器关闭
				else BEEP=1;	
				delay_ms(10);
		}



	}
}




img

4. Information list & download link

0. Common usage problems and solutions – a must-read! ! ! !

1. Source program

2. Simulation diagram

3. Functional requirements

4. Explanation video

Altium Designer Software Information

KEIL software information

Proteus software information

Microcontroller learning materials

Defense skills

Common descriptions for design reports

Double-click the mouse to open and find more 51 STM32 Microcontroller Course Graduation Project.url

img

Data download link (clickable):

Guess you like

Origin blog.csdn.net/weixin_52733843/article/details/132503733