TUTORIALS Arduino

# LPG Sensor with MQ-6 and Arduino

DFRobot Apr 04 2018 1040

### Introduction

#### 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 }

#### MQ-6 LPG Concentration SensorDisplaying 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

#### 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); }