MQ2 Gas sensor Intro

I am using the MQ2 gas sensor with Arduino UNO and have made connections as follows

Vcc - 5V
SIG - A2

I tested the calibration mentioned in

My results are

  1. R0 = 1.45
  2. ratio = range from 8-10…Thus shows Air from Graph

My query:
The default position of the resistor pot a it shows different RO values at different resistor settings but the answer is around the same range
For better accuracy, What is the default position?


There is no recommended settings for Resistor POT. It depends on the sensitivity range required for your application. Please refer to MQ-2 datasheet for few pointers to set the Load Resistor value (i.e POT).

If you are unsure, keeping the POT resistance at mid point would be sufficient for most applications.

Thanks and Warm Regards.


I made use of the foll codes for using with Arduino UNO

[code]const int analogInPin = A2; // Analog input pin that the potentiometer is attached to
int outputValue;

void setup()
// initialize serial communications at 9600 bps:

void loop()

// read the analog in value:
int sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 100); //Gives the analog value in %

Is the code applicable? it was inspired by documentation @

Your code does not make use of the calculation that are already provided. If you are just looking for detection (i.e sense presense of a particular gas at a threshold), it might be useful.

Thanks and Warm Regards.

My purpose is to simply sense gases.

Are you sure my codes are working in the right manner?

In your code, you are reading the analog value and mapping it to 0 - 100 range. Please understand that this sensor’s voltage range is non-linear. It also depends on the load resistor value (POT).

It is better to use the analog value range 0 - 1023 to set gas detection threshold. If you intened to measure the concentration, follow the direction given in the Wiki.


But by reading data from the analog port gives random values like 50, 60…sometimes 300…etc

I did follow the calibration mentioned in the wiki an got the RS/R0 = 9…depicting air
Is that correct?

The Rs/R0 seems to be correct. BTW, the wiki only provides a method for approximate measurement. The measured value needs to be matched with the graph.

"According to the graph, we can see that the minimum concentration we can test is 100ppm and the maximum is 10000ppm, in a other word, we can get a concentration of gas between 0.01% and 1%. However, we can’t provide a formula because the relation between ratio and concentration is nonlinear. "

Hence, these sensors are suitable for detection & not measurement. Measurement requires using professional equipments to calibarate the sensor. The read value must be matched against professional equipment value.


Would it be good idea to include RS/R0 and match the output with the graph mentioned in the wiki an detect the presence of gas ?

But the RS/R0 is dependant on temp and humidity,so may not be approximate at all times.

Using RS/R0 value and matching to the graph is the closest approximation that can be got without using external calibration.

Yes, these values depend on temperature and humidity.


How do you convert the RS/RO to ppm

As mentioned earlier, these sensors are only suitable for detection not for measurement. You would need to use reference measurement using professional gas measurement tool to correlate.