How to Use the MQ-7 Carbon Monoxide Sensor

The MQ-7 carbon monoxide gas sensor is especially designed to be sensitive to carbon monoxide (CO) gas which is emitted by vehicles, factories, etc. Since this gas is considered toxic to humans at certain levels, the concentration of CO is used to determine the air pollution in a given area.

Introduction to MQ-7 Carbon Monoxide Sensor

According to its datasheet, the MQ-7 carbon monoxide sensor detects 20 to 2000 ppm of CO in the air. Here is its sensitivity characteristic curve:

This is a graph of Rs/R0 vs. gas concentration in ppm. Rs is the resistance of the sensor in target gas while R0 is the resistance in clean air. We will use this graph later when we create our code.

For this tutorial, I will be using the MQ-7 breakout board which has four output pins as shown:

This breakout board is more convenient as it converts resistance variations to voltage variations. Here is its schematic diagram:

This schematic diagram is the same as with the MQ-3 alcohol sensor and MQ-6 LPG sensor.

There are two ways to read the output from the MQ-7. One is through the DOUT pin which gives a high when the concentration threshold is reached and low otherwise. The threshold can be varied by adjusting the trimmer on the breakout board which is Rp in the schematic.

Meanwhile, the AOUT pin gives varying voltage representing the CO concentration. We can convert the voltage reading to ppm if we look at the characteristic curve above, which is a log-log plot.

We are only interested in the blue line on the plot which gives the CO concentration. The function of a line in such a plot is given as

Where F1, x1, and F0, x0 are any two points in the plot. We can select two points on the plot, as shown:

The encircled two points are approximated to be:

• F1 = 0.25 , x1 = 10
• F0 = 0.065, x0 = 100

Thus, using the equation above:

$F(x)=0.065(\frac{x}{100})^{\frac{log(0.25/0.065)}{log(10/100)}} = 0.0065x^{-0.585}$

or, the relationship between concentration in ppm and RS/R0 is now:

$\frac{R_{S}}{R_{0}}= 0.00065ppm^{-0.585}$

Solving for ppm:

$ppm = (1538.46\frac{R_{S}}{R_{0}})^{-1.709}$

Arduino Sketch for MQ-7

Before we can use this formula in a sketch, we need to determine R0 of the MQ-7 sensor first. This varies between devices so there is a need for actual testing.

From the log-log plot, we can see that RS/R0 is constant in air and is equal to 1. Since by definition, R0 is the resistance of the sensor in clean air, then only RS varies for every gas.

RS is the sensor resistance and forms a voltage divider with the resistor R2 (see schematic diagram above). Thus, RS can be determined if the series resistor R2 from the schematic is known. Most boards use a 2 kilo-ohm resistor for R2.

We can then use this sketch to get R0:

float sensor_volt;
float RS_gas;
float R0;
int R2 = 2000;

void setup() {
Serial.begin(9600);
}

void loop() {
sensor_volt=(float)sensorValue/1024*5.0;
RS_gas = ((5.0 * R2)/sensor_volt) - R2;
R0 = RS_gas / 1;
Serial.print("R0: ");
Serial.println(R0);
}

Once R0 is determined, we can then use this sketch to display the ppm concentration of C0

float RS_gas = 0;
float ratio = 0;
float sensorValue = 0;
float sensor_volt = 0;
float R0 = 7200.0;

void setup() {
Serial.begin(9600);
}

void loop() {
}