$USD
  • EUR€
  • £GBP
  • $USD
TUTORIALS Arduino

LPG Sensor with MQ-6 and Arduino

DFRobot Apr 04 2018 552

The MQ-6 is a semiconductor 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 graph of the resistance of the MQ-6 board with 1000 ppm of LPG (R0) to its resistance when other gases are present (RS):

While it’s able to read other gases, the MQ-6 is most sensitive to LPG based on the graph. The breakout board simplifies things for us because it converts resistance changes into voltage.

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. The most obvious are:

1000, 1
10000, 0.7

Based on these two, the linear equation for the LPG curve should be:

y = -30000x + 31000

Where y is the concentration in PPM and x is the RS/R0 ratio.

But before that, we must first determine the RS/R0 ratio. This 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. Use this sketch to determine R0 of your 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; // 10 is found using interpolation
    Serial.print("R0 = ");
    Serial.println(R0);
    delay(1000);
}

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

void setup() {
    Serial.begin(9600);
}
void loop() {
    float sensor_volt;
    float RS_gas; // Get value of RS in a GAS
    float ratio; // Get ratio RS_GAS/RS_air
    float LPG_PPM;
 
    int sensorValue = analogRead(A0);
 
    sensor_volt=(float)sensorValue/1024*5.0;
 
    RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL /*-Replace the name "R0" with the value of R0 in the demo of First Test -*/
 
    ratio = RS_gas/R0;  // ratio = RS/R0
    LPG_PPM = -30000*ratio + 31000 //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!

Thanks for Teachmemicro.com. The original tutorial is from here.

REVIEW