Connection mq 2. Gas sensors series MQ (Trema-module v2.0). Connecting to the Arduino platform

New Articles

● 4.5. Determination of the concentration of hydrocarbon gases using the MQ-2 sensor

One of the most important tasks in smart home security is gas leak detection. In order for the Arduino board to successfully solve problems of this kind, you need to connect an MQ-2 gas sensor to it. The MQ-2 sensor (Fig. 4.24) will determine the concentration of hydrocarbon gases (propane, methane, n-butane), smoke (suspended particles resulting from combustion) and hydrogen in the environment. The sensor can be used to detect gas leaks and smoke. The gas analyzer has a built-in heating element, which is necessary for a chemical reaction. Therefore, the sensor will be hot during operation. A new sensor must be warmed up (left on) once for 24 hours to obtain stable readings. After that, stabilization after switching on takes about a minute.

Rice. 4.24. Gas sensor MQ-2.

Depending on the level of gas in the atmosphere, the internal resistance of the sensor changes. The MQ-2 has an analog output, so the voltage at this output will vary in proportion to the level of gas in the environment. There is also a digital output for logic level detection. The sensor module has a built-in potentiometer that allows you to adjust the sensitivity of this sensor depending on how accurately you want to register the gas level.
Now about the units of measurement. On the territory of the former Soviet Union, indicators are usually measured as a percentage (%) or directly in mass to volume (mg / m3). In foreign countries, it uses such an indicator as ppm.
The abbreviation ppm stands for parts per million (parts per million). For example, 1 ppm = 0.0001%.
Sensor measurement range:

Propane: 200-5000ppm;
. Butane: 300-5000ppm;
. Methane: 500-20000ppm;
. Hydrogen: 300-5000ppm.

Consider connecting the MQ-2 sensor to the Arduino Mega board and the NodeMcu ESP8266 module.

4.5.1. Connecting the MQ-2 Sensor to the Arduino Mega Board

We will connect the MQ-2 sensor to the Arduino Mega board via an analog input. We also take power for the sensor from the Arduino board. The connection diagram is shown in fig. 4.25.


Rice. 4.25. Scheme of connecting the MQ-2 sensor to the Arduino Mega board

Let's upload a sketch to the Arduino Mega board to receive data from the MQ-2 sensor and output to the Arduino serial port. Procedures for determining from data coming from an analog input:


The contents of the sketch are shown in Listing 4.10.
Listing 4.10

#include # // pin to which the sensor is connected #define MQ2PIN A10 MQ2 mq2 (MQ2PIN ); void setup()( Serial.begin(9600 ); // calibration mq2.calibrate(); mq2.getRo(); ) void loop()( if (millis()-millis_int1 >= INTERVAL_GET_DATA) ( // display gas values ​​in ppm // display gas values ​​in ppm // start of the countdown interval millis_int1=millis(); ) ) float get_data_ppmpropan() // get value float get_data_ppmmethan()( Serial.println(mq2.readRatio()); // get value float get_data_ppmsmoke()( Serial.println(mq2.readRatio()); // get value

Let's upload the sketch to the Arduino Mega board, open the serial port monitor and see the output of data on the content of propane, methane and smoke (Fig. 4.26).

Rice. 4.26. Output data from the MQ-2 sensor to the serial port monitor.

You can download this sketch from www.

4.5.2. Connecting the MQ-2 sensor to the NodeMcu ESP8266 module

Now consider connecting the MQ-2 sensor to the NodeMcu ESP8266 module. We connect the MQ-2 sensor to the input y2 of the multiplexer. To select the analog input of the multiplexer, use the contacts D5, D7, D8 of the Node Mcu module. The connection diagram is shown in fig. 4.27.

Rice. 4.27. Scheme of connecting the MQ-2 sensor to NodeMcu ESP8266

Let's upload a sketch to the NodeMcu module to receive data from the MQ-2 sensor and output to the Arduino serial port. To select the analog input of the multiplexer y2, we apply a low-level signal LOW to pins D5, D8, and a high-level signal HIGH to pin D7.
Procedures for determining from data coming from an analog input:

Get_data_ppmpropan() - propane content in ppm;
. get_data_ppmmethan() - propane content in ppm;
. get_data_ppmsmoke() - smoke content.

The contents of the sketch are shown in Listing 4.11.
Listing 4.11

// library for working with MQ sensors#include #define INTERVAL_GET_DATA 2000 // measurement interval, ms // analog pin #define MQ2PIN A0 // create an object to work with the sensor MQ2 mq2 (MQ2PIN ); // variable for measurement interval unsigned long millis_int1=0 ; void setup(){ // inputs for connecting to the multiplexer D5, D7, D8 (GPIO 14, 13, 15)// as OUTPUT pinMode(14 ,OUTPUT); pinMode(13 ,OUTPUT); pinMode(15 ,OUTPUT); // open serial port Serial.begin(9600 ); digitalWrite(14 ,LOW); digitalWrite(13 ,HIGH); digitalWrite(15 ,LOW); // calibration mq2.calibrate(); mq2.getRo(); ) void loop()( if (millis()-millis_int1 >= INTERVAL_GET_DATA) ( // select CD4051 multiplexer input - y2 (010) digitalWrite(14 ,LOW); digitalWrite(13 ,HIGH); digitalWrite(15 ,LOW); // receiving data from the mq2 sensor float propan= get_data_ppmpropan(); // display gas values ​​in ppm Serial print("propan=" ); Serial print(propan); Serial.println("ppm"); float methan= ​​get_data_ppmmethan(); // display gas values ​​in ppm Serial.print("methan=" ); Serial print(methan); Serial.println("ppm"); float smoke= get_data_ppmsmoke(); // display gas values ​​in ppm Serial print("smoke=" ); Serial print(smoke); Serial.println("ppm"); // start of the countdown interval millis_int1=millis(); ) ) // get propane data from MQ2 sensor float get_data_ppmpropan()( Serial.println(mq2.readRatio()); // get value float value =mq2.readLPG(); return value ; ) // get methane data from MQ2 sensor float get_data_ppmmethan()( Serial.println(mq2.readRatio()); // get value float value =mq2.readMethane(); return value ; ) // get smoke content data from sensor MQ2 float get_data_ppmsmoke()( Serial.println(mq2.readRatio()); // get value float value =mq2.readSmoke(); return value ; )

Let's upload the sketch to the Node Mcu module, open the serial port monitor and see the data output received from the MQ-2 sensor (Fig. 4.28).

Rice. 4.28. Output data from the MQ-2 sensor to the serial port monitor.

You will say, on the Internet about the MQ-2 sensor and Arduino! But many hours of searching for information did not give a positive result. All programs were not working, or did not suit me. I had to write the program myself.

The module is based on the gas analyzer MQ-2. Allows you to detect propane, butane, hydrogen and methane in the air.

Figure 1 - MQ-2 Gas Sensor.

Characteristics

  • Supply voltage: 5 V
  • Current consumption: 160 mA

Measuring range

  • Propane: 0.2 - 5 ppm
  • Butane: 0.3 - 5 ppm
  • Methane: 5 - 20 ppm
  • Hydrogen: 0.3 - 5 ppm

Strange, but the sensor responds very well to gas from a lighter, to smoke, but does not react to a gas stove at all. The sensitivity of the sensor can be adjusted with a variable resistor.

The sensor is connected to the arduino as follows:

Scheme 1 - Connecting the sensor to the Arduino.

Vss - connect to +5V
Aout - A0 arduino (this is the analog output of the sensor, there is a digital dout)
GND - to ground

Below is the program:

#define mic 5 #define analogInPin A0 void setup() ( pinMode(analogInPin, INPUT); Serial.begin(9600); ) void loop() ( Serial.println(analogRead(analogInPin)); int sensorValue = analogRead(analogInPin) ; int range = map(sensorValue, 100, 145, 1, 4); switch (range) ( case 1: analogWrite(mic,100); delay(100); analogWrite(mic,0); break; case 2: analogWrite (mic,50); delay(100); analogWrite(mic,0); break; case 3: analogWrite(mic,30); delay(100); analogWrite(mic,0); break; case 4: analogWrite(mic ,20); delay(100); analogWrite(mic,0); break; ) )

A buzzer is used to alert smoke.

  1. Gas sensor MQ-2: http://ali.ski/6JRA_
  2. Arduino uno: http://ali.ski/gC_mOa
  3. Breadboard: http://ali.ski/rq8wz8
  4. Contact wires: http://ali.ski/Exjr3
  5. Diodes and resistors: http://fas.st/KK7DwjyF

In this tutorial, we will connect a gas sensor to the Arduino. With it, we can monitor the amount of carbon dioxide in the room.

The sensor board itself consists of the 6-pin sensor itself, which, for accurate readings, must stand for some time working and heat up to the required temperature. Potentiometer to change the sensitivity of the sensor. Well, 4 pins, 2 of which are +, - and two pins, one Analog, the other digital. Therefore, you need to connect either to the analog pin of the arduino or to the digital pin.

To implement this example, we will take the MQ-2 sensor. In general, there are a lot of MQ series sensors, there are carbon dioxide sensors, and carbon monoxide sensors, and an alcohol vapor and air purity sensor. You can choose a sensor for your needs without any problems, but since we will be looking for carbon dioxide, we need an MQ-2 sensor.

We will connect the sensor to the analog pin of arduino A0. Accordingly, we take an analog pin from the MQ-2 sensor, and not a digital one.

After the correct connection according to the diagram, you need to copy the code of the program below and upload it to the arduino.

Const int analogInPin = A0; // Specify the pin to which the sensor is connected const int ledPin = 13; int sensorValue = 0; // Declare a variable to store values ​​from the sensor //and set its initial value to 0 void setup() ( Serial.begin(9600); pinMode(ledPin, OUTPUT); // Set the mode for pin 13 Serial.println("MQ2 Test "); //Send text to the port monitor to monitor the program execution ) void loop() ( sensorValue = analogRead(analogInPin); //read the values ​​from the sensor if (sensorValue >= 350) //and if the specified threshold is exceeded ( digitalWrite(ledPin, HIGH); // then turn on the LED. ) else // and if not ( digitalWrite(ledPin, LOW); // then turn it off ) Serial. print("MQ2 value= "); // To track data from the sensor, we broadcast them to the port monitor Serial.println(sensorValue); delay(1000); )

After downloading the program code, you can breathe on the sensor, or release gas from the lighter - in the monitor window of the serial port you will see the corresponding values ​​received from the sensor.

More details can be seen in the video below.

Video:

When I had an Arduino kit, in search of an object for automation, I somehow thought of myself that it would be nice to get information about whether the level of CO (carbon monoxide) is dangerous in the winter in the boiler room of a country house. During the cold winter days and especially the nights, the gas equipment works at an intensive rate and burns natural gas to keep the house warm. What if I have bad ventilation? Or is a felt boot stuck in the pipe? And every time I enter the boiler room and stay there for a while, I put my precious life in danger. And no one is immune from natural gas leaks either. Here, in general, you can blow up half the house, just by turning on the light. It would be nice to control them too and somehow track them.

Therefore, it was decided to assemble a system for monitoring the level of CO and methane in the air of a boiler room based on an Arduino or a compatible board. In addition to simple alarms, I would also like to collect statistics, for example, on how concentrations of hazardous gases are related to the operation of gas equipment. In principle, the task is being implemented at the modern level of culture and technology, and for very little money. As a source of natural gas consumption, I used pulses from a sensor built into the gas meter, and for air analysis I used two MQ-4 and MQ-7 sensors that are extremely popular among Arduino developers. The MQ4 sniffs the air for methane, while the MQ7 measures for CO.

But in order to go further, it turned out that you need to specifically delve into the details. Since few of the users of Arduino and analogues understand what kind of sensors these MQ-4 and MQ-7 are, and how to use them in general. Well, let's get down to the exciting story.

What is ppm

In order to properly operate with the values ​​\u200b\u200bthat I will give below, you need to understand the units of measurement for yourself. In our country, on the territory of the former Soviet Union, it is customary to measure indicators as a percentage (%) or directly in mass to volume (mg / m 3). But in some foreign countries it uses such an indicator as ppm.

The abbreviation ppm stands for parts per million, or loosely translated as “parts per million” (it’s good that pounds per gallons and imperials to fathoms are not used here). In principle, the indicator does not differ much from the percentage, or rather, only the dimension differs. 1 ppm = 0.0001%, respectively 3% = 30.000 ppm.

Converting from percent or ppm to mg / m 3 is already more difficult, here you need to take into account the molar mass of the gas, pressure and temperature. In general, the conversion formula is as follows P x V M =R x T, where P is pressure, V M is molar volume, R is the universal gas constant, T is absolute temperature in Kelvin (not Celsius and not Fahrenheit). But in order not to torment the reader with a school chemistry course, I will immediately give several meanings. And the most experienced internet drillers can find online calculators for self-calculation on the vast web.

CO: 3% = 30.000 ppm = 34695.52 mg/m3
CO 2: 3% = 30.000 ppm = 54513.22 mg/m 3

Data are given for normal atmospheric pressure and room temperature. Note that CO 2 at a comparable percentage is almost twice as heavy as CO. Let me remind you that the CO 2 molecule contains one more atom, hence the difference. And it is thanks to this difference that CO 2 accumulates in the lowlands, and CO at the ceiling.

The difference between CO and CO 2

To begin with, it is worth understanding what CO is and how it differs from CO 2. First, CO is carbon monoxide, which is also called carbon monoxide, carbon monoxide, or carbon monoxide (II). CO gas is very tricky. It is extremely poisonous, but it has neither color nor smell. Once in a room with carbon monoxide, you only by indirect symptoms will understand that you are exposed to poison. First, a headache, dizziness, shortness of breath, palpitations, then a bluish corpse. Carbon monoxide combines with blood hemoglobin, causing the latter to stop carrying oxygen to the tissues of your body, and the brain and nervous system are the first to suffer.

Secondly, carbon monoxide is an excellent fuel and can burn as well as other combustible gases. At certain concentrations, it forms an explosive mixture that is ready to smash into chips any volume where gas has accumulated mixed with oxygen. Yes, carbon monoxide is lighter than air, so it actively penetrates the second, third and subsequent floors of buildings.

The main source of CO emission, oddly enough, is the combustion of carbon fuel with insufficient oxygen. Carbon "does not burn out" and instead of carbon dioxide CO 2, carbon monoxide CO is emitted into the atmosphere. In the domestic sense, wood-burning stoves, gas burners, gas boilers and other carbon-fueled heating equipment can act as an excellent source of CO, if used improperly. Do not forget about cars, in the exhaust of a gasoline engine CO can be up to 3%, and according to hygiene standards it should be no more than 20 mg / m³ (about 0.0017%).

In general, carbon monoxide is an insidious and easily obtained thing. It is enough to clog the chimney and you can safely go to the forefathers, having melted the stove for the night.

CO 2, also known as carbon dioxide, carbon dioxide, carbon dioxide, carbon monoxide (IV) or simply carbonic anhydride, is an equally interesting gas. We encounter carbon dioxide much more often in everyday life than carbon monoxide. We drink sparkling water in which carbon dioxide is dissolved. We use dry ice to preserve ice cream in the park on a hot summer afternoon, and we finally breathe out crazy amounts of carbon dioxide. Yes, and natural objects, such as volcanoes, swamps or landfills can generate a fair amount of carbon dioxide.

But do not think that CO 2 gas is gentler and safer than CO gas. High concentrations of CO 2 lead to no less severe consequences, up to death. And you can raise your concentration easily and naturally just by closing the window in the bedroom at night. Moreover, unlike CO, carbonic anhydride is heavier than air and accumulates dangerously in lowlands, basements, undergrounds and other unexpected places. There have been documented cases of deaths of people accidentally falling into hollows full of carbon dioxide leaking from a neighboring volcano. The bus engine stalls, the air starts to run out and that's it. CO 2 gas is also colorless, odorless and tasteless, therefore its presence is almost impossible to determine organoleptically, except to control the onset of pronounced suffocation.

Both gases are composed of only two types of elements. Of oxygen (O) and carbon (C), the only question is the number of oxygen atoms. The knowledgeable reader can guess that one gas can be transformed into another with extraordinary ease. Yes, maybe, but not quite easily and not quite ordinary. You have to make an effort. So, for example, in the catalytic converters of modern gasoline cars, the process of afterburning (converting) CO into CO 2 takes place. The process takes place at high temperature and in the presence of catalysts (for example, platinum). The reverse process is also possible, but again not easy.

By the way, there is a CO2.Earth site on the Internet that displays the dynamics and current concentration of carbon dioxide in the Earth's atmosphere. Yes, the concentration is not so low. After all, with the accumulation of carbon dioxide in the region of 2-4%, a person loses working capacity, feels drowsiness and weakness. And at concentrations of about 10%, suffocation begins to be felt.

We deviated a little from the topic, but the conclusion here is this: you should not confuse two different gases, as well as the consequences of them, but it is definitely worth controlling their presence in the indoor atmosphere.

Design of electrochemical sensors

The most common type of MQ sensors. And it is widely distributed solely due to its cheapness. I did a little research to try to understand the issue of electrochemical sensors a little more than most hobbyists build some device on their own.

An electrochemical sensor is built on the principle of changing the resistance of an element when interacting with another element. In other words, a chemical reaction occurs between these two elements, resulting in a change in the resistance of the substrate. Everything seems to be simple. But in order for the reaction to proceed normally, and the sensor was not disposable, the sensitive part of the sensor must be kept warm.

So the electrochemical sensor consists of a certain substrate with a sensitive material, a substrate heater and the actual output contacts. A metal mesh is stretched over the sensor from above, yet the substrate is noticeably heated, and all kinds of combustible gases can be around the sensor, the same CO. This is what a grid is for. Safety is paramount. By the way, a certain Humphrey Davy invented to stretch the mesh over dangerous elements when used in explosive environments for miners at the beginning of the 90th century.

In the network, you can count a couple of dozen manufacturers of boards with electrochemical sensors of the MQ series. But the manufacturer for all sensors (not boards) is the same - the Chinese company HANWEI. The company produces a significant range of various devices for detecting gases and everything related to them. But there are no sensors of the MQ series among the nomenclature, it is possible that the products are too small to post them on the site.

Being a curious person by nature, I dug into the specifications of HANWEI and brought together all the available sensors of the MQ series, substrate material and detection type into a single table.

Sensor

Gas

Substrate

MQ-2 LPG SnO 2
MQ-3 Alcohol SnO 2
MQ-4 CH 4 SnO 2
MQ-5 LPG, natural gas SnO 2
MQ-6 LPG, propane SnO 2
MQ-7 CO SnO 2
MQ-9 CH4, LPG SnO 2
MQ-131 O 3 SnO 2
MQ-135 air quality SnO 2
MQ-136 air quality SnO 2
MQ-137 air quality SnO 2
MQ-138 Multipurpose SnO 2
MQ-303A Alcohol ???
MQ-306 LPG, LNG ???

With the exception of the 300 series MQ sensors, they all use the same backing material. It is for the very substrate that determines the concentration of gas in the atmosphere, it is for the substrate that changes its resistance. It is the same for all sensors. In the 300th series, information about sensitive material is modestly omitted.

Despite the single design and the used sensitive element, it cannot be said that all sensors from the manufacturer are the same. They differ in shape and parameters such as, for example, the supply voltage of the heater. You can take readings from such sensors using an ohmmeter, measuring the resistance, which varies depending on the concentration of the gas being measured. Or, by adding a load resistor, measure the voltage (how to add a resistor is indicated directly in the specifications for the sensors).

Please note that all sensors have a certain and very short lifespan, which is about 5 years. Moreover, 5 years is not only directly work, but also storage. And if your sensor is stored without proper packaging, then its shelf life is even shorter. The fact is that a sensitive chemical element, without heating, will be saturated with carbon, which will gradually destroy it all. It is for this reason that new sensors are recommended to be “baked” while keeping them in working order for a day, or even better, two. The carbon that has managed to eat into the tin (IV) oxide will “burn out” and the sensor will be able to determine the readings with higher accuracy.

If you look closely at the list of measured gases or the purpose of the sensors, you can see that all of them, one way or another, are tied to carbon (methane, natural gas, propane, carbon monoxide, liquefied gas, alcohol, and even air quality sensors measure the presence of carbon in compounds in air). And only the ozone sensor (MQ-131) stands out, although it uses the same sensor with SnO 2 . The fact is that all sensors of the MQ series are designed to work in an atmosphere with a stable level of oxygen. The specification tells us that the oxygen content should be 21%, which is a certain average rate. And if there is less or more oxygen, then the readings will float, up to the complete inability of the sensor to give intelligible results at an oxygen content of 2% or less. Still, in this case, carbon will not burn out on the substrate at all, the oxidizing agent is not enough. Apparently, the measurement of ozone by an electrochemical sensor is based on this effect.

But the accuracy of the readings of the MQ-series sensors depends on more than just oxygen. The readings change well depending on the humidity of the air and its temperature. Calculated figures are given for a humidity of 65% and a temperature of 20 degrees Celsius. And at humidity above 95%, the sensor will no longer adequately give readings. It's a pity that the specification does not specify which humidity is used: relative or absolute. Intuition suggests that it is still relative.

In addition to environmental indicators, the accuracy of the readings of MQ sensors is also affected by the service life of the sensors themselves, no worse than other parameters. Over time, their testimony floats. The sensitive layer is “clogged” with measurement products, the characteristics of the heater change and the resistance changes at reference values. In which direction it changes is not clear, but the manufacturer recommends, firstly, to calibrate the sensor after purchase and initial “annealing”, and then to carry out regular recalibration throughout the entire life of the sensor. And the only normal way to calibrate is to compare the results of the sensor readings with an already calibrated device. It is clear that neither the end consumer-private trader has such a device (and the pros will use slightly different sensors, more expensive), nor many board manufacturers. Some manufacturers state this honestly right on their website:

“And how do I know what the concentration of a particular gas is with the MQ sensor?” - the impatient reader will ask? Since in most cases the consumer uses a voltage meter, however, everything is similar with resistance, but one step less, then the consumer has a need for how to convert Arduino DAC volts or quanta into the coveted ppm or at least percentages. This operation can be done only with the help of indistinct graphs from the specification for the sensor.

Looking at the graph from the specification, it can be seen that, firstly, it has at least one logarithmic region. And, secondly, in addition to the main gas, the sensor calmly captures all the other similar ones (carbon-containing ones). Dealing with the graph and understanding which ppm corresponds to which sensor resistance is an occupation for practicing samurai, since a straight line crossing several different logarithmic zones will clearly not be a straight line in reality.

On this I would like to sum up the intermediate result. So, the advantages of the MQ series sensors include their extremely and categorically democratic price. But there are many more cons:

  • Virtually identical sensors using the same sensing element and differing in the value of trimming resistors used.
  • The dependence of the measurement results on many factors: temperature, humidity, oxygen concentration.
  • The lack of the claimed selectivity for the measured gases reacts to everything with carbon (and, quite possibly, to other elements that react with the substrate).
  • High power consumption (heater).
  • The need for primary "annealing" of the sensor.
  • Time instability.
  • The need for initial and recurring calibration.
  • The practical impossibility of obtaining meaningful values ​​in the form of ppm or%.

Digital or analog?

The market knows its business and if there is a demand for a product, then this demand will be satisfied. Sooner or later, but it will be necessary. And with the use of nimble Chinese comrades, demand is satisfied sooner rather than later. And so a great many manufacturers from China appeared, producing ready-made boards with electrochemical sensors of the MQ series. Let's consider in increasing order what delivery options can be in general.

Clean sensor

The easiest and cheapest option. The delivery includes only the electrochemical sensor itself and nothing else. Connect it to a system with voltage measurement (for example, to the Arduino analog port) through a load resistor. The resistor is best used with the ability to adjust when calibrated. Resistor ratings are specified in the specification (DataSheet) for the sensor.

With an alternative measurement method, you can use an ohmmeter and measure the resistance of the sensor outputs, and then recalculate it into the desired results according to the same specification.

Here the user receives not just the sensor itself, but the sensor installed on the board, with the installed resistor. It is already possible (and necessary) to connect it to the voltage meter directly, without any intermediate resistors. In this case, only voltage measurement is available, since, together with the resistor, the entire circuit works like an ordinary voltage divider.

The use of an analog sensor on the board is convenient because the manufacturer has already installed the required resistor on the board and perhaps even performed some kind of calibration of the entire structure. Some analog sensors use a trimming resistor and the user is free to calibrate himself, and some do not have this option. It is clear that it is better to take a version with the ability to adjust.

digital sensor

It would seem that if the sensor is digital, then it should give out information in digital form. However, all digital sensors with MQ sensors that I came across did not have this capability. The "digital" in their name only means that the sensor has a digital output that switches to HIGH mode when the measured gas concentration exceeds a certain threshold. And the user performs the main reading of values ​​in the same analog way as with an ordinary analog sensor.

It is clear that all the resistors are already soldered on the digital sensor boards. And good sensors also have trimming resistors available for configuring the sensor. One is used to set the sensor and the other is used to set the threshold for the digital output. And the best ones also have some kind of signal amplifier, which is useful when the sensor is far from the measuring device and there is a risk of catching interference on a long cable.

Digital sensor with digital bus

Perhaps this is the most Hi End among such sensors. Connection and data transfer is carried out via the I 2 C digital bus. And as many as a hundred of such sensors can be connected to one information retrieval device (for example, Arduino). Just keep in mind that the sensors consume a lot of current and it must be supplied separately. The tuning resistor, of course, is present.

Judging by the example code offered by the sensor manufacturer, the sensor itself sends data in raw form and they are already programmatically converted to ppm values. In general, the sensor differs from the analog version only in the presence of a digital bus.

Nutrition

I already mentioned above that for the operation of the MQ sensor heater, it is required to supply high-quality power to it and in sufficient volume. According to the specification, the sensors consume about 150 mA. In reality, consumption can float in a very wide range. In principle, 150 mA is not such a big current until a device (or several) with such a consumption is tried to be crossed with something like an Arduino. By connecting even one such sensor to the power supply on the board, you already risk getting an inoperative device that will not have enough voltage for normal operation. During operation, the sensors themselves heat up, not significantly, but up to forty degrees may well get hot. If we compare this temperature with 60-70 degrees on the stabilizer that feeds these sensors, then the temperature of the sensors can be considered tolerable.

To ensure the normal operation of the heater and, as a result, the sensor itself, it is necessary to supply power separately for these sensors. For example, use an independent power supply of 1 or 2 A and 5V to power the sensors (not all sensors consume 5V). Or use a special board that converts the voltage 9-12V into the required voltage to power the sensors.

In any case, you will have to tinker with a current source with the required power. Although it is possible that the sensor is connected directly to the board (for example, Arduino). But in this case, it is not recommended to connect anything else to it.

Option to calibrate the sensor and convert readings to ppm

Wandering the net looking for a solution to calibrate and get reliable results from the sensor, I came across a very interesting post from a certain Davide Gironi, who faced exactly the same problem as me. Davide tried to figure out how to get ppm readings from his MQ-135 (Air Quality) sensor.

According to the research conducted by the blogger for calibration, it is enough to have an idea about the concentration of some gas in the atmosphere and, based on this data, try to choose a resistor to hit the desired sector according to the schedule. Davide used the MQ-135 sensor, which is designed to determine the quality of air, among the controlled gases of which there is also CO 2 . And it was carbon dioxide that interested the blogger the most. Using information from co2now.org, he was able to calculate the required resistor value. Agree that the method is very far from ideal, but still better than nothing.

Then, after calibration, he sketched out a little code that allows you to get the ppm you are looking for based on the data obtained as a result of the calibration. I will not give the code here, those who wish can familiarize themselves with it, but it boils down to something like this:

float ppm = ((10000.0 / 4096.0) * raw_adc) + 200;

The above code is, by the way, from an example for an MQ-4 probe with a digital I 2 C interface. Note that this is better than nothing. Indeed, many are simply not able to reach such a transformation and are limited only by certain threshold values. For example, at a value of 750 (there is no unit of measure, this is a quantum), you need to turn on the red LED, in the range of 350-750 yellow is enough, and when below 350 let the green LED light up.

Alternatives?

If MQ sensors are that bad, is there any alternative to use in home projects? Actually there is. Even a lot. There are not one or two methods for measuring the concentration of gases. Only here the sensors with high accuracy cost decent money. And sometimes amphibious asphyxia comes from such a cost. The difference in cost can reach thousands and tens of thousands of times. Here you will involuntarily think about it.

However, quite recently, infrared detectors appeared on the market, thanks to the efforts of the same hardworking comrades. Yes, they are far from being for all gases, but at least CO 2 is caught without significant energy costs and with high selectivity. These sensors use a non-dispersive infrared method for determining the gas concentration.

If detection of other gases is required, but using inexpensive devices, then there are not so many options available at the moment (summer 2016), if not to say directly that there are very few of them. The use of the MQ series can be considered an alternative, although you will only have to manage the thresholds of values ​​​​(I have already spoken about the accuracy of the translation in ppm above).

Many will immediately object, they say, I personally used such a sensor, and it works. As examples, experiments are given akin to "breathe on the sensor", hold a hand around it, blow a cloud of cigarette smoke. Yes, the sensor readings will immediately change, the values ​​will creep up. Yes, the sensor will reflect that it has warmed up, that the humidity has increased, that there is more carbon in the atmosphere and less oxygen. But how much more, how much of the studied gas is now in the atmosphere and, most importantly, what kind of gas? This question can no longer be answered with the help of MQ series sensors. It is better to buy an ordinary household alarm for hazardous gases, the same CO. For quite comparable money, you will get a factory-made device with a loud alarm and low energy consumption.

Twin sensors

And in conclusion, I want to summarize. I am frustrated that such affordable sensors can in no way be used in any more or less serious project. Yes, you can practice programming and connecting sensors, but the reliable values ​​you are looking for cannot be obtained with their help. And the value of sensors will very soon rush to zero.

Moreover, I am personally convinced that all MQ sensors do not have a sufficient level of selectivity, differ only in external design and recommendations for selecting resistors. The sensors react to anything containing carbon and react more strongly the more active the carbon in the compound and the more easily it reacts with the substrate. I do not believe that the manufacturer adds additional elements to the substrate that increase selectivity and at the same time does not write anything to the specification. But I assume that one sensor can be turned into another by using different resistors and looking at resistance and concentration graphs.

But it all started with the fact that I connected two sensors (MQ-4 and MQ-7) to one device and started uploading the results of their work on ThingSpeak. One of the sensors should measure the level of toxic CO, and the second one should show how much methane is in the air. I was very interested in graphs that repeated each other more than almost completely. Yes, one sensor gave readings at the level of 100-150 units, and the second at the level of 350-400. Peaks and plateaus coincided in time from different sensors, and bursts only shaded the inevitable pattern.

I combined the readings of both sensors into a single correlation graph and realized that they show the same results, though in different ranges. And I asked myself - why do I need a methane sensor that reacts to everything? Ranging from carbon monoxide to alcohol. Why do I need a CO sensor, which, in addition to CO itself, reacts even more to LPG and hydrogen? That's right - no need.

update. Before throwing unnecessary sensors in the trash, I decided to disassemble a couple of them and see what they have inside. So:

The insides of the MQ-4 sensor

As you can see, the sensor has six legs. From two of them, a heating coil passes through the center of a tube of silvery substance. The other four legs each hold two thin wires, apparently to analyze the changing resistance.

The insides of the MQ-7 sensor

Despite the different appearance, the interiors of the MQ-7 are identical to those of the MQ-4. And the heated boss of a grayish color is nothing more than the desired tin oxide, which, when heated and in the presence of carbon or hydrogen (just those same gases), is partially reduced, tending to become metallic tin, and accordingly changes its resistance.

Description

The gas sensor module, the main element of which is the MQ-2 gas analyzer, allows you to detect the presence of hydrocarbon gases (propane, methane, n-butane), smoke, hydrogen in the ambient air. The sensor can be used in projects for detecting gas leaks, smoke. The analog-digital module allows both to receive data on the content of gases to which the gas analyzer is susceptible, and to work directly with devices, issuing a digital signal about exceeding/decreasing the threshold value. It has a sensitivity regulator, which allows you to adjust the sensor to the needs of a particular project. The module has two LEDs: the first (red) - power supply indication, the second (green) - indication of exceeding/decreasing the threshold value.

The main working element of the sensor is a heating element, due to which a chemical reaction takes place, as a result of which information about the gas concentration is obtained. During operation, the sensor should heat up - this is normal. It must also be remembered that due to the heating element, the sensor consumes a large current, so it is recommended to use an external power supply.

Please note that the sensor readings are affected by the ambient temperature and humidity. Therefore, in the case of using the sensor in a changing environment, it will be necessary to compensate for these parameters.

Measuring ranges:

    0-1% - propane

    0.03-0.5% - butane

    0.05-2% - methane

    0.03-0.5% - hydrogen

Specifications

    Supply voltage: 4.8 - 5.2 V

    Current consumption: 170 mA

    Warm-up time when turned on: 1 min

Physical dimensions

    Module (L x W x H): 35 x 20 x 21 mm

Pros of using

    Optimum cost-effective solution for gas and smoke detection projects

    Easy-to-use module due to the presence of digital and analog outputs

Cons of using

    Before use requires a long warm-up (at least 24 hours)

    Warm-up required to take readings (at least 1 minute)

    High power consumption (additional power is desirable)

Example of connection and use

The example demonstrates connecting a sensor and outputting the received data to the Serial port monitor. (Example tested on Smart UNO controller)

Wiring diagram:

Download sketch:

const int analogSignal = A0; //connect analog signal pin const int digitalSignal = 8 ; //connect digital signal pin boolean noGas; //variable for storing the value of the presence of gas int gasValue = 0 ; // variable to store the amount of gas void setup() ( pinMode (digitalSignal, INPUT ) ; //set pin mode Serial.begin(9600) ; //initialization of the Serial port) void loop() ( noGas = digitalRead(digitalSignal) ; //read the value of the presence of gas gasValue = analogRead(analogSignal) ; // and about its quantity //message output Serial .print("There is " ) ; if (noGas) Serial .print("no gas" ) ; else Serial .print("gas") ; Serial .print(", the gas value is ") ; Serial .println(gasValue) ; delay(1000) ; //delay 1s)