MQ-2 Smoke Detection Tutorial

Detect Smoke using MQ-2 Sensor

Introduction

This tutorial demonstrates how to detect smoke and gas levels using the MQ-2 gas sensor with an Arduino. The MQ-2 sensor is versatile, capable of detecting gases such as smoke, propane, methane, and alcohol. Its affordability and sensitivity make it ideal for safety systems, environmental monitoring, and IoT applications.

By the end of this guide, you will learn how to wire the MQ-2 sensor, read gas concentration values, and interpret results to implement in your own projects.

Required Components

Tip: If you want a visual alert system, consider adding an LED or a buzzer that triggers at a specific smoke level.

Working Principle

The MQ-2 sensor operates using a gas-sensitive material that changes resistance when exposed to specific gases. A built-in heating element increases the sensitivity of the sensor. The Arduino reads the analog output voltage from the sensor, which corresponds to the gas concentration in the environment. By calibrating the sensor, you can detect specific gases with greater accuracy.

The sensor has two outputs:

Circuit Wiring Instructions

To connect the MQ-2 sensor to the Arduino:

  1. VCC Pin: Connect the VCC pin on the MQ-2 sensor to the 5V pin on the Arduino.
  2. GND Pin: Connect the GND pin on the MQ-2 sensor to the GND pin on the Arduino.
  3. A0 Pin: Connect the A0 pin on the sensor to the analog pin A0 on the Arduino for analog readings.
  4. D0 Pin (Optional): Connect the D0 pin to a digital input pin on the Arduino if you want to use the threshold-based digital output.

Optional: Add an LED or buzzer between a digital pin and GND to serve as an alert system when smoke levels exceed a specific threshold.

Arduino Code


/*
 * Smoke and Gas Detection with MQ-2 Sensor
 */

const int mq2Pin = A0;  // MQ-2 sensor connected to analog pin A0
const int ledPin = 13;  // Optional LED connected to digital pin 13
int smokeLevel = 0;

void setup() {
    Serial.begin(9600);  // Start serial communication
    pinMode(ledPin, OUTPUT);  // Set LED pin as output
}

void loop() {
    // Read analog value from MQ-2 sensor
    smokeLevel = analogRead(mq2Pin);

    // Print smoke level to serial monitor
    Serial.print("Smoke Level: ");
    Serial.println(smokeLevel);

    // Trigger LED if smoke level exceeds threshold
    if (smokeLevel > 300) {  // Adjust threshold as needed
        digitalWrite(ledPin, HIGH);  // Turn on LED
    } else {
        digitalWrite(ledPin, LOW);   // Turn off LED
    }

    delay(1000);  // Wait for 1 second
}
        

Note: Adjust the threshold value in the code based on your sensor's environment and calibration.

Sensor Calibration

The MQ-2 sensor needs a warm-up period for accurate readings. After powering the sensor, wait for 20–30 seconds before taking measurements.

To calibrate the sensor:

Results

Once you upload the code and open the serial monitor, you will see the sensor's output values. These values represent the detected gas concentration. Higher values indicate higher smoke or gas levels.

If you connected an LED or buzzer, it will activate when the gas level exceeds the threshold.

Challenges and Solutions

Here are some common issues you might face and how to resolve them:

Applications

Conclusion

The MQ-2 sensor is an affordable and versatile tool for detecting smoke and gases. By following this tutorial, you can build your own gas detection systems for safety, monitoring, or automation purposes. Experiment with different setups and enhance your projects!