当前位置:网站首页>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 !
边栏推荐
- 智能合约安全审计入门篇 —— delegatecall (2)
- Power supply noise analysis
- Why useevent is not good enough
- Volcano becomes spark default batch scheduler
- R语言corrplot相关热图美化实例分析
- NFT质押流动性挖矿系统开发技术
- Intel and Microsoft give full play to the potential energy of edge cloud collaboration to promote the large-scale deployment of AI
- 上位机与MES对接的几种方式
- Introduction to smart contract security audit delegatecall (2)
- SaltStack State状态文件配置实例
猜你喜欢

Game between apifox and other interface development tools

Introduction and tutorial of SAS planet software

Why useevent is not good enough

AI时代生物隐私如何保护?马德里自治大学最新《生物特征识别中的隐私增强技术》综述,全面详述生物隐私增强技术

Technology implementation | Apache Doris cold and hot data storage (I)

Geoscience remote sensing data collection online

The efficiency of okcc call center data operation

Starring V6 platform development take out point process

R语言 4.1.0软件安装包和安装教程

Intel and Microsoft give full play to the potential energy of edge cloud collaboration to promote the large-scale deployment of AI
随机推荐
How to customize cursor position in wechat applet rotation chart
How to deal with the problem that the Flink CDC reads MySQL in full and always reports this error
What type of datetime in the CDC SQL table should be replaced
对国产数据库厂商提几个关于SQL引擎的小需求
The script implements the automated deployment of raid0
starring开发HttpJson接入点+数据库
three. Basic framework created by JS
一文理解OpenStack网络
Introduction and download of nine npp\gpp datasets
IBPS开源表单设计器有什么功能?
[leetcode] rotation series (array, matrix, linked list, function, string)
ls 常用参数
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
60 divine vs Code plug-ins!!
The efficiency of okcc call center data operation
目前是不是只cdc 监控mysql 可以拿到新增列的数据 sqlserver不行是吧
Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
The sharp sword of API management -- eolink
ArrayList源码解析
How to select the ECS type and what to consider?