Example 35: Smoke Sensor (MQ-2)
About 1 min
Example 35: Smoke Sensor (MQ-2)
Experiment Overview
The MQ-2 gas sensor detects combustible gases (LPG, propane, hydrogen) and smoke concentration, outputting an analog signal. Suitable for kitchen gas leak alarms, smoke fire alarms, and other safety scenarios.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| AO | GPIO34 | MQ-2 analog output |
| DO | GPIO4 | MQ-2 digital output (over-threshold alarm) |
MQ-2 requires 1-2 minutes of preheating before readings stabilize.
JSON Configuration Example
{
"peripherals": [
{
"id": "smoke_01",
"name": "MQ-2 Smoke",
"type": 15,
"enabled": false,
"pins": [34],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario: Smoke Alarm (Polling Trigger)
Feature: Trigger buzzer alarm when smoke concentration is too high (ADC > 2000)
Web UI Configuration Steps
Step 1: Ensure Buzzer Peripheral is Configured
- Peripheral ID:
buzzer_gpio - Type: GPIO Output
Step 2: Create Rule
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Smoke Alarm - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: Configure Trigger (Polling Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Polling Trigger Periodic condition check Target Peripheral Select smoke_01MQ-2 smoke sensor Polling Interval 20002 seconds Condition Expression value > 2000Smoke concentration threshold
Step 4: Configure Actions (2 actions required)
Action 1: Buzzer Alarm
- Click Add Action button
- Fill in:
- Action Type: Select HIGH
- Target Peripheral: Select
buzzer_gpio
Action 2: Send Alarm Event
Click Add Action button again
Fill in:
- Action Type: Select Send Event
- Event Type:
alarm - Event Message:
Smoke concentration too high!
Click Save button
MQ-2 Sensor Specifications
| Feature | Description |
|---|---|
| Detectable Gases | LPG, propane, hydrogen, smoke |
| Preheat Time | 24-48 hours first time, 1-2 minutes daily |
| Power Consumption | ~800mW (heating element) |
| Lifespan | ~2-5 years |
| Cross-Sensitivity | Also responds to alcohol, acetone |
Notes
- Preheating: First power-on requires 24-48 hours preheating; daily use requires 1-2 minutes warm-up
- Power Consumption: Heating element consumes ~800mW; stable 5V power supply required
- Cross-Sensitivity: Also responds to alcohol, acetone, etc.; not smoke-specific
- Calibration: Record baseline value in clean air as alarm threshold reference
- Lifespan: Sensor lifespan is ~2-5 years; sensitivity gradually decreases
