
1. Introduction
The gas-sensitive material used in the MQ-4 gas sensor probe is tin dioxide (SnO2) with a low electrical conductivity in clean air.When the sensor is in an environment with flammable gases, the conductivity of the sensor increases with the increase of the concentration of flammable gases in the air.Using a simple circuit, the change in conductivity can be converted into an output signal corresponding to the gas concentration.The gas sensor has high sensitivity to liquefied gas, propane, and hydrogen, and the detection of natural gas and other flammable vapors is also ideal.This sensor can detect a variety of flammable gases and is a low-cost sensor suitable for a variety of applications.
2. Schematic

Module Parameters
Pin Name | description |
|---|---|
G | GND (Negative Power Input) |
V | VCC (Positive Power Input) |
S | Signal Pin |
Power Supply Voltage: 3.3V / 5V
Connection method: PH2.0 3P terminal
Installation method: Screw fixed / Lego construction
4, Circuit Board Size

5 of Arduino IDE example program
Arduino UNO Graphical Example Program:
void setup(){
pinMode(11, OUTPUT);
Serial.begin(9600);
digitalWrite(11,LOW);
pinMode(A2, INPUT);
}
void loop(){
//烟雾报警器:有源蜂鸣器接D11,
//烟雾传感器接A2;
//注意烟雾传感器与扩展版接口线序,不要正负极接反。
//当烟雾传感器检测气体或者烟雾时输出低电平(0),
//蜂鸣器有频率的响起。
//打开串口监视器,查看串口烟雾传感器输出值,调节电位器,没有烟雾或者气体,模块指示灯熄灭。
if (digitalRead(A2) == 0) {
//检测到烟雾输出低电平(0),电机工作,led灯与蜂鸣器响
for (int i = 0; i <= 3; i = i + (1)) {
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
delay(200);
}
} else {
digitalWrite(11,LOW);
}
Serial.print("烟雾输出值:");
Serial.println(digitalRead(A2));
delay(10);
}ESP32 Python Example (for Mixly IDE / Micskit)
(Choose the Python ESP32 [ESP32 Generic(4MB)] to switch to code mode upload):
import machine
import music
import time
pin2 = machine.Pin(2, machine.Pin.IN)
midi = music.MIDI(4)
while True:
if pin2.value() == 0:
for i in range(0, 3, 1):
midi.pitch_time(440, 1000)
time.sleep(1)
time.sleep_ms(10)
6, Miciqi Mixly Example Program (Graphical Language)
Arduino UNO Graphical Example Program:Click to download

ESP32 Python Graphical Example Program:Click to download

7, Test Environment Setup
Arduino UNO Test Environment Setup
Prepare Components:
HELLO STEM UNO R3 DEVELOPMENT BOARD *1
HELLO STEM UNO R3 P EXPANSION BOARD *1
USB TYPE-C DATA CABLE *1
Gas Sensor Module (HS-S11L) *1
Active buzzer (HS-F07L) * 1
PH2.0 3P dual-head terminal line *2
Circuit wiring diagram:

ESP32 Python test environment setup
8. Video tutorial
Arduino UNO video tutorial: Click to view
ESP32 Python Video Tutorial:
9. Test conclusion
Arduino UNO Test Conclusion:
Adjust the threshold of the potentiometer on the back of the module, with the gas sensor module powered on, adjust the potentiometer of the sensor module with a small screwdriver, until the sensor signal indicates the blue light is off when there is no gas or smoke interference, and the signal of the gas sensor module indicates the blue light is on when there is gas or smoke.

After the device is connected to the wire, upload the above program to the Arduino UNO development board, open the Mxily serial port monitor, and when the smoke sensor detects gas or smoke, it outputs a low level (0), and the buzzer sounds at a frequency; when no smoke is detected, it outputs a high level (1), and the buzzer does not sound.

ESP32 Python test conclusion:Adjust the threshold of the potentiometer on the back of the module, with the gas sensor module powered on, adjust the potentiometer of the sensor module with a small screwdriver, until the sensor signal indicates the blue light is off when there is no gas or smoke interference, and the signal of the gas sensor module indicates the blue light is on when there is gas or smoke.

After the device is connected to the wire, upload the above program to the ESP32 development board, open the Mxily serial port monitor, when the smoke sensor detects gas or smoke, it outputs a low level (0), and the buzzer sounds at a frequency; when no smoke is detected, it outputs a high level (1), and the buzzer does not sound.
