How to Calibrate & Use MQ9 Gas Sensor w/ Arduino © GPL3+

In this tutorial, you will learn how to calibrate and use MQ9 gas sensor with an Arduino board.

  • 499 views
  • 2 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

You can read this and other amazing tutorials on ElectroPeak's official website

Overview

In this tutorial, you will learn how to calibrate and use MQ9 gas sensor with an Arduino board.

What You Will Learn:

  • What the gas sensor is and how it works.
  • Comparison of different gas sensor models
  • How MQ9 gas sensor works
  • Using MQ9 gas sensor with Arduino

What Is a Gas Sensor and How Does It Work?

A gas sensor is a device that detects the presence of one or more types of gas in the environment. These sensors have wide applications such as security systems of refineries, industrial centers, and even homes. These sensors can detect combustible gas, toxic gas, pollutant gas, and so on. There are several methods for gas detection, the most commonly used is electrochemical sensors. These sensors measure the concentration of a specific gas by performing a chemical reaction on their heated electrodes and measuring the resulting electric current.

MQ Gas Sensor Series

MQ gas sensor series are the most common gas sensors available. These sensors have various models for detecting various gases, some of which are listed in the following table:

Here we will get to know how to hookup MQ9, but they all work almost in the same way.

The MQ9 sensor is sensitive to carbon monoxide and flammable gases. It can detect the detect carbon monoxide density from 10ppm to 1000ppm and flammable gases density from 100ppm to 10000ppm. MQ9 has an internal heater which starts warming up if a 5V voltage is applied.

The internal resistance of this sensor changes as the density of the detectable gases changes. This value can be read by a simple circuit. MQ9 sensor modules in the market have already implemented the necessary circuit and you do not need any extra item.

Interfacing MQ9 Gas Sensor and Arduino

In order to get correct and accurate data, you need to take the following actions first:

  • MQ9 sensor needs 24-48 hours of preheating time. Connect the power supply and leave for the required time until it gets ready.
  • You need to calibrate the sensor (We have explained this in the following section)

Circuit

This module has 4 pins. Connect Vcc to 5V and GND to GND. The AO pin returns an analog value based on the concentration of the gas. The DO pin returns HIGH if the concentration of gas is higher than a certain value. This value can be set by the potentiometer on the board.

Notes:1. Do not expose this sensor to water and frost.

2. Applying a voltage higher than 5V or applying the voltage to the wrong pins may damage the sensor.

3. Exposing the sensor to a high concentration of gases for a long time may have a negative effect on its performance.

4. Shaking or vibrating the sensor may decrease its accuracy.

How to Calibrate MQ9 Gas Sensor?

Before using the module you have to calibrate it. This sensor measures the gas concentration based on resistance ratio. This ratio includes R0 (sensor resistance in 1000ppm concentration of LPG) and Rs (Internal resistance of the sensor which changes by gas concentration). In clean air, after preheating, upload the following code and wait for about 15 minutes until R0 reaches a fixed value.

 /* 
MQ9 Calibration 
modified on 19 Feb 2019 
by Saeed Hosseini 
https://electropeak.com/learn/ 
*/ 
void setup() { 
 Serial.begin(9600); 
} 
void loop() { 
 float sensor_volt;  
 float RS_air; //  Rs in clean air 
 float R0;  // R0 in 1000 ppm LPG 
 float sensorValue; 
//Average   
   for(int x = 0 ; x < 100 ; x++) 
 { 
   sensorValue = sensorValue + analogRead(A0); 
 } 
 sensorValue = sensorValue/100.0; 
//-----------------------------------------------/ 
 sensor_volt = (sensorValue/1024)*5.0; 
 RS_air = (5.0-sensor_volt)/sensor_volt; // Depend on RL on yor module 
 R0 = RS_air/9.9; // According to MQ9 datasheet table 
 Serial.print("sensor_volt = "); 
 Serial.print(sensor_volt); 
 Serial.println("V");
 Serial.print("R0 = "); 
 Serial.println(R0); 
 delay(1000); 
}

As you see in the code, we have averaged from 100 data to achieve a stable value. Then we measure the sensor voltage and according to RL restance (in our case, 5K), we calculate Rs. Then according to the table available in the datasheet, R0 can be found.

Code

NoteIn the following code, replace R0 with the value you achieved in the previous step.

/* 
 MQ9 
 modified on 19 Feb 2019 
 by Saeed Hosseini 
 https://electropeak.com/learn/ 
*/ 
const int LED = 2; 
const int DO = 8; 
void setup() { 
 Serial.begin(9600); 
 pinMode(LED, OUTPUT); 
 pinMode(DO, INPUT); 
} 
void loop() { 
 int alarm = 0; 
 float sensor_volt; 
 float RS_gas; 
 float ratio; 
//-Replace the name "R0" with the value of R0 in the demo of First Test -/ 
 float R0 = 0.91; 
 int sensorValue = analogRead(A0); 
 sensor_volt = ((float)sensorValue / 1024) * 5.0; 
RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module 
 ratio = RS_gas / R0; // ratio = RS/R0 
//------------------------------------------------------------/ 
 Serial.print("sensor_volt = "); 
 Serial.println(sensor_volt); 
 Serial.print("RS_ratio = "); 
 Serial.println(RS_gas); 
 Serial.print("Rs/R0 = "); 
 Serial.println(ratio); 
 Serial.print("\n\n"); 
 alarm = digitalRead(DO); 
 if (alarm == 1) digitalWrite(LED, HIGH); 
 else if (alarm == 0) digitalWrite(LED, LOW); 
 delay(1000); 
}

What’s Next?

  • Find the gas concentration in PPM with the help of the above table.
  • Create an intelligent CO leakage notifier.

Code

code1Arduino
/* 
 
MQ9 Calibration 
 
modified on 19 Feb 2019 
by Saeed Hosseini 
https://electropeak.com/learn/ 
 
*/ 
 
void setup() { 
  Serial.begin(9600); 
} 
  
void loop() { 
  float sensor_volt;  
  float RS_air; //  Rs in clean air 
  float R0;  // R0 in 1000 ppm LPG 
  float sensorValue; 
 
//Average   
    for(int x = 0 ; x < 100 ; x++) 
  { 
    sensorValue = sensorValue + analogRead(A0); 
  } 
  sensorValue = sensorValue/100.0; 
//-----------------------------------------------/ 
 
  sensor_volt = (sensorValue/1024)*5.0; 
  RS_air = (5.0-sensor_volt)/sensor_volt; // Depend on RL on yor module 
  R0 = RS_air/9.9; // According to MQ9 datasheet table 
   
  Serial.print("sensor_volt = "); 
  Serial.print(sensor_volt); 
  Serial.println("V");
  
  Serial.print("R0 = "); 
  Serial.println(R0); 
  delay(1000); 

}
code2Arduino
/* 
 
  MQ9 
 
  modified on 19 Feb 2019 
  by Saeed Hosseini 
  https://electropeak.com/learn/ 
 
*/ 
 
const int LED = 2; 
const int DO = 8; 
 
void setup() { 
  Serial.begin(9600); 
  pinMode(LED, OUTPUT); 
  pinMode(DO, INPUT); 
} 
 
void loop() { 
 
  int alarm = 0; 
  float sensor_volt; 
  float RS_gas; 
  float ratio; 
 //-Replace the name "R0" with the value of R0 in the demo of First Test -/ 
  float R0 = 0.91; 
 
  int sensorValue = analogRead(A0); 
  sensor_volt = ((float)sensorValue / 1024) * 5.0; 
 RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module 
 
 
  ratio = RS_gas / R0; // ratio = RS/R0 
 //------------------------------------------------------------/ 
 
  Serial.print("sensor_volt = "); 
  Serial.println(sensor_volt); 
  Serial.print("RS_ratio = "); 
  Serial.println(RS_gas); 
  Serial.print("Rs/R0 = "); 
  Serial.println(ratio); 
 
  Serial.print("\n\n"); 
 
  alarm = digitalRead(DO); 
  if (alarm == 1) digitalWrite(LED, HIGH); 
  else if (alarm == 0) digitalWrite(LED, LOW); 
 
  delay(1000); 
 
}

Comments

Similar projects you might like

Smoke Detection using MQ-2 Gas Sensor

by Aritro Mukherjee

  • 249,854 views
  • 44 comments
  • 160 respects

How to Connect MQ2 Gas Sensor to Arduino

by Junez Riyaz

  • 2,039 views
  • 0 comments
  • 3 respects

MQ-4 Natural Gas Sensor Experiment Based on Arduino

Project tutorial by Andrew85

  • 1,191 views
  • 1 comment
  • 7 respects

Arduino And MQ2 Gas Sensor

Project showcase by Mahamudul Karim Khondaker

  • 6,156 views
  • 7 comments
  • 14 respects

Displaying Sensor Values on LCD

by Wimpie van den Berg

  • 51,022 views
  • 4 comments
  • 40 respects

Ultra-Sonic "Ping" Sensor

by MicroBob

  • 27,606 views
  • 6 comments
  • 37 respects
Add projectSign up / Login