Smoke Detection using MQ-2 Gas Sensor © LGPL

In this tutorial, we will learn how to detect Smoke and inflammable gases using an MQ-2 sensor.

  • 462,146 views
  • 92 comments
  • 270 respects

Components and supplies

Apps and online services

About this project

In this example, you will read the sensor analog output voltage and when the smoke reaches a certain level, it will make sound a buzzer and a red LED will turn on.

When the output voltage is below  that level, a green LED will be on.

What is an MQ-2 Smoke Sensor?

The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:

  • LPG
  • Butane
  • Propane
  • Methane
  • Alcohol
  • Hydrogen

The resistance of the sensor is different depending on the type of the gas.

The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity according to how accurate you want to detect gas.

How does it Work?

The voltage that the sensor outputs changes accordingly to the smoke/gas level that exists in the atmosphere. The sensor outputs a voltage that is proportional to the concentration of smoke/gas.

In other words, the relationship between voltage and gas concentration is the following:

  • The greaterthe gas concentration,the greaterthe output voltage
  • The lowerthe gas concentration,the lowerthe output voltage

The output can be an analog signal (A0) that can be read with an analog input of the Arduino or a digital output (D0) that can be read with a digital input of the Arduino.

Pin Wiring

The MQ-2 sensor has 4 pins.

Pin-------------------------------------Wiring to Arduino Uno

A0-------------------------------------Analog pins

D0-------------------------------------Digital pins

GND-----------------------------------GND

VCC------------------------------------5V

So, before jumping into the coding part, let's check whether we've assembled all the necessary hardware components.

Kindly refer to the connection schematic attached below. After you've wired all the components properly, it's time to upload the necessary code.

Code

MQ-2 sensor codeArduino
After setting up the hardware components properly, flash this code into your Arduino.
Feel free to adjust the variable " sensorThres " with a different threshold value.
/*******
 
 All the resources for this project:
 https://www.hackster.io/Aritro

*******/

int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;

void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThres)
  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
    tone(buzzer, 1000, 200);
  }
  else
  {
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
    noTone(buzzer);
  }
  delay(100);
}

Schematics

Connection schematic diagram
Circuit 1

Comments

Similar projects you might like

Security Access Using RFID Reader

by Aritro Mukherjee

  • 473,659 views
  • 71 comments
  • 500 respects

Motion Following Motorized Camera Base

Project tutorial by Lindsay Fox

  • 152,012 views
  • 83 comments
  • 388 respects

Portable Arduino Temp/Humidity Sensor with LCD

Project tutorial by ThothLoki

  • 285,564 views
  • 164 comments
  • 399 respects

Easy Motion and Gesture Detection by PIR Sensor & Arduino

Project tutorial by ElectroPeak

  • 93,076 views
  • 14 comments
  • 375 respects

Arduino And MQ2 Gas Sensor

Project showcase by Mahamudul Karim Khondaker

  • 24,673 views
  • 12 comments
  • 24 respects

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 869,681 views
  • 84 comments
  • 488 respects
Add projectSign up / Login