Carbon Monoxide MQ-7 Gas Sensor

Introduction

This introduces the MQ-7 Carbon Monoxide (CO) Gas Sensor module and a simple "Hello World" program to interact with the device. The MQ-7 sensor detects carbon monoxide gas concentrations in the air and alerts the user when the levels go past a safe threshold.

Carbon Monoxide is a poisonous gas that has no color, odor, or taste. It is produced as a result of incomplete combustion (i.e. when there is not enough oxygen in the air to make carbon dioxide). Household sources of carbon monoxide include:

  • gas stoves
  • car exhaust
  • candles
  • water heaters
  • butane curling irons

This demo is written for the gas sensor module found here: https://www.parallax.com/product/27983. The breakout board includes the MQ-7 gas sensor, potentiometers, resistors, and transistors. The sensor itself could be used (found here: https://www.parallax.com/product/605-00007) but then it would require manual set up with the other components mentioned previously. However, it can de done, and instructions for doing so are located within the device's data sheet: https://www.parallax.com/sites/default/files/downloads/27983-Gas-Sensor-Board-Guide-v1.0.pdf. The device requires a max of 5V @ 165mA, which should be enough to supply with the LPC1768 microcontroller. If other devices or sensors are to be added, an external power supply with a minimum of 500MA should be used.

Connecting the Gas Sensor Module

There are four pins on the module. Two correspond to powering the device, the others for incoming and outgoing signals that connect to the microcontroller. The ALR pin is an active low digital signal that is set HIGH (5V) when the CO gas concentrations meet a threshold. The mbed writes to the HSW pin via a pulse-modulated signal to control the voltage of the internal gas heater.

MbedMQ-7
DigitalIn (p20)ALR
PwmOut (p21)HSW
VU5V
GNDGND

The CO gas sensor has two phases it cycles through: a purge and a sense phase. During the purge phase, the internal heater of the sensor is powered by the full 5V for 60 seconds. Then there is a low-power sense phase that checks for the ALARM condition at 1.4V for 90 seconds. This low-voltage power can be achieved by a pwm signal where the duty cycle is set to 1.4V/5V, or 0.28. During the sense phase, the resistance of the sensor decreases linearly to the amount of CO gas present in the air, and the module outputs a logic HIGH when the voltage across the MQ-7 sensor is higher than the voltage set by potentiometer R4.

Calibrating the Sensor

Before using the CO gas sensor, a calibration has to be performed. The datasheet has more detailed instructions, but here is a simple numbered list on how to calibrate the sensor:

  1. Adjust potentiometer R3 (Set Point) to read near 200 ohms.
  2. Power the sensor in a clean environment and let stand for 10 minutes.
  3. Adjust potentiometer R4 (Trip Level) until the voltage across TP3(+) and TP4(-) reads between 0.7V and 0.8V.
  4. Apply CO gas/air mixture to the screen of the gas sensor. The voltage across TP1(+) and TP2(-) should exceed 0.7V and the breakout board LED should turn on.
  5. Remove the CO from the environment and allow the gas sensor module to sit in clean air for 10 min.

Simple "Hello World"

#include "mbed.h"
#include "MQ7.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
MQ7 sensor(p21, p22); // ALR, HSW

int main() {
    
    while(1) {
        led1 = 0;
        led2 = 0;
        led3 = 0;
        
        // Purge the device for 60 sec
        sensor.setHeat(1.0f); // supply full 5V to module
        led1 = 1; // Turn on only LED1 during Purge phase
        for (int i = 0; i < 60; i++){
            wait(1); // wait 60 seconds
        }
        
        // Purge complete
        // Sense the device for 90 sec 
        sensor.setHeat(0.28f); // supply 1.4V to module
        led1 = 0; 
        led2 = 1; // Turn on only LED2 during Sense phase
        for (int i = 0; i < 90; i++){
            if (sensor.getAlarm() == 1)
                led3 = 1; // Turn on LED3 if CO gas levels reached
            wait(1); 
        }
        // Sense complete, start over
        wait(0.5);
    }
}

Import programLab4_4180

MQ-7 Gas Sensor demo

Check out this YouTube video to see the carbon monoxide gas sensor in action! LED1 of the mbed is lit during the Purge phase of the sensor (it should remain lit for 60 sec). The it turns off and LED2 is turned on, indicating the Sense cycle. When the unlit cigarette lighter is placed near the screen of the gas sensor, a red LED on the gas sensor module and LED3 on the mbed light up.


1 comment on Carbon Monoxide MQ-7 Gas Sensor:

17 Feb 2019

How to read the value of the CO concentration? please help me

Please log in to post comments.