Introduction: Ardunio Smoke and Gas Sensor(MQ-2)

Picture of Ardunio Smoke and Gas Sensor(MQ-2)

Hello everyone , I have got another super easy arduino tutorial, this time is on the MQ-2 gas and smoke detector. Mostly combustible gases, propane and hydrogen.Its very easy to connect and program. Just using the map function.

Step 1: Parts List / Connection

Picture of Parts List / Connection

The parts needed are :-
-Arduino micro controller
-MQ-2 sensor
-RGB LED indicator
- Breadboard and jumpers

The connection is easy as well.
The MQ-2 has gnd, vcc +5v, Do(digital out) and Ao(analog out). This is because it can work with both analog and digital signal, even though I worked with analog signal here but I can tell you that if you want to work with digital pins using this sensor you should use the arduino pwm pins if not it might not work.
See the image for connections.

Step 2:

Picture of

So the code is simple to understand, the G lights when gas level is greater than 20 and less than or equal to 30, i started from 20 because i noticed that when you map it in an open space the initial values without the presence of combustible gas or smoke is often between 14-19, so safe so zone.

And the B lights up when gas level is greater than 30 and less than 60, the not so good zone. while the R lights up when gas level is greater than 60 and less then or equal to 90, so danger zone. This is my code and you can choose your range of values as you wish.

//GAS sensor output pin to Arduino analog A0 pin
#define R 2 #define G 7 #define B 5
#define MQ2 A0
int gaslevel;
void setup()
{
Serial.begin(9600); //Initialize serial port - 9600 bps
pinMode(MQ2,INPUT);
pinMode(R,OUTPUT);
pinMode(G,OUTPUT);
pinMode(B,OUTPUT);
}
void loop()
{
  gaslevel=(analogRead(MQ2));
  gaslevel=map(gaslevel,0,1023,0,255);
	
 if(gaslevel > 20 && gaslevel <= 30){//gaslevel is greater than 20 and less than 30
    digitalWrite(R,LOW);//green led is off
    digitalWrite(B,LOW);//blue led is off
     _delay_ms(500);//delay
    digitalWrite(G,HIGH);//red led is on
  _delay_ms(500);
  }
  else if(gaslevel > 30 && gaslevel <= 60){//gaslevel is greater than 30 and less than 60
        digitalWrite(R,LOW);//red led is off
         digitalWrite(G,LOW);//green led is off
         _delay_ms(500);
    digitalWrite(B,HIGH);//blue led is on
    
      }
      
       else if(gaslevel > 60 && gaslevel <= 90 ){//gaslevel is greater than 60 and less than 90
        digitalWrite(G,LOW);//red led is off
        digitalWrite(B,LOW);//blue led is off
         _delay_ms(500);
    digitalWrite(R,HIGH);//green led is on
      }
      else
      {
         digitalWrite(G,LOW);//red led is off
        digitalWrite(B,LOW);//blue led is off
    digitalWrite(R,LOW);//green led is off
      }
  Serial.println(gaslevel);//print values on serial monitor
  _delay_ms(100);
}


Step 3: Test Video

you can also change your indicator, maybe a piezo buzzer or motor instead an LED. I made a minute video you can watch it and see how it works.Thank you and have a good day. :)

Comments

latharadhu (author)2017-01-20

Does the above coding calibrate the output because there is no coding for converting the analog read value into ppm provided. can u please tell what the output units displayed on the serial monitor .

kchugh (author)2016-05-07

can someone tell me how to use a motor with mq2 smoke sensor

ryanmudry (author)2015-08-05

So how sensitive would you say it is? Do you think it would detect smoke from downstairs neighbors?

rmikel (author)ryanmudry2015-08-06

This will depend on how dense the smoke is and the sensor settings. if you set your sensor reading to start from a very low value 5 perhaps, then it is going to detect every little presence of smoke and combustible gas in the air around it. It is a very sensitive sensor, but more sensitive to some gases than others. :)

ryanmudry (author)rmikel2015-08-07

Very cool. Thanks. I think I'll give it a shot.

About This Instructable

8,807views

30favorites

License:

Bio: bachelors degree in Electrical Engineering, love developing hardware systems on both microcontrollers and PLC.
More by rmikel:Ardunio Smoke And Gas Sensor(MQ-2)Arduino servo control using Ultrasonic sensorArduino I2C
Add instructable to: