Home / Tutorials / Arduino Tutorial / LPG Sensor with MQ-6 and Arduino

LPG Sensor with MQ-6 and Arduino

The MQ-6 is a semiconductor gas sensor device for detecting the levels of propane and butane in the air. Since liquefied petroleum gas (LPG) is composed of these two gases, then the MQ-6 can be used as a LPG sensor.

Introduction

For this tutorial, I will be using the MQ-6 breakout board:

Similar to MQ-3 Alcohol sensor, the MQ-6 has four output pins: A0, D0, GND and VCC. A0 gives out varying voltages corresponding to the level of LPG in the air. D0 goes high when a certain threshold is reached. Otherwise, it stays low. The threshold can be varied by adjusting the trimmer on the board.

The datasheet shows the log-log graph of the resistance of the MQ-6 board with 1000 ppm of LPG (R0) to its resistance when other gases are present (RS):

MQ-6 Resistance Ratio

While it’s able to read other gases, the MQ-6 is most sensitive to LPG based on the graph. We also see that RS/R0 is equal to a constant 10 in air. This fact is useful when we need to calculate the actual LPG concentration (in PPM) later on.

MQ-6 Gas Leak Detector

If you want to detect only the presence of LPG in the air, you only need to connect the AO pin to any analog pin of the Arduino UNO. Then you must determine the threshold value by placing the MQ-6 near a safe LPG source (like an unignited gas stove) and record the reading.

Note that the MQ-6 needs at least 20 seconds to warm up.

You can use this Arduino sketch for determining the threshold value. Connect the AO pin to the Arduino UNO’s A0 pin:

float sensorValue;
float sensorVolts;

void setup()
{
 Serial.begin(9600);      // sets the serial port to 9600
 delay(20000);    // allow the MQ-6 to warm up
}

void loop()
{

 for(int i = 0; i < 100; i++){
     sensorValue = sensorValue + analogRead(0);       // read analog input pin 0
 }

 sensorValue = sensorValue / 100;                  // get average reading
 sensorVolts = sensorValue/1024*5.0;   //convert to voltage
 Serial.println(sensorVolts);  // prints the value read
 delay(100);                        // wait 100ms for next reading
}

For example, if the value in the serial monitor reaches 1.4 V when near the LPG source, then that is your threshold value. You can then proceed to using this sketch:

float sensorValue;
float sensorVolts;

void setup()
{
 Serial.begin(9600);      // sets the serial port to 9600
 delay(20000);    // allow the MQ-6 to warm up
}

void loop()
{
 for(int i = 0; i < 100; i++){ 
    sensorValue = sensorValue + analogRead(0); // read analog input pin 0 
 } 
 sensorValue = sensorValue / 100; // get average reading 
 sensorVolts = sensorValue/1024*5.0; //convert to voltage 
 if(sensorVolts > 1.4){
     Serial.println(“LPG gas detected!”);
 }
 delay(100);                        // wait 100ms for next reading
}

Of course, 1.4V is just an example. You must test your device to determine the actual threshold value.

MQ-6 LPG Concentration Sensor

Displaying the LPG concentration in PPM is much more trickier than just specifying a threshold value. Here, the graph presented above is useful. We need to determine two points from the graph to create an equation. Note that the plot is a log-log plot similar to those other MQ gas sensors.

We select the points:

1000, 1
10000, 0.2

For any line in a log-log plot, the function is as follows:

Here, we substitute  F0 = 1, x0 = 1000 and F1 = 0.2, x1 = 10000.

The relationship between RS/R0 and ppm is therefore:

Solving for PPM:

We can determine the LPG concentration in PPM given the RS/R0 ratio.

Determining the RS/R0 ratio can be done if we determine the R0 of the device first. Recall the R0 is the resistance of the device when 1000 ppm of LPG is present in the air. This is about the same as clean air. In fact, only RS would change for different gases. Noting that RS/R0  = 10 in air according to the graph, we use this sketch to determine R0 of the device (make sure there is no LPG source present when using this):

void setup()
{
   Serial.begin(9600);
}
void loop()
{
   float sensor_volt;
   float RS; //  Get the value of RS via in a clear air
   float R0;  // Get the value of R0 via in LPG
   float sensorValue;

   for(int i = 0 ; i < 100 ; i++)
   {
       sensorValue = sensorValue + analogRead(A0);
   }
    sensorValue = sensorValue/100.0;     //get average of reading
    sensor_volt = sensorValue/1024*5.0;
    RS = (5.0-sensor_volt)/sensor_volt; //
    R0 = RS/10.0; //recall from the plot that RS/R0 = 10 in clean air
    Serial.print("R0 = ");
    Serial.println(R0);
    delay(1000);
}

Note that we skipped the effect of the load RL when we calculated RS in the sketch above since it only presents a minor variation to the actual RS.

Once R0 is determined, we can now use the following sketch to determine the concentration of LPG:

float sensor_volt;
float RS_gas; // Get value of RS in a GAS
float R0 = 15000; //example value of R0. Replace with your own
float ratio; // Get ratio RS_GAS/RS_air
float LPG_PPM;

void setup() {
    Serial.begin(9600);
}
void loop() {
    int sensorValue = analogRead(A0);
    sensor_volt=(float)sensorValue/1024*5.0;
    RS_gas = (5.0-sensor_volt)/sensor_volt;
    ratio = RS_gas/R0;
    x = 1000*ratio 
    LPG_PPM = pow(x,-1.431)//LPG PPM
    Serial.print("LPG PPM = ");
    Serial.println(LPG_PPM);
    Serial.print("\n\n");
    delay(1000);
}

If you find this tutorial helpful or have other questions, kindly drop a comment below!

About Roland Pelayo

Roland Pelayo started TMM in 2015. He is a firmware engineer who has over ten years of experience in developing electronic and microcontroller-based systems. Roland's designs include medical devices, security and automation, robots, emergency alert systems, and educational training modules.   Have something that you like Roland to write about here? or do you need consultation for microcontroller firmware projects? just contact him via the contact page.

Check Also

arduino NPK sensor wiring diagram

Using an NPK Sensor with Arduino

We’ve featured in a previous project how we can make a “plant” send messages when …

3 comments

  1. Hello sir, may i know how you determine these 2 values? y = -30000x + 31000

  2. How about the distance between MQ-6 and LPG source?

  3. Hello. I used the first two programs only since i only want to detect the presence of LPG. The first program worked fine – although the value kept decreasing (it went below 0.9) so im not sure if that’s correct. But i moved on to the second program to detect the presence of LPG. When i verified the code, it displayed an error message – stray ‘\342’. Im not sure why. Could you please help??

Leave a Reply

Your email address will not be published. Required fields are marked *