当前位置:网站首页>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 !
边栏推荐
- 实时渲染:实时、离线、云渲染、混合渲染的区别
- 为什么生命科学企业都在陆续上云?
- 《Go题库·11》channel的应用场景
- Power supply noise analysis
- Introduction and download of nine npp\gpp datasets
- R语言 4.1.0软件安装包和安装教程
- Why are life science enterprises on the cloud in succession?
- Game between apifox and other interface development tools
- cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
- 技术实现 | Apache Doris 冷热数据存储(一)
猜你喜欢

Introduction and download tutorial of administrative division vector data

Why are life science enterprises on the cloud in succession?

SaltStack State状态文件配置实例

Source code analysis of ArrayList

Module V

Freeswitch uses origin to dialplan

论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》

Huawei machine learning service speech recognition function enables applications to paint "sound" and color

Northwestern Polytechnic University attacked by hackers? Two factor authentication changes the situation!

How to use R package ggtreeextra to draw evolution tree
随机推荐
Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data
php OSS文件讀取和寫入文件,workerman生成臨時文件並輸出瀏覽器下載
西北工业大学遭黑客攻击?双因素认证改变局面!
starring开发HttpJson接入点+数据库
Does finkcdc support sqlserver2008?
Why are life science enterprises on the cloud in succession?
为什么生命科学企业都在陆续上云?
php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载
The group offsets of the Kafka of the Flink SQL. If the specified groupid is not mentioned
Freeswitch使用originate转dialplan
程序员如何做自媒体?
Technology implementation | Apache Doris cold and hot data storage (I)
制造业项目MDM主数据项目实施心得
一文详解|Go 分布式链路追踪实现原理
Example analysis of corrplot related heat map beautification in R language
一文理解OpenStack网络
Will the CDC read out of order when I use SQL
佛祖保佑 永无BUG
NFT pledge liquidity mining system development technology
Xiaodi class massive data processing business short chain platform