Aritro Mukherjee
Published © LGPL

Smoke Detection using MQ-2 Gas Sensor

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

BeginnerProtip30 minutes603,826

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
MQ-2 Smoke detection sensor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Buzzer
Buzzer
×1
Resistor 221 ohm
Resistor 221 ohm
×3

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connection schematic diagram

Code

MQ-2 sensor code

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

Credits

Aritro Mukherjee

Aritro Mukherjee

5 projects • 367 followers
Associate Developer @ Altimetrik. B.Tech (Electrical Engineering) Enthusiastic about IOT , Robotics and Automation technologies

Comments