Smoke Detection using MQ-2 Gas Sensor – Atmega328p Arduino

5,921 views

Today in this tutorial we are going to make a “Smoke Detection Circuit” using MQ-2 Gas Sensor & Atmega328p IC. In this example, you will read the MQ-2 sensor analog output voltage and when the smoke reaches a certain level, it will make the sound of a buzzer, and a red LED will turn on. When the output voltage is below that level, a green LED will be on. So let’s get Started!

This Project is sponsored by PCBWay. They have an open-source community, people can share their design projects with each other. Moreover, every time people place an order for your board, PCBWay will donate 10% of the cost of PCB to you, for your contribution to the Open Source Community.

Hardware Required

Sr NoComponentsValueQty
1Smoke SensorMQ21
2Buzzer1
3LED5mm1
4Resistor1
5Bread Board1
7Jumper wire1

Atmega328p Pinout

MQ2 Pinout

MQ2-smoke-sensor-pinout

Circuit Diagram

Working Explanation

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 gas.

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

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 greater the gas concentration, the greater the output voltage
  • The lower the gas concentration, the lower the output voltage

Atmega328p Code

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);
}

Applications

  • Air quality monitoring.
  • It can also be used in gas leak detection equipment.
  • It may be employed in any safety-related equipment