In this tutorial, we will be interfacing Gas Sensors MQ2, MQ3, MQ7, and MQ135 Gas Sensor With Arduino board to build a gas leakage detector. The gas sensor is a widely used sensor for detecting a number of gases, including carbon monoxide and methane gas.
Thank You NextPCB:
Guys if you have a PCB project, please visit their website and get exciting discounts and coupons. if you sign-up using this link you will get free coupons worth $100. Checkout out NextPCB now and get amazing discounts on your first order.
The MQ series gas sensors are analog sensors so they are easy to implement with any microcontroller.
MQ series sensors are electrochemical and change their resistance when exposed to specific gases, internally it has a heater responsible for increasing the internal temperature and with this, the sensor can react with the gases pushing a change in the resistance value.
Depending on the model, the heater may need a voltage between 5 and 2 volts, the sensor behaves like a resistor and needs a load resistor (RL) to close the circuit and with this make a voltage divider and be able to read it from a microcontroller:
The internal structure of the MQ Series Sensor
Due to the heater, it is necessary to wait for a heating time so that the output is stable and has the features that the works show in its datasheets, this time, depending on the model, can be between 12 and 48 hours.
In the market, MQ sensors are generally found in modules, which facilitates the connection part and makes it more comfortable for us to use, it is enough to power the module and starts reading the sensor, these modules also have a digital output that internally It works with a comparator and with the help of a potentiometer we can calibrate the threshold and thus be able to interpret the digital output as the presence or absence of gas.
Different Types of MQ Gas Sensor With Arduino
The difference between the various types of MQ series sensors is the sensitivity to a specific range of gases, more sensitive to some gases than others, but they always detect more than one gas, so it is necessary to review the datasheets to choose the right sensor for our applications. The MQ2 gas sensor is a popular choice for multiple applications, including home protection, industrial monitoring, and environmental monitoring. The MQ2 gas sensor is a reliable and inexpensive, gas sensor that can be used in a variety of applications.
MQ Gas Sensor Series
MQ gas sensor series are the most standard gas sensors. These sensors have different models for detecting different gases, some of which are listed in the following table:
Model | Object detected | Heater |
MQ-2 | Methane, butane, LPG, humus | 5V |
MQ-3 | alcohol, ethanol, smoke | 5V |
MQ-303A | alcohol, ethanol, smoke | 0.9V |
MQ-4 | Methane, compressed natural gas (CNG) | 5V |
MQ-5 | Gas natural, GLP | 5V |
MQ-6 | Butano, GLP | 5V |
MQ-306A | Butano, GLP | 0.9V |
MQ-7 | Carbon monoxide | Alternate 5V and 1.4V |
MQ-307A | Carbon monoxide | Alternate 0.2 and 0.9V |
MQ-8 | Hydrogen | 5V |
MQ-9 | Carbon monoxide, flammable gases | Alternate 5V and 1.5V |
MQ-309A | Carbon monoxide, flammable gases | Alternate 0.2 and 0.9V |
MQ-131 | Ozone | 6V |
MQ-135 | benzene, alcohol, smoke, air quality | 5V |
MQ-136 | hydrogen sulfide | 5V |
MQ-137 | Ammonia | 5V |
MQ-138 | benzene, toluene, alcohol, acetone, propane, formaldehyde, hydrogen |
5V |
MQ-214 | Methane, natural gas | 5V |
MQ-216 | natural gas, coal gas | 6V |
MG-811 | Carbone dioxide | 6V |
AQ-104 | Air quality * | |
AQ-2 | Flammable gases, smoke | |
AQ-3 | Alcohol, Benzene | |
AQ-7 | Carbon monoxide |
Below we detail the main MQ sensors
1. MQ-2 Smoke and Flammable
The MQ2 sensor can be used to create a gas leakage detector that can be used to alert of potentially dangerous gas leaks. This is a powerful Gas sensor suitable for detecting LPG, Smoke, Alcohol, Propane, Hydrogen, Methane, and Carbon Monoxide concentrations anywhere from 200 to 10000ppm. Being more sensitive to LPG and propane.
2. MQ3 Alcohol Sensor
MQ3 sensor is very sensitive to alcohol and less sensitive to benzine, it is also sensitive to gases such as LPG, Hexane, CO, and CH4 but with very low sensitivity, which can be ignored if there is little concentration of these. It is a highly sensitive sensor that can detect even very low concentrations of alcohol.
3. MQ-5 Natural Gas Detector Sensor
The MQ-5 Natural Gas Detector Sensor is a low-cost, reliable sensor that can detect the presence of natural gas in the environment, The MQ-5 Natural Gas Detector Sensor is a valuable tool for anyone who needs to monitor the presence of natural gas in their environment.
4. MQ7 Carbon Monoxide Sensor
MQ7 Carbon Monoxide Sensor is a semiconductor sensor that is used to detect the presence of carbon monoxide in the air. MQ7 sensor is highly sensitive to carbon monoxide (CO) but is also sensitive to H2.
5. MQ-9 Combustible Gas Detector
The MQ-9 Combustible Gas Detector is a reliable and cost-effective way to detect the presence of combustible gases. The MQ-9 is able to detect a wide range of combustible gases, including methane, propane, and butane. MQ-9 sensor is also able to detect hydrogen gas.
6. MQ135 Air Quality Sensor
The MQ135 sensor is a popular and inexpensive sensor that can be used to measure air quality. This sensor is placed in the air inlet of air conditioners and air purifiers to monitor the air quality. The MQ135 sensor measures the concentration of carbon monoxide, nitrogen dioxide, and ozone in the air.
How does MQ Sensor work?
The most common use for the MQ type of sensor is to detect the presence of methane, but it can also be used to detect other gases such as carbon monoxide and hydrogen sulfide. The MQ2 sensor is a very sensitive device, and it can be used to detect very small concentrations of gas in the air.
This makes it an ideal tool for use in gas leak detection applications. The sensor is able to produce a voltage output that is proportional to the concentration of the gas present in the air. Check lastminuteengineers Gas sensor Tutorial
Scaling MQ sensors
The characteristic curve of sensitivity of temperature: In the example below, we use the analog reading to determine the gas concentration, usually in ppm (parts per million), but some sensors use other units such as mg/L or bpm (parts per billion).
The MQ modules are sensitive to more than one gas and in a different proportion to each one, so if the objective is to obtain the values ​​in units corresponding to the concentration of the measured gas, it is necessary to carry out a scaling process through software based on the sensitivity characteristic curve.
For example, the following image shows the concentration curves of each gas measured in an MQ-2 sensor
MQ Sensor Pinout
- Now let’s have a look at the pinout.
- A/OÂ provides an analog output voltage that is proportional to the concentration of gas.
- D/O provides a digital representation of the presence of gases.
- GNDÂ is the Ground Pin and needs to be connected to the GND pin on the microcontroller.
- VCCÂ supplies power for the module. You can connect it to 5V output from your microcontroller board.
Wiring Diagram For DIGITAL READING
Wiring Diagram For ANALOG READING
Working code MQ Gas sensor with ArduinoÂ
- MQ_Sensor Calibration
- DIGITAL READING
- ANALOG READINGÂ
1. MQ_Sensor Calibration Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//MQ Sensors Calibration 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); } |
2. Digital reading of the MQ Gas Sensor With Arduino
The same MQ sensor data can be read on two different types, whose operation is the same but they have a different order of pins:
Connections
The connection to read the digital output would be as follows:
Arduino –> Sensor Gas Sensor With Arduino
- 5V –> VCC
- GND –> GND
- D8–> D0
In the example, we will use an MQ-2 (Gas sensor) but the program is the same for any MQ module if the digital output is used since this output acts as 1 or 0. Note that this output is negated, 1 for no Gas and 0 for the presence of Gas.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
int MQPin= 8; void setup () { Serial . begin (9600); pinMode (MQPin, INPUT ); } void loop () { boolean mq_status = digitalRead (MQPin); //We read the sensor if (mq_status) //if the sensor output is 1 { Serial . println ( "No Gas present" ); } else //if sensor output is 0 { Serial . println ( "Gas detected" ); } delay (100); } |
3. Analog reading of MQ Gas Sensor With Arduino
For this case we must connect the analog output of the module to an analog input of the Arduino board: Â The difference between using the digital output is that using the analog output we can work with different levels of gas presence and scale it according to the requirements of our application.
Connections Gas Sensor With Arduino
Arduino –> Sensor
- 5V –> VCC
- GND –> GND
- A0 –> A0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#define MQPin (A0) float sensorValue; //variable to save the analog value of the sensor voidsetup ( ) { Serial.begin (9600); // Initialize the serial port to 9600 Serial.println (" The gas sensor is pre-heating" ); delay (20000); // Wait for the sensor to warm up for 20 seconds } void loop () { sensorValue = analogRead (MQPin); // We read the terminal "A0" of the sensor Serial.print ( "Value detected by the sensor: " ); Serial.print (sensorValue); if (sensorValue > 300) { Serial.print ( " Gas detected " ); } Serial.println ( "" ); delay (2000); // wait for 2 seconds for the next read } |
As this is an analog output, the code is the same for whatever type of MQ sensor you are working with.
Because the module has a heating chamber where the gas has to enter or exit, the response time is slow, and the sensor will continue to detect the gas residues that remain inside the heating partition until they disappear.
2 Comments
Pingback: MFRC522 RFID Module With Arduino Tutorial – How It Works, Code
Pingback: How To Use Relay Module With Arduino – How It Works, Codes1