How to Detect Concentration of Gas by Using MQ2 Sensor

49,248

20

41

Introduction: How to Detect Concentration of Gas by Using MQ2 Sensor

MQ-2 Gas sensor is used to detect the gas level around the area. This sensor able to use as home or factory gas leak monitoring, suitable for gas, butane, propane, methane, alcohol, hydrogen, smoke and other monitoring devices.

Specification:

  • Size: 35mm x 22mm x 23mm (length x width x height)
  • Main chip: LM393, ZYMQ-2 gas sensors
  • Working voltage: DC 5 V
  • Characteristics:
  1. With a signal output instruction.
  2. Dual signal output (analog output, and high/low digital output)
  3. 0 ~ 4.2V analog output voltage, the higher the concentration the higher the voltage.
  4. Better sensitivity for gas, natural gas, city gas.
  5. With a long service life and reliable stability.
  6. Rapid response and recovery characteristics.

Step 1: Gather Materials

Step 2: Understanding Pin Definition of MQ2 Gas Sensor

Step 3: Set Up the Circuit Above

LCD pins

-Pins D7 , D6 , D5 , D4 connect to arduino digital pins 2,3,4,5 respectively.

-Pins A and K connect to 5V and GROUND respectively

-Pins VSS and VDD connect to Ground and 5V respectively.

LED

-Use as a LED indicator for the calibration process of the MQ2 gas sensor

-Connect to digital pin 13 of Arduino Uno

MQ2 Gas Sensor

-Analog output connect to the A0 of arduino

Potentiometer

-Center pin connect to the V0 of LCD display

-Other two pins just connect to 5V and GROUND respectively

*Note: All of pins above is configured regarding the circuit figure above. You can configure the connection yourself regarding your favourite.

Step 4: Programming the Arduino Uno

As you can see in the graph above , it shows several gases.

The values are plotted on a semilog paper, as you can see the values indicate 100......1000.....10000 ppm.

These values when plotted on a normal graph would represent a curve like an exponential one.

Formula In the Coding

pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0]))

Based on the graph MQ2, the derivation of ppm formula will be:

Y - y1 = m( X - x1)

X= (y-y1)/m + x1

X= (Rs/Ro-y1)/m + x1

log X =(log (Rs/Ro) - y1)/m +x1

X =10^( (log (Rs/Ro) - y1)/m +x1)

*Note: X = ppm on the graph

Y= Rs/Ro

***The derivation formula are same and can be used for other types of MQ gas sensor.

If you have any problem about the coding, you are welcome to ask any question in the comments below or contact us for further details.

2 People Made This Project!

Recommendations

  • Battery Powered Contest

    Battery Powered Contest
  • Plywood Challenge

    Plywood Challenge
  • Plastic Contest

    Plastic Contest

41 Discussions

0
maww100
maww100

11 months ago

Hi, I used your code but it returns 0 PPM for all three gasses. Blowing smoke through the sensor does not change the smoke reading. Do you know why?

0
gabriels1
gabriels1

Question 1 year ago

Hello! Very good tutorial. What's the role of the potentiometer? What if I don't put one? Thanks!

0
Farrukh_
Farrukh_

Answer 12 months ago

it seems pot is just for lcd backlight, if you don't have lcd, it isn't needed

0
gabriels1
gabriels1

Reply 12 months ago

Good, clear. Many thanks Farrukh!

0
chandrasekhar3841
chandrasekhar3841

1 year ago

Hi Sir, I tried interfacing gas sensor with Arduino. it is not showing correct values. Does the position of the gas sensor have any effect on the readings?

0
riker65
riker65

3 years ago

Hi how do you distinguish the different gases? this is not clear to me

0
TheerapongSanthaveesuk
TheerapongSanthaveesuk

Reply 1 year ago

No, you can't.

The same raw data from analog pin used to calculate Rs and then, Gas concentration from different slope's equation. Therefore, you get the ppm value of all gases even though you didn't expose the sensor to those gases.

0
kapilj17
kapilj17

Reply 2 years ago

By comparing with the different slopes give in the data sheet

1
PeterM439
PeterM439

Question 2 years ago on Step 4

In the video, you start up the arduino, it calibrates, and consequently, all readings say 0 ppm. This I understand, but the you open the lighter, releasing flammable gas (probably similar to LPG), and then the readings for CO and Smoke also rise. I think there is a error in reasoning: the values should be read as possible values: either this much ppm LPG, or this much CO, or this much Smoke, or possibly all at the same time. But it is impossible to distinguish between the gases, since any combination of gases, or a rise in the concentration of one, gives the same reading. Maybe this could be clearer, for the code and the readings are very ambiguous otherwise.

0
TheerapongSanthaveesuk
TheerapongSanthaveesuk

Answer 1 year ago

1. This is a very very cheap sensor, so the accuracy is poor, the selectivity of gases is also bad.
2. The high price/ high performance sensor will give a far better result for many quality; sensitivity, selectivity, recovery time and so on.
3. if you need to used this type of sensor for more performance, Fabricated them as the sensor arrays might help you to get better result.
4. The same raw data from analog pin used to calculate Rs and then, Gas concentration from different slope's equation. Therefore, you get the ppm value of all gases even though you didn't expose the sensor to those gases.

0
AIS9
AIS9

3 years ago

If i may ask, how did you get these values LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve.

0
LazarV1
LazarV1

Reply 2 years ago

log(200)=2,3 (200 is first point from ppm axe)

log(1.6)=0.21 (0.21 is first point from Rs/Ro axe)

log(10000)=4(last point from ppm axe )

log(0.25)= -0.6 (last point from Rs/R0 axe)

and with (2.3, 0.21, 4, -0.6) will obtain slope =-0,47

0
ARDUINOIDE
ARDUINOIDE

Reply 1 year ago

How can i obtain the slope of the graph??

0
TheerapongSanthaveesuk
TheerapongSanthaveesuk

Reply 1 year ago

finding the slope is basic.
But, finding the correct value of the point from log-log graph is not easy.

0
karthik27mech
karthik27mech

Reply 1 year ago

how do you get -0.47?
Slop=(y2-y1)/(X2-X1)=(-0.6-0.21)/(4-0.23)=0.214

From,

X= (Rs/Ro-y1)/m + x1

log X =(log (Rs/Ro) - y1)/m +x1

Why you take log only (Rs/Ro) , not the whole equation?

0
srisha_robotics
srisha_robotics

3 years ago

HI . from the graph how to find x y and slope .. pls help me out

0
kapilj17
kapilj17

Reply 2 years ago

first take 2 points from the graph, find y axis co-ordinate and x-axis co-ordinate, since it is log-log graph, find respective log values of each co-ordinate with base 10,then substitute in (y2-y1)=m(x2-x1), where "m" is slope..

0
TheerapongSanthaveesuk
TheerapongSanthaveesuk

Reply 1 year ago

Since it is a log scale, you will not get the correct value.

1
Aung Win Htut
Aung Win Htut

Question 2 years ago

Bro, I have done too, but I got unreasonable large amount of PPM value after detection of gas. How can we solve this problem please?

IMG_20181026_023802.jpg