How to Detect Concentration of Gas by Using MQ2 Sensor

31,574

19

28

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.

Share

    Recommendations

    • 1 Hour Challenge

      1 Hour Challenge
    • Classroom Science Contest

      Classroom Science Contest
    • Beauty Tips Contest

      Beauty Tips Contest

    28 Discussions

    0
    None
    BillelB4

    7 weeks ago on Step 4

    The function MQGetgaspercentage ( float rs_r0 ratio,int gas id), gas id is the gas get taget but from where takes his values

    1
    None
    maxior30

    4 months ago

    It took me more than 20h to realise where is mistake. Formula for arduino should have log10(rs_ro_ratio) instead of log(rs_ro_ratio). Small difference but it was not working properly. log() stands for natural logarithm so the base is e number and this is logarithmic scale so it should have base 10. I hope it will help a few people who was trying to figure it out.

    1 reply
    0
    None
    AIS9

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

    2 replies
    0
    None
    LazarV1AIS9

    Reply 1 year 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
    None
    karthik27mechLazarV1

    Reply 4 months ago

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

    0
    None
    karthik27mech

    4 months ago

    hi please give me example code for MQ9 Gas Sensor to measure ppm value of LPG smoke and CO. ext..

    0
    None
    Aung Win Htut

    Question 8 months 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
    0
    None
    KairuK

    Question 9 months ago

    Why am I getting 0 PPM readings every time?

    0
    None
    AgilanK

    Question 11 months ago on Step 4

    why releasing lpg also changes other valus also...........whether these sensor used to measure accurately concentration of gases?

    0
    None
    PeterM439

    Question 11 months 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
    None
    matcha620

    1 year ago

    May I know how to adjust load resistance(RL) which is given to be 5Kohms, do I need to adjust the on board load resistor or what, how should I twist it to get 5kohm

    0
    None
    kapilj17

    Question 1 year ago

    How to adjust load resistance(RL) which is given to be 5Kohms in data sheet..and how clean air resistance (Ro) is taken to be 10Kohms?

    0
    None
    myboticTheThinker

    Reply 2 years ago

    Hi, we are not sure for it. Anyway you may refer to the datasheet
    https://drive.google.com/file/d/0B8OvrwVDp8fCdDV3eDN3YXpsVzg/view

    0
    None
    kapilj17srisha_robotics

    Reply 1 year 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
    None
    riker65

    1 year ago

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

    1 reply
    0
    None
    kapilj17riker65

    Reply 1 year ago

    By comparing with the different slopes give in the data sheet