0

I'm on a project to sense any amounts of methane in the home. I have bought the popular MQ-4 methane sensor from SparkFun: https://www.sparkfun.com/products/9404

I've looked online for any sample code, but I am confused as to whether the input from the sensor is already given in parts per million, or it is just a voltage. To be specific, here is the sample code the data sheet for the sensor gives:

int sensorValue;

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
}

void loop()
{
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println(sensorValue, DEC);  // prints the value read
  delay(100);                        // wait 100ms for next reading
}

I have also used a breakout board for these sensors: https://www.pololu.com/product/1479 The sensor is soldered on it, along with a 20K ohm load resistor, like how the spec. sheet specifies. However, I am confused on the readings I am getting. It's always something that ranges between 259 and 261. Is this ppm of methane in my home? If it is, shouldn't the normal level be 0? I currently have no methane based heating. Or is the 259 - 261 voltage?

Thanks for any help.

2

Actually, you are getting raw data from the sensor. A little bit of math should be done in order to calibrate it and based on the chart in datasheet, measure the real value in PPM.

The calibration basically helps you find R0, which is an internal resistance (along with RS form a voltage divider) that could be derived by doing calibration in a clean environment. After that, you use R0 to calculate a ratio and then look at the datasheet's chart to measure whatever gas you want since there is a curve describing it.

Please refer to this tutorial for more information. I have developed a similar application using MQ-4 before.

It is related to MQ-2, you may have noticed that all theses sensors have similar features and principle applications.

2

The values you're reading relate to the voltage measured by the AD converter, that is, the voltage over the load resistor. Arduino's AD converters have 10 bit resolution and measure against a 5V reference, so you can use the following line to convert it to millivolts:

VRL = map(sensorValue, 0, 1023, 0, 5000);

Once you have the voltage, you can compute the resistance of the sensor using the formula

Rs=(Vc/VRL-1)×RL

with Vc the circuit voltage (5V), VRL the voltage over the load resistor, and RL the resistance of the load resistor in Ohms.

The tricky part is to convert this to a concentration in ppm CH4. The curve in the datasheet gives you a starting point, but the values it gives are not absolute, but relative to the reference of 1000 ppm. The value of that reference depends on various factors, like temperature, humidity, other gases in the environment and how long the sensor has been running (the longer, the more reliable are the results).

If you really need exact ppm values, you'll need to calibrate your setup in an environment where you can exactly control the CH4 concentration. You'll also have to measure temperature and humidity along with the sensor readings.

Otherwise you'll get only a qualitative estimate of CH4 concentration, which is actually sufficient for many use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.