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:

MQ-7 Carbon Monoxide Sensor 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:

MQ3 schematic

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:

MQ-7 Plot annotatedThe encircled two points are approximated to be:

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

Thus, using the equation above:

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

Solving for ppm:

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() {
  int sensorValue = analogRead(A0);
  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);
}

[the_ad id="3059"]

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() {
   sensorValue = analogRead(A0);
   sensor_volt = sensorValue/1024*5.0;
   RS_gas = (5.0-sensor_volt)/sensor_volt;
   ratio = RS_gas/R0; //Replace R0 with the value found using the sketch above
   float x = 1538.46 * ratio;
   float ppm = pow(x,-1.709);
   Serial.print("PPM: ");
   Serial.println(ppm);
   delay(1000);
}

Upload the sketch above to your Arduino, open your serial monitor and now you have an Arduino carbon monoxide sensor! Use this with a smartphone app and detect C0 levels in your surrounding. If it's above 35 ppm, that’s already toxic and you should leave right away!

 

      Leave a Reply

      Your email address will not be published. Required fields are marked *