Smoke Detector


The incident behind making this was that once in the afternoon I was making coffee and after I hade made it I forgot to switch off the gas regulators. As a result gas was continuously flowing out and the entire kitchen along with its adjacent rooms was smelling. When this smell hit my aunt’s nose she ran to the kitchen and turned off the gas. I recieved a good scolding that day and this urged me to make this project.


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



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

                                                        Hardware Components

 Interfacing with Arduino:


  int redLed = 12;int greenLed = 11;int buzzer = 10;int smokeA0 = A5;// Your threshold valueint 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);}



  • Prevent the spread of fires, increasing security.
  • Avoid damaging or stopping of the industrial production process.
  • Increase efficiency and competitiveness.
  • Efficient and precise monitoring, in real time, for the users.
  • Easy accessing data through PC / tablet / smartphone.
  • Timely detection in critical environments.