Skip to Content

Arduino and MQ7 CO Sensor – A Complete Guide

Arduino and MQ7 CO Sensor – A Complete Guide

Are you interested in building a project that can detect levels of carbon monoxide (CO) in the air? In this article, I’ll show you how to do this with the Arduino UNO and MQ7 CO Sensor.

I’ll share step-by-step instructions on connecting the sensor to an Arduino board, an example code you can use, and show you how to use the readings from the sensor to trigger alerts or other responses in your project. 

I’ll also answer the most frequently asked questions about the MQ7 carbon monoxide sensor.

Whether you’re building a home safety system or a personal CO monitor, the MQ7 sensor can be a valuable tool in your toolkit.

So, grab your Arduino board and let’s get started!

-> Read our guide about What You Can Build with Adruino.

Components Needed To Build Arduino And MQ7 CO Sensor Project

Hardware Components

Software is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on

Basics of The Carbon Monoxide Sensor MQ7

In this section, we will understand the basics of the low-cost MQ-7 CO sensor module. The MQ-7 sensor is a gas sensor that can detect levels of carbon monoxide (CO) in the air.

This sensor is commonly used in applications requiring indoor air quality monitoring and control, such as in homes, offices, and industrial facilities.

The MQ-7 sensor works by measuring the resistance changes that occur when CO molecules are absorbed onto the surface of its sensing element.

MQ7 module mounted on the PCB

The image is a typical representation of the build of the sensor which is usually not visible when you buy the MQ7 module mounted on the PCB. On the right, you can also see the labeled parts of the sensor. 

The sensing element is typically made of a tin dioxide (SnO2) film deposited on a ceramic substrate.

When the sensor is exposed to CO, the gas molecules react with the SnO2 film, which causes the film’s electrical resistance to decrease. 

This change in resistance is proportional to the concentration of carbon monoxide in the air.

The graph below illustrates how the performance of the sensor is affected by temperature and humidity.

Although there may be some fluctuations, these variations can be predicted and modeled to a certain degree.

performance of the sensor

As a result, it is possible to compensate for these effects and improve the accuracy of the sensor.

The sensor converts this change in resistance to an electrical signal, which can be processed by a microcontroller or other electronic circuitry.

To operate the MQ-7 sensor, a small amount of current (usually around 100mA) is passed through the sensing element.

This current is controlled by a heater element that is built into the sensor.

The heater ensures that the sensing element remains at a constant temperature, which helps to improve the sensor’s accuracy and sensitivity.

One important consideration when using the MQ-7 sensor is its sensitivity to other gases, such as methane and propane, which can also cause changes in the sensor’s resistance.

To address this issue, you can calibrate the sensor to detect only CO at a specific concentration range.

In addition to its use in indoor air quality monitoring, the MQ-7 sensor is also used in automotive applications, such as in vehicle emissions control systems.

You can also use MQ7 sensors in portable gas detectors, such as those used by firefighters and other first responders.

Features of the MQ7 Carbon Monoxide Gas Sensor

Here are the features of Arduino-compatible MQ7 CO sensor:

  • High sensitivity: The MQ-7 sensor has a high sensitivity to carbon monoxide gas, making it ideal for use in applications where low levels of CO need to be detected.
  • Fast response time: The MQ-7 sensor has a fast response time, meaning it can detect changes in CO levels quickly.
  • Low power consumption: The MQ-7 sensor has a low power consumption, making it suitable for use in battery-powered applications.
  • Simple interface: The MQ-7 sensor has a simple analog output that can be easily read by a microcontroller (Arduino UNO analog input).
  • Wide operating voltage range: The MQ-7 sensor can operate over a wide voltage range, typically from 2.5 V to 5.5 V.
  • Compact size: The MQ-7 sensor is relatively small in size, making it easy to integrate into different systems.
  • Stable performance: Provides you reliable data over a wider operating temperature range.
  • Low cost: The MQ-7 sensor is an affordable option for measuring carbon monoxide gas levels.

Special note on safe Carbon Monoxide levels: 

Carbon monoxide is a sneaky gas that you can’t see or smell, but it can cause serious illness if you breathe in too much of it. 

The danger level of CO depends on how long you’re exposed to it and factors like your age, health, and activity level.

Basically, you shouldn’t breathe in more than 50 parts per million of CO over an 8-hour workday, and you definitely don’t want to go above 400 ppm for more than 15 minutes at a time (and no more than four times a day). 

Going over these limits can give you headaches, nausea, and other unpleasant symptoms, or even put you in a coma or worse!

So if you’re working in any environment where CO is produced, make sure you’ve got good ventilation, CO detectors, and that you’re following safety protocols.

Take care while testing your sensor.

Pin Details Of The MQ7 Carbon Monoxide Sensor

Let’s have a closer look at the MQ7 Carbon monoxide module.

MQ7 Carbon monoxide module

You may have a different looking module. The overall guide still remains the same. 

DOUTDigital Output
AOUTAnalog Output
GNDGround connection
VCCPower Supply

Here is the pin description of the pins of the MQ7 sensor module:

  1. DOUT– This pin generates a digital signal that indicates whether the preset threshold for Carbon Monoxide has been exceeded or not.
  1. AOUT – The output signal from this pin is analog, and it measures the level of Carbon Monoxide detected by the sensor. This analog output allows for a more precise determination of the appropriate actions to take in response to the CO level.

Additionally, the analog signal can be used to display the level of CO in various formats, such as a LED graph or as a percentage. This flexibility is not available with a digital output alone.

  1. GND – Ground connection
  1. VCC – Arduino 5 V

The module also optionally may house two LEDs, one to indicate the power and the other one to indicate the digital output.

-> Read our article about How Easy Is It To Learn Arduino?

Step-By-Step Instructions To Connect The MQ7 Carbon Monoxide Sensor With Arduino UNO

In this section, we will build a project using Arduino UNO and the MQ7 carbon monoxide sensor. The connections are easy to make, so let’s get started.

How To Connect The MQ7 Carbon Monoxide Gas Sensor To Arduino UNO?

Below is the step-by-step connection guide to complete the Arduino and the MQ7 Carbon Monoxide sensor.

Step 1: Start with the GND connections

Start with the GND connections

Connect the GND pin of the MQ7 module to the GND of the Arduino. Choose any GND pins available on the Arduino for the connection. It is always good practice to start with the GND connections. 

Step 2: Connect the DOUT line

Connect the DOUT line

You can hook up the DOUT pin of your MQ7 sensor to pin 8 on your Arduino UNO, or really any other digital input that works for you.

Step 3: Connect the AOUT line

Connect the AOUT line

Connect the AOUT pin on the MQ7 sensor to A0 on the Arduino, as shown here in the diagram.

Step 4: Connect the Power line (Red wire)

Connect the Power line (Red wire)

Connect the VCC pin on the MQ7 sensor to the 5 V pin on the Arduino UNO.

Step 5: Verify the complete Connection

Verify the complete Connection

You can now sense the CO in the air. Congratulations. This completes the required hardware connections.

Let’s take a look at some code you can use with the device.

Arduino Code Example For The MQ7 Sensor Module Project

In this section, you can find the complete Arduino sketch and the information on installing the necessary libraries. 

The complete Arduino Code For The MQ7 Arduino Project Example

/* MQ-7 Carbon Monoxide Sensor Circuit with Arduino */
const int AOUTpin = 0; //the AOUT pin of the CO sensor goes into analog pin A0 of the arduino
const int DOUTpin = 8; //the DOUT pin of the CO sensor goes into digital pin D8 of the arduino
const int ledPin = 13; //the anode of the LED connects to digital pin D13 of the arduino

int limit;
int value;

void setup() {
  Serial.begin(115200);//sets the baud rate
  pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
  pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino

void loop()
  value = analogRead(AOUTpin); //reads the analog value from the CO sensor's AOUT pin
  limit = digitalRead(DOUTpin); //reads the digital value from the CO sensor's DOUT pin
  Serial.print("CO value: ");
  Serial.println(value);//prints the CO value
  Serial.print("Limit: ");
  Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
  if (limit == HIGH) {
    digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
  else {
    digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off

Let’s walk through the code. 

The below lines specify the Arduino pin connections with the sensor. The analog pin of the sensor is connected to the A0 pin of the UNO.

The digital output pin is connected to the Pin of the Arduino UNO.

const int AOUTpin = 0; //the AOUT pin of the CO sensor goes into analog pin A0 of the arduino
const int DOUTpin = 8; //the DOUT pin of the CO sensor goes into digital pin D8 of the arduino
const int ledPin = 13; //the anode of the LED connects to digital pin D13 of the arduino

In the loop function, the sensor values are read. If the limit is reached, the digital pin 13 is driven high.

There is an LED connected to Pin 13 of the UNO on board. You can build on this code further to integrate the sensor with your main project. 

FAQs About The Carbon Monoxide Sensor Module MQ7

I have included a list of the most frequently asked questions about projects built using Arduino and the Carbon monoxide sensor MQ7.

If you have any further inquiries, feel free to leave a comment below, and I will be delighted to provide you with a response.

1. What is an MQ7 sensor?

The MQ7 sensor is an electronic device designed to detect the presence of carbon monoxide gas in the environment.

It works by measuring the concentration of CO in the air and outputting an analog voltage signal proportional to the concentration.

The sensing material of the gas sensor is tin oxide. The measuring range is from 10 ppm to 10000 ppm.

2. How accurate is the MQ7 sensor?

The accuracy of the MQ7 sensor can vary depending on several factors, such as temperature, humidity, and other environmental conditions.

The sensor has a typical accuracy of ±10% for carbon monoxide concentrations between 100 ppm and 1000 ppm.

3. How long does the MQ7 sensor take to warm up?

The MQ7 sensor requires a warm-up time of at least 48 hours before it can take accurate measurements. A warm-up time of 7 days is recommended for optimal performance.

4. What is the lifespan of the MQ7 sensor?

The typical lifespan of the sensor element inside the MQ7 sensor is five years under normal operating conditions.

However, this can vary depending on usage, storage conditions, and other factors. You have to factor in those conditions before choosing the sensor for your project. 

5. Can the MQ7 sensor detect other gases besides carbon monoxide?

Yes, the MQ7 sensor can detect other gases, such as hydrogen and methane. However, it is specifically designed for carbon monoxide detection and may not be as accurate for other gases.

 6. How do I interface the MQ7 sensor with an Arduino?

The MQ7 sensor outputs an analog voltage signal that an analog input pin can read. Typically, the sensor is connected to an analog input pin on the Arduino.

The voltage is read and converted into a digital value using the microcontroller’s built-in analog-to-digital converter (ADC). 

Example code and connection diagrams are available in the previous sections of this article. 

> Check out our guide to the Top 12 Best Arduino Online Courses


In this article, I’ve covered all the essential information about how to connect and use the MQ7 sensor with an Arduino board.

I’ve provided step-by-step connection instructions and working code examples to help you get started with your project quickly.

As an Arduino enthusiast, I found the MQ7 carbon monoxide sensor to be an exciting and useful tool for my projects.

The MQ7 sensor’s ability to detect carbon monoxide levels makes it a first choice for applications such as home safety systems or personal CO monitors. 

I hope that this article has been helpful in introducing you to the MQ7 sensor and its applications.

If you have any questions or feedback, please don’t hesitate to leave a comment. I’m always eager to hear from fellow Arduino enthusiasts and happy to help in any way I can.

So, get your Arduino board ready, follow the guide, and start exploring the possibilities of the MQ7 sensor.

Happy building!