当前位置:网站首页>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 !
边栏推荐
- Volcano becomes spark default batch scheduler
- 小滴课堂海量数据处理商用短链平台大课
- Volcano成Spark默认batch调度器
- cdc sql表里面的datetime要用什么类型替换
- 60 divine vs Code plug-ins!!
- 应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
- 《Go题库·11》channel的应用场景
- php OSS文件读取和写入文件,workerman生成临时文件并输出浏览器下载
- Interprétation de la thèse (SR - gnn) Shift Robust GNNS: Overcoming the Limits of Localized Graph Training Data
- The group offsets of the Kafka of the Flink SQL. If the specified groupid is not mentioned
猜你喜欢
随机推荐
cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
Introduction to alos satellite
请问一下2.2.0版本支持动态新增mysql同步表吗
Preliminary study nuxt3
How to select the ECS type and what to consider?
Mqtt protocol usage of LabVIEW
假如,程序员面试的时候说真话
对国产数据库厂商提几个关于SQL引擎的小需求
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
请教一个问题。adbhi支持保留一个ID最新100条数据库,类似这样的操作吗
通过SCCM SQL生成计算机上一次登录用户账户报告
物联网?快来看 Arduino 上云啦
Starring develops httpjson access point + Database
网络安全审查办公室对知网启动网络安全审查
60 divine vs Code plug-ins!!
智能合约安全审计入门篇 —— delegatecall (2)
Kubernetes集群部署
Zadig + 洞态 IAST:让安全溶于持续交付
Network security review office starts network security review on HowNet
Multi segment curve temperature control FB (SCL program) of PLC function block series








