MQ-2 Smoke Detection Sensor
The MQ-2 smoke sensor uses tin dioxide (SnO2) as its semiconductor material, which is a surface ion-type N-type semiconductor. At temperatures ranging from 200 to 300°C, the surface of tin dioxide adsorbs oxygen from the air, forming negative oxygen ions, which reduces the electron density in the semiconductor and increases its resistance. When exposed to smoke, the potential barriers at the grain boundaries are altered by the presence of smoke, causing a change in the surface conductivity. This change allows the sensor to detect the presence of smoke. The higher the smoke concentration, the greater the conductivity, the lower the output resistance, and the higher the analog signal output.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-24706531953.12.4cd36a4bho6MgR&id=522572009794
Baidu Netdisk Download Link:
https://pan.baidu.com/s/1ETxqg03p5fEjKS7AZ2kV6w
Password: dfr1
Specifications
Operating Voltage: 5V
Operating Current: 150mA
Output Method: DO interface for digital output, AO interface for analog output Reading Method: ADC
Pin Count: 4 Pin (2.54mm pitch header)
Hardware Connection
MQ-2 smoke sensor has high sensitivity to liquefied gas, natural gas and city gas. It should be noted that: it must be heated for a period of time before use, otherwise its output resistance and voltage are inaccurate. Its range of detecting combustible gas and smoke is 100~10000ppm (ppm is volume concentration. 1ppm=1 cubic centimeter/1 cubic meter). With dual signal outputs (analog output AO and digital output DO). When the gas concentration does not exceed the set threshold, the digital interface DO port outputs a low level, and the analog interface AO voltage is basically about 0v; when the gas influence exceeds the set threshold, the module's digital interface DO outputs a high level, and the analog interface AO outputs a voltage that will slowly increase as the gas influences. The threshold is controlled by an adjustable resistor on the module.
Its corresponding schematic diagram is shown in the figure below. AO output is the voltage directly output from the MQ-2 sensor, so it is analog; DO is the output high and low level after voltage comparison by LM393, so it is digital. Specific principles see the hardware connection of the photoresistor light sensor chapter.
Therefore the DO pin can be configured for GPIO input mode and the AO pin needs to be configured for ADC analog input mode.
- The Vcc terminal of the sensor is connected to the 5V supply of the development board;
- The GND terminal is connected to the GND of the development board;
- AO (analog signal output) is connected to the A0 analog input pin of the development board;
- DO (digital signal output) connects to pin 8 of the development board;
Usage Method
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 8, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
int MQ2_AO_Pin = A0; // 定义烟雾电阻传感器的AO连接到开发板的A0引脚
int MQ2_DO_Pin = 8; // 定义烟雾传感器的DO连接到开发板的8号引脚
int MQ2Value = 0; // 用于存储烟雾浓度值的变量
#define ADC_MAX_VALUE 1023 //ADC的最大采集值
void setup() {
Serial.begin(9600); // 开始串行通讯,设置波特率为9600
pinMode(MQ2_DO_Pin, INPUT_PULLUP);
}
void loop() {
// 读取按钮的状态
int MQ2State = digitalRead(MQ2_DO_Pin);
if (MQ2State == LOW) {
Serial.println("检测到高浓度烟雾");
} else {
Serial.println("检测到低浓度烟雾");
}
MQ2Value = analogRead(MQ2_AO_Pin); // 读取A0引脚的电压值
Serial.print("烟雾浓度: ");
Serial.println( MQ2Value); // 将读取的值发送到电脑的串行监视器
delay(1000); // 延时1秒
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39