当前位置:网站首页>Mq-2 smoke concentration sensor (STM32F103)

Mq-2 smoke concentration sensor (STM32F103)

2022-06-24 19:23:00 Me-Space

This experiment is displayed by the serial port debugging assistant STM32F103C8T6 Collect to MQ-2 Voltage value of the sensor .

One 、 summary

1. brief introduction

MQ-2 It can be used for gas leakage monitoring devices in homes and factories , Suitable for liquefied gas 、 Butane 、 propane 、 methane 、 alcohol 、 Detection of smoke, etc . Its advantage is high sensitivity 、 Fast response 、 Good stability . Long life 、 The driving circuit is simple and easy to install .

2. working principle

MQ-2 The smoke sensor belongs to tin oxide semiconductor gas sensing material , It belongs to surface ionic formula N Type semiconductor . be in 200~3000 Degree Celsius , The surface of tin oxide adsorbs oxygen in the air , Form negative ion adsorption of oxygen , Reduce the electron density in semiconductors , Increase the resistance value from the surface . When in contact with smoke , If the potential barrier at the intergranular boundary receives the adjustment surface change of smoke , It will cause the change of surface conductivity . Using this point, we can get the information about the existence of this kind of smoke. The greater the smoke concentration, the greater the conductivity , The lower the output resistance , The larger the output analog signal .

3. MQ-2 characteristic

  1. MQ-2 Smoke sensor to liquefied gas 、 Natural gas 、 The sensitivity of city gas is high .
  2. MQ-2 The sensor has good repeatability and long-term stability . Initial stability , Short response time , Good working performance for a long time . It should be noted that : It must be heated for a period of time before use , Otherwise, the output resistance and voltage are not accurate .
  3. The detection range of combustible gas and smoke is 100~10000ppm(ppm Is the volume concentration . 1ppm=1 Cubic centimeter /1 Cubic meters )
  4. Dual signal output ( Analog output and digital output ).
  5. When the gas concentration does not exceed the set threshold , Digital interface DO Port output low level , Analog interface A0 The voltage is basically 0v about ; When the gas influence exceeds the set threshold , Module digital interface D0 Output high level , Analog interface A0 The output voltage will gradually increase with the influence of gas .

Two 、 Experimental materials

  1. Minimum system STM32F10SC8T6.
  2. MQ-2 Smoke concentration sensor .
  3. There are several DuPont lines .

3、 ... and 、 Hardware connection

Module pin GPIO
VCCVCC
GNDGND
D0NC( empty )
A0PA0

notes :A0: Analog output interface ;D0: Digital quantity switch interface (0/1).

Four 、 Implement the program

1、 GPIO initialization

void ADC_Pin_Init(void)
{
    
	GPIO_InitTypeDef GPIO_InitStruct;
	ADC_InitTypeDef ADC_InitStruct;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA
						| RCC_APB2Periph_ADC1,ENABLE);
	
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	
	ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;// Single conversion 
	ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;// Data alignment 
	ADC_InitStruct.ADC_Mode = ADC_Mode_Independent;// Independent mode 
	ADC_InitStruct.ADC_NbrOfChannel = 1;// Total number of conversions 
	ADC_InitStruct.ADC_ScanConvMode = DISABLE;// Single channel scanning 
	ADC_Init(ADC1,&ADC_InitStruct);
	
	// Switching channels   The number of conversions   Sampling time 
	ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_239Cycles5);
	
	ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);
	
	ADC_Cmd(ADC1,ENABLE);
}

2、 Data conversion

u16 ADC_Trans(void)
{
    
	u16 adc_value = 0;
	u8 i = 0;
	
	for(i = 0; i < 50; i++)
	{
     
		// Start conversion 
		ADC_SoftwareStartConvCmd(ADC1,ENABLE);
		
		// Does the conversion end 
		while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC) != SET);
		adc_value = adc_value + ADC_GetConversionValue(ADC1);// read ADC The value in 
	}
	
	return adc_value / 50;// sampling 50 The average of times 
}

3、 The main program

int main(void)
{
    
	u16 ad = 0;
	
	Sys_Delay_Init();
	Usart1_Pin_Init(115200);
	printf(" Successful initialization \r\n");
	ADC_Pin_Init();
	while(1)
	{
    
		ad = ADC_Trans();
// printf(" Voltage value :%f\r\n",3.3/4095*ad); // Actual voltage value  
		printf("%.2f\r\n",ad * 99 / 4096.0);// hold AD Values are converted to percentages 0~99
		delay_ms(1000);

	}
}

5、 ... and 、 Experimental results  Insert picture description here

Complete procedures and relevant data :
link :https://pan.baidu.com/s/1G-Xl3c6kYr9eU48Gt0EKAg
Extraction code :9owd

If there is any mistake, please point out , thank you !

原网站

版权声明
本文为[Me-Space]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211331529353.html