Thursday, July 3, 2014

Arduino MQ-2 Smoke/LPG/CO Gas Sensor Module

In this tutorial we will make a gas leakage detecting system with MQ-2 gas sensor which is sensitive to LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke.

What we need:
Wire module to arduino and upload the sketch.



Alternatively use codebender
Open serial monitor and type 'smoke', 'co' or 'lpg'. Each of these commands will return concentrations of smoke, carbon monoxide and liquefied petroleum gas. You can read more details here.

You can define your own commands by changing the lines below...


After that we will use those values to detect for any king of leakage. We will make a new schedule that will run every 60 seconds and perform evaluation.

As usual please make sure you have properly configure arduino serial port and then enable it.


Let's get dirty
First we need to make a new launcher to retrieve smoke values for this particular example. Go to Instruction Sets menu and press Add New Launcher. Enter a name (handler) and type the following command...

judo serial send smoke


Then our notification launcher using judo mail send API command.
Syntax: judo mail send <from> <to> `<subject>` `<message>`

judo mail send xxx@gmail.com yyy@gmail.com `smoke alert` `Smoke detected *getsmoke ppm`


And finally the Instruction Set that handle the evaluation function. Press Add New Instruction Set, type a name and the following command...

{ evalBool(*getsmoke > 0); sendmailonsmoke; ; }

Note: Zero value can be changed with one of your choice you consider dangerous.


The above action will call the first launcher and get a value from the sensor, then will evaluate if it's greater than zero, if the statement is true the second launcher will be triggered and send us an email notification. Read more about evaluation function.

Now we are ready to create a 60 seconds schedule for task to be repeated. Click on scheduler and press Add New. In the popup window enter a name, period <Repeat>, interval in milliseconds <60000> and the 'smokeschedule' instruction set we had create in order to call the evaluation procedure.


This is it, once we save the schedule it will be activated. You can do the same way for gas (co) and perform a test with a lighter.

Another approach is to trigger an event from the sketch like this example.
You can accomplish that by change the lines below...

void loop(void) {
 
  if (MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_SMOKE) > 500)
    Serial.println("HazardousSmokeDetection");



When the measurement exceeds the value we have set, the 'HazardousSmokeDetection' will be printed to serial port and cause Jubito to execute the corresponding event.

5 comments:

  1. Hello.
    Nice work :) I would like prepare similiar project but with MQ131 ozone sensor, can You tell me about values You take from datasheet ? Can You help me with curve values for MQ131 ?
    Marek

    ReplyDelete
  2. Thank you!
    I have no plan for MQ131, sorry.
    But stay tuned, you'll never know :)

    ReplyDelete
  3. Hi guys,

    What is the curve mentioned in the code and where can I find the curve for every gases detected by MQ-2 to written in the code? Because I want to detect more gases other than LPG, Co and smoke?

    ReplyDelete
  4. Hi, you might want to check out this simple MQ2 library: MQ2Lib

    ReplyDelete
  5. Thanks yanoschik, will do. Meanwhile you can post some of your work with Jubito and your lib!

    ReplyDelete

Note: Only a member of this blog may post a comment.