Skip to content

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 LabelGPIO PinConnected Device
AOGPIO34MQ-2 analog output
DOGPIO4MQ-2 digital output (over-threshold alarm)

MQ-2 requires 1-2 minutes of preheating before readings stabilize.

JSON Configuration Example ​

json
{
  "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

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Smoke Alarm
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Polling Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Polling TriggerPeriodic condition check
    Target PeripheralSelect smoke_01MQ-2 smoke sensor
    Polling Interval20002 seconds
    Condition Expressionvalue > 2000Smoke concentration threshold

Step 4: Configure Actions (2 actions required)

Action 1: Buzzer Alarm

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select HIGH
    • Target Peripheral: Select buzzer_gpio

Action 2: Send Alarm Event

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select Send Event
    • Event Type: alarm
    • Event Message: Smoke concentration too high!
  3. Click Save button

MQ-2 Sensor Specifications ​

FeatureDescription
Detectable GasesLPG, propane, hydrogen, smoke
Preheat Time24-48 hours first time, 1-2 minutes daily
Power Consumption~800mW (heating element)
Lifespan~2-5 years
Cross-SensitivityAlso responds to alcohol, acetone

Notes ​

  1. Preheating: First power-on requires 24-48 hours preheating; daily use requires 1-2 minutes warm-up
  2. Power Consumption: Heating element consumes ~800mW; stable 5V power supply required
  3. Cross-Sensitivity: Also responds to alcohol, acetone, etc.; not smoke-specific
  4. Calibration: Record baseline value in clean air as alarm threshold reference
  5. Lifespan: Sensor lifespan is ~2-5 years; sensitivity gradually decreases

FastBee | fastbee.cn