当前位置:网站首页>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
- MQ-2 Smoke sensor to liquefied gas 、 Natural gas 、 The sensitivity of city gas is high .
- 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 .
- The detection range of combustible gas and smoke is 100~10000ppm(ppm Is the volume concentration . 1ppm=1 Cubic centimeter /1 Cubic meters )
- Dual signal output ( Analog output and digital output ).
- 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
- Minimum system STM32F10SC8T6.
- MQ-2 Smoke concentration sensor .
- There are several DuPont lines .
3、 ... and 、 Hardware connection
| Module pin | GPIO |
|---|---|
| VCC | VCC |
| GND | GND |
| D0 | NC( empty ) |
| A0 | PA0 |
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 
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 !
边栏推荐
- 试驾 Citus 11.0 beta(官方博客)
- Preliminary study nuxt3
- 目前是不是只cdc 监控mysql 可以拿到新增列的数据 sqlserver不行是吧
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
- How to select the ECS type and what to consider?
- three. Basic framework created by JS
- Apifox与其他接口开发工具的博弈
- 西北工业大学遭黑客攻击?双因素认证改变局面!
- 企业网络管理员必备的故障处理系统
- Make track map
猜你喜欢

IBPS开源表单设计器有什么功能?

System design idea of time traceability

Zadig + 洞态 IAST:让安全溶于持续交付

Interpreting harmonyos application and service ecology

华为机器学习服务语音识别功能,让应用绘“声”绘色

一次 MySQL 误操作导致的事故,高可用都不顶不住!

Introduction and download of nine npp\gpp datasets

试驾 Citus 11.0 beta(官方博客)

Power supply noise analysis

How to protect biological privacy in the AI era? Overview of the latest "privacy enhancement technology in biometrics" of the Autonomous University of Madrid, comprehensively detailing the biometric p
随机推荐
【计算讲谈社】第三讲:如何提出关键问题?
Unityshader world coordinates do not change with the model
Dataworks development ODPs SQL development production environment automatic completion of ProjectName
Apifox与其他接口开发工具的博弈
TKDE2022:基于知识增强采样的对话推荐系统
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
IBPS开源表单设计器有什么功能?
flink cdc全量读mysql老是报这个错怎么处理
Why useevent is not good enough
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
R language 4.1.0 software installation package and installation tutorial
多云模式并非“万能钥匙”
Example analysis of corrplot related heat map beautification in R language
Why is nodejs so fast?
Power efficiency test
Volcano becomes spark default batch scheduler
建立自己的网站(8)
The sharp sword of API management -- eolink
小滴课堂海量数据处理商用短链平台大课
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data