Arduino Air Monitor Shield. Live in a Safe Environment.




Introduction: Arduino Air Monitor Shield. Live in a Safe Environment.

About: Electronics hobbyist

In this Instructabe I am going to make a Air monitoring shield for arduino. Which can
sense LPG leakage and CO2 concentration in our atmosphere.
And also beeps a buzzer turns on LED and the exhaust fan whenever LPG is detected or the concentration of CO2 increases.
As this was made to be work in home it does not need to be accurate, but it should be somewhat meaning full and should be suited for our application.
As I was using this to turn on the exhaust fan when there was any LPG gas leakage or increase of CO2 and other harmful gases level. This was to protect the family members health condition and prevent dangers that can be caused by leakage of LPG gas.
let's get started.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Gather Parts!!!!!!

Gather these parts:

Main parts

1. Arduino Uno.
2. 16x2 lcd display.
3. MQ2.
4. MQ135.
5. RELAY 12v (current rating according to
your exhaust fan's specifications).
6. 12 volts power supply (for relay module).

Common parts

1. Male and female headers.
2. Dot PCB.
3. Buzzer.
4. LEDs.
5. Resistors(R1=220, R2, R3=1k)
6. NPN transistor.(2n3904)
7. Enclosure box
8. some wires.
9. Dc jack.
let's do it!!!!!.

Step 2: Deep Into the MQ Gas Sensors.

Lets get to know about the MQ series gas sensors.

MQ series gas sensors have 6 pins, in which 2 of them is heaters and other 4 of them are sensor pins, whose resistance depends on the concentration of the various gases according to their sensitive layer.

Heater pins H1, H2 are connected to 5 volts and ground( Polarity doesn't matters).

Sensor pins A1,A2 and B1,B2

Use any one either A or B .( in schematic both are used, it is not required ).

connect A1(or B1) to 5 volts and A2(or B2) to RL (which is connected to the ground).

A2(or B2) is the analog output which should be connected to the analog input of the Arduino.

As the resistance of the sensor pins varies with change the concentration of gases, the voltage across the RL changes which is the analog input for the arduino.

By analysing the graph of the sensors given in the datasheet we can convert that analog reading into concentrations of the gases .

These sensors need to be heated for 24 hours to 48 hours to get a stabilised readings .( the heating time is shown as pre-heat time in the datasheet )

Accuracy can not be achieved without proper calibration , but for our application it is not needed.

have a look at these datasheets.


As in the above schematic R6 is the RL for MQ2 .

datasheet of MQ2 suggests RL to be between 5K ohms and 47K ohms.

It is sensitive to gases like: LPG,Propane,CO,H2,CH4,Alcohol.

here, it will used for detecting LPG.

Any other MQ sensors which is sensitive to LPG can be used

like: MQ5 or MQ6.


As per the above schematic R4 is the RL for MQ135.

datasheet suggests RL to be between 10K ohms and 47K ohms.

It is sensitive to gases like : CO2 , NH3, BENZENE, Smoke etc.,

here, it is used to detect CO2 concentration.

Step 3: Making and Calculating.

Build your circuits according to the schematics.

In my circuits you can see the modules of gas sensors . I modified their circuitry to the above schematic.

leave the sensors to heat for 24 hours to 48 hours according to the pre heat time. while that time lets analyse the graph of the MQ135 to get the equation for CO2.

By looking at the graph we can say that i is log-log graph .

for such graphs equation of the graph is given by:

log(y) = m*log(x)+c


x is the ppm value

y is the the ratio of Rs/Ro.

m is the slope .

c is the y intercept .

To find "m" slope:

m= log(Y2)-log(Y1) / log(X2-X1)

m=log(Y2/Y1) / log(X2/X1)

by taking the points on the CO2 line the average slope of the line is -0.370955166.

To find "c" Y-intercept:

c= log(Y)- m*log(x)

considering m value in the equation and taking the X and Y values from the graph.

we get average c to be equal to 0.7597917824

The equation is :

log(Rs/Ro) = m * log(ppm) + c

log(ppm) = [log(Rs/Ro) - c] / m

ppm = 10^{[log(Rs/Ro) - c] / m}

Calculating R0:

we know that ,



VRL is the voltage drop across the resistor RL

V is the applied voltage.

RL is the resistor (see the diagram).

RT is the total resistance.

in our case,

VRL= voltage across RL = analog reading of the arduino*(5/1023).

V =5 volts

RT =Rs(refer datasheet to know about Rs).+ RL.

therefore , Rs = RT-RL

from equation- VRL= V*RL / RT.


and Rs = (V*RL/VRL)-RL

we know that ,

the concentration of CO2 is 400 ppm currently in atmosphere.

so by using the equation

log(Rs/Ro) = m * log(ppm) + c

we get Rs/Ro = 10^{[-0.370955166* log(400)] + 0.7597917824}

Rs/Ro = 0.6230805382.

which gives Ro=Rs/0.623080532.

use the code " to get Ro " and also note the value of V2( in fresh air).
and also note down the value of R0.

I programmed in such a way that the Ro, V1 and V2 are displayed both on serial monitor and LCD.(Because I don't want to keep my PC stay on until the readings stabilise ).

Step 4: The Code......

here is the link to download codes from GitHub.

The program is very simple and can be easily understood .

In the code "to_get_R0". I have described the

MQ135 analog output as sensorValue.

RS_CO2 is the the RS of the MQ135 in 400 ppm CO2 which is the current concentration of the CO2 in Atmosphere.

R0 is calculated using the formula derived in the previous step.

sensor1_volt is the conversion of anolog output of MQ135 into voltage.

sensor2_volt is the conversion of analog output of MQ2 into voltage.

these are displayed both on the LCD and Serial monitor.

In the code " AIR_MONITOR"

After adding the LCD library.

we start by defining the connections of the buzzer, led, MQ2, MQ135, Relay.

Next in setup, we define whether the connected components are input or output and also there states(i.e, high or low).

Then we begin LCD display and make it to display as "Arduino Uno Air Monitor Shield" for 750 milli seconds with a beep of buzzer and LED.

Then we set all the output states to low.

In loop

We first define all the terms that we use in the formula for calculation that I said in previous step.

Then we implement those formulas to get concentration of CO2 in ppm.

Define your R0 value in this section.(which I said to note down while running the previous code).

then we display the concentration of the CO2 in the LCD.

using " if " function we use the threshold limit for the ppm value which I have used as 600 ppm.

and also for the MQ2 voltage we use " if " function to set the threshold limit for it.

we make the buzzer , led, relay to go high for 2 seconds when the if function is satisfied ad also make the LCD to display LPG as Detected when MQ2's voltage is higher than the threshold limit.

Define your threshold limit for MQ2's voltage that you noted down during the previous code as V2.(set this slight higher than that value).

After this we will define " else " function and delay the loop for 1 second.

Instead of using Delay to set the output high for 2 seconds in the if function it is good to use a simple timer.

If anybody could modify the delay into timer in the code, you are always welcomed and let me know that in the comment section.

Step 5: It Works!!!!!!!!

Here is the video to demonstrate that it is working.

sorry I could not show the relay in the video.

you can notice that the Concentration of CO2 increases madly because the gases released from the lighter also poses effect on the MQ135 which is sensitive to other gases also but don't worry it will come back to normal after few seconds.

Sensors Contest 2017

Participated in the
Sensors Contest 2017

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    13 Discussions


    1 year ago

    Excuse me sir do you know why my v2 and v1 value is just 0.1x which makes my r0 value become too big (ex 2021682)

    Maker BR
    Maker BR

    Reply 1 year ago

    there is no relation between V1 and R0.
    R0 is treated to V2 only.
    check your RL resistance value, Be sure to enter the same value in the code.


    Reply 1 year ago

    Is analog read supposed to be unstable because the ppm value varys a lot

    Maker BR
    Maker BR

    Reply 1 year ago

    it should not vary more than +/-10ppm,
    if it is varying more than that then you have not pre-heated the sensor.
    the sensor to have stable readings it should be pre-heated for 24-48 hrs.(acc. to the datasheet)


    1 year ago

    May i know where u get the 32850 value from?

    Maker BR
    Maker BR

    Reply 1 year ago

    Hello there, it is the value of the resistor RL( R4 in the schematic). I measured it using multimeter for accurate readings.


    2 years ago

    really helpful, thanks


    3 years ago

    I made it but I used optical dust sensor from sharp its name is AEROBOT u can search for it


    Reply 3 years ago

    the project's name is AEROBOT


    Reply 3 years ago

    here it is

    Maker BR
    Maker BR

    Reply 3 years ago

    Good project.
    I have already seen it.
    But the cost of Mq sensors are cheap and I actualy made it for our kitchen to sense LPG gas leakage.


    3 years ago

    Great sensor project.

    Maker BR
    Maker BR

    Reply 3 years ago