Alcohol vapor sensor mq 3 application diagrams. Alcohol vapor concentration tester for AVR. Digital sensor with digital bus

When I had an Arduino kit, in search of an object for automation, I somehow thought to myself that it would be nice to receive information about whether the level of CO (carbon monoxide) in winter time in the boiler room of a country house. On cold winter days and especially nights, gas equipment works in intensive mode and it burns natural gas to keep the house warm. What if I have poor ventilation? Or is there a felt boot stuck in the pipe? And every time I enter the boiler room and stay there for some time, I put my precious life in danger. And no one is immune from natural gas leaks either. Here you can actually 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 Arduino or a compatible board. In addition to simple alarms, I would also like to collect statistics, for example, on how the concentrations of dangerous 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 the sensor built into the gas meter, and to analyze the air I used two extremely popular among developers Arduino sensor MQ-4 and MQ-7. The MQ4 sniffs the air for methane, while the MQ7 takes measurements for CO.

But in order to go further, it turned out that we needed to go into specific detail. Since few users of Arduino and analogues understand what kind of sensors MQ-4 and MQ-7 are, and how to use them in general. Well, let’s slowly begin the fascinating story.

What is ppm

In order to properly operate with the values ​​that I will give below, you need to understand the units of measurement for yourself. Here, on the territory of the former Soviet Union, indicators are usually measured as a percentage (%) or directly in mass to volume (mg/m 3). But in some foreign countries uses an indicator such 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/m3 is more complicated; here you need to take into account the molar mass of the gas, pressure and temperature. In general, the formula for conversion 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 the absolute temperature in Kelvin (not Celsius or 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 explorers can find online calculators on the vast web for independent calculations.

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

Data given for normal atmospheric pressure and room temperature. Note that CO2, at comparable percentages, 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 precisely because of this difference that CO 2 accumulates in the lowlands, and CO near the ceiling.

Difference between CO and CO 2

First, it’s worth understanding what CO is and how it differs from CO 2 . First, CO is carbon monoxide, also called carbon monoxide, carbon monoxide, or carbon (II) monoxide. CO gas is very insidious. It is extremely poisonous, but has neither color nor odor. Once in a room with carbon monoxide, you will only understand from indirect symptoms that you are exposed to poison. First, headache, dizziness, shortness of breath, palpitations, then blueness of the corpse. Carbon monoxide combines with hemoglobin in the blood, 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 no worse than other flammable gases. At certain concentrations, it forms an explosive mixture that is ready to smash into pieces 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 release, 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 released into the atmosphere. In the everyday sense, an excellent source of CO, if not used correctly, can be wood stoves, gas burners, gas boilers and other heating equipment that runs on carbon fuel. Don’t forget about cars, the exhaust of a gasoline engine can contain up to 3% CO, and according to hygienic 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 your forefathers by lighting 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 with carbon monoxide. We drink carbonated water in which carbon dioxide is dissolved. We use dry ice to preserve ice cream in the park on a hot summer afternoon, we finally exhale carbon dioxide in crazy amounts. Yes and natural objects, such as volcanoes, swamps or landfills, can generate a fair amount of carbon dioxide.

But don’t 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 fatal outcome. And you can increase your concentration easily and naturally just by closing the window in your bedroom at night. Moreover, unlike CO, carbonic anhydride is heavier than air and dangerously accumulates in low-lying areas, basements, crawl spaces and other unexpected places. Cases of deaths of people who accidentally fell into hollows full of carbon dioxide leaking from a neighboring volcano have been documented. The bus engine stalls, there is not enough air 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 consist of only two types of elements. From oxygen (O) and carbon (C), the only question is the number of oxygen atoms. A knowledgeable reader can guess that one gas can be transformed into another with extraordinary ease. Yes, it can, but not quite easily and not quite ordinary. You need to make an effort. For example, in the catalytic converters of modern gasoline cars, the process of afterburning (converting) CO into CO 2 occurs. The process takes place at high temperature and in the presence of catalysts (eg platinum). The reverse process is also possible, but again it is not easy.

By the way, there is a website on the Internet called CO2.Earth that displays the dynamics and current concentration of carbon dioxide in the Earth’s atmosphere. Yes, the concentration is not that low. Indeed, when carbon dioxide accumulates 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 have deviated a little from the topic, but the conclusion here is this: you should not confuse two different gases, as well as the consequences from them, but it is definitely worth monitoring their presence in the indoor atmosphere.

Design of electrochemical sensors

The most common type of MQ sensors. And it is widespread solely due to its low cost. I did a little research to try to understand the issue of electrochemical sensors a little more than most DIY enthusiasts.

An electrochemical sensor is built on the principle of changing the resistance of a certain element when interacting with another element. In other words, what happens chemical reaction 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 for the sensor to not be disposable, the sensitive part of the sensor must be kept in a heated state.

So the electrochemical sensor consists of a certain substrate with sensitive material, a substrate heater and the output contacts themselves. A metal mesh is stretched over the top of the sensor, but the substrate heats up noticeably, and all sorts of flammable gases can be around the sensor, such as CO. This is what a grid is required for. Safety comes first. By the way, a certain Humphrey Davy came up with the idea of ​​stretching mesh over dangerous elements when used in explosive environments for miners at the beginning of the 19th century.

On the network you can count a couple of dozen manufacturers of boards with electrochemical sensors of the MQ series. But all sensors (not boards) have the same manufacturer - the Chinese company HANWEI. The company produces a wide range of various devices for detecting gases and everything related to them. But there are no MQ series sensors among the product range; it is possible that the products are too small to be posted on the website.

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

Sensor

Gas

Substrate

MQ-2 LPG SnO2
MQ-3 Alcohol SnO2
MQ-4 CH 4 SnO2
MQ-5 LPG, natural gas SnO2
MQ-6 LPG, propane SnO2
MQ-7 CO SnO2
MQ-9 CH4, LPG SnO2
MQ-131 O 3 SnO2
MQ-135 Air Quality SnO2
MQ-136 Air Quality SnO2
MQ-137 Air Quality SnO2
MQ-138 Multi-purpose SnO2
MQ-303A Alcohol ???
MQ-306 LPG, LNG ???

With the exception of the 300 Series MQ sensors, they all use the same substrate material. It is for the very substrate that determines the gas concentration in the atmosphere, precisely for the substrate that changes its resistance. All sensors use the same one. For the 300 series, information about sensitive material is modestly omitted.

Despite the uniform design and the sensing element used, it cannot be said that all sensors from the manufacturer are the same. They differ in shape and parameters such as, for example, heater supply voltage. You can take readings from such sensors using an ohmmeter, measuring the resistance, which changes depending on the concentration of the gas being measured. Or by adding a load resistor to 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 the work itself, but also storage. And if your sensor is stored without proper packaging, its shelf life is even shorter. The point is that sensitive chemical element, without heating, will be saturated with carbon, which will gradually destroy it all. It is for this reason that it is recommended to “calcinate” new sensors by keeping them in working condition 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 readings with higher accuracy.

If you look closely at the list of measured gases or the purpose of the sensors, you will see that all of them, one way or another, are related 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 apart, although it uses the same sensing element with SnO 2. The fact is that all MQ series sensors are designed to operate in an atmosphere with a stable oxygen level. The specification tells us that the oxygen content should be 21%, which is some kind of average norm. And if there is less or more oxygen, then the readings will fluctuate, up to the complete inability of the sensor to produce intelligible results at an oxygen content of 2% or lower. Of course, in this case the carbon will not burn out on the substrate at all; there is not enough oxidizing agent. Apparently, the measurement of ozone with an electrochemical sensor is based on this effect.

But the accuracy of the MQ Series sensors depends on more than just oxygen. The readings vary well depending on air humidity and temperature. Calculation figures are given for a humidity of 65% and a temperature of 20 degrees Celsius. And if the humidity is above 95%, the sensor will no longer provide adequate readings. It’s a pity that the specification doesn’t indicate what humidity is used: relative or absolute. Intuition suggests that everything is relative.

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

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

Looking at the graph from the specification, you can see that, firstly, it has at least one logarithmic region. And, secondly, in addition to the main gas, the sensor easily detects all other similar gases (carbon-containing). Understanding the graph and understanding which ppm corresponds to which sensor resistance is a task for practicing samurai, since a straight line crossing several different logarithmic zones will obviously not be straight in reality.

With this I would like to draw an intermediate conclusion. So, the advantages of the MQ series sensors include their extremely and categorically affordable price. But there are many more disadvantages:

  • Virtually identical sensors using the same sensing element and differing in the used value of trimming resistors.
  • Dependence of measurement results on many factors: temperature, humidity, oxygen concentration.
  • The lack of declared selectivity for measured gases reacts to everything with carbon (and, quite possibly, to other elements that react with the substrate).
  • High energy consumption (heater).
  • The need for initial “annealing” of the sensor.
  • Instability of readings over time.
  • The need for initial and repeat calibration.
  • It is practically impossible to obtain meaningful values ​​in the form of ppm or %.

Digital or analogue?

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 definitely happen. And with the use of nimble Chinese comrades, the demand is satisfied sooner rather than later. This is how a great many manufacturers from China appeared, producing ready-made boards with electrochemical sensors of the MQ series. Let's take a closer look at what delivery options there may be.

Clean sensor

The simplest and cheapest option. The delivery contains only the electrochemical sensor itself and nothing else. You need to connect it to a system with voltage measurement (for example, to an Arduino analog port) through a load resistor. It is best to use a resistor that can be adjusted during calibration. Resistor values ​​are indicated in the specification (DataSheet) for the sensor.

At alternative way measurements, you can use an ohmmeter and measure the resistance of the sensor outputs, and then recalculate it into desired results according to the same specifications.

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

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

Digital sensor

It would seem that if the sensor is digital, then it should provide 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 simply means that the sensor has a digital output that switches to HIGH mode when the concentration of the gas being measured is exceeded. And the user carries out the main reading of values ​​in the same analog way as with an ordinary analog sensor.

It is clear that all resistors are already soldered on the digital sensor boards. And good sensors also have trimming resistors available for tuning the sensor. One is used to configure the sensor, and the second 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 remote from the measuring device and there is a risk of picking up interference on a long cable.

Digital sensor with digital bus

Perhaps this is the most Hi End among similar sensors. Connection and data transfer are carried out via the I 2 C digital bus. And as many as a hundred of these sensors can be connected to one information acquisition device (for example, Arduino). You just need to 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 it is already converted into ppm values ​​in software. 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 MQ sensor heater to work, it needs to be supplied with high-quality power and in sufficient volume. According to the specification, the sensors consume about 150 mA. In reality, consumption can vary within a very wide range. In principle, 150 mA is not such a large current until they try to cross a device (or several) with such consumption with something like Arduino. By connecting even one such sensor to the power supply on the board, you already run the risk of getting an inoperable device that will not have enough voltage for normal operation. During operation, the sensors themselves heat up, not significantly, but up to forty degrees they can easily heat up. If we compare this temperature with 60-70 degrees on the stabilizer that powers these sensors, then the temperature of the sensors can be considered tolerable.

To ensure normal operation of the heater and, as a consequence, 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 to the voltage required to power the sensors.

In any case, with a current source having the required power, you'll have to tinker. 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 more to it.

Option to calibrate the sensor and convert readings to ppm

Wandering the web in search of a solution for calibration and obtaining reliable results from the sensor, I came across a very interesting post from a certain Davide Gironi, who encountered 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 research conducted by the blogger, for calibration, it is enough to have an idea of ​​​​the concentration of some gas in the atmosphere and, based on this data, try to select a resistor to fall into the desired sector according to the schedule. Davide used the MQ-135 sensor, which is designed to determine air quality, among the monitored gases of which is CO 2. And it was carbon dioxide that most interested the blogger. 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 small code that allowed him to obtain the required ppm based on the data obtained as a result of calibration. I won’t give the code here; anyone can read it themselves, but it boils down to something like this:

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

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

Alternatives?

If MQ sensors are so bad, is there any alternative for use in home projects? Actually there is. Even a lot. There are more than one or two methods for measuring gas concentrations. Only high-precision sensors cost a lot of money. And sometimes from such a cost amphibiotropic asphyxia occurs. The difference in cost can reach thousands and tens of thousands of times. Here you can’t help but think about it.

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

If detection of other gases is required, but using inexpensive devices, then there are not many available options at the moment (summer 2016), if not to say frankly that there are very few of them. An alternative is to use the MQ series, although you will only have to make do with value thresholds (I already spoke above about the accuracy of the conversion to ppm).

Many will immediately object, saying, I personally used such a sensor, and it works. Examples include experiments akin to “breathing on a sensor,” holding your hand around it, or blowing 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 humidity has increased, that there is more carbon and less oxygen in the atmosphere. But how much more, how much of the gas being studied is now in the atmosphere, and most importantly, what kind of gas? It is no longer possible to answer this question using MQ series sensors. It’s better to purchase an ordinary household hazardous gas alarm, like CO. For quite comparable money you will get a factory-made device, with a loud alarm and low energy consumption.

Twin sensors

And finally, I want to summarize. I'm upset 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 you won’t be able to get the reliable values ​​you are looking for using them. And the value of sensors will very soon go to zero.

Moreover, I am personally convinced that all MQ sensors do not have a sufficient level of selectivity; they differ only in their external design and recommendations for the selection of resistors. The sensors respond to anything containing carbon and react more strongly the more active the carbon in the compound is and the more easily it reacts with the substrate. I do not believe that the manufacturer adds additional elements to the substrate to increase selectivity and does not write anything in 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 when I connected two sensors (MQ-4 and MQ-7) to one device and started uploading the results of their work to ThingSpeak. One of the sensors should measure the level of toxic CO, and the second should show how much methane is in the air. I was very interested in the graphs, which 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 the bursts only highlighted the inevitable pattern.

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

Update. Before throwing unnecessary sensors into the trash, I decided to disassemble a couple of them and see what’s inside them. So:

Internals 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 made of a silvery substance. The other four legs each hold two thin wires, apparently to analyze the changing resistance.

Internals of the MQ-7 sensor

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

Answer

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five http://jquery2dotnet.com/ centuries , but also the leap into electronic typesetting, remaining essentially unchanged. It was popularized in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.



This project uses the MQ-3 alcohol content sensor. Thanks to the sensor board, you can connect the MQ-3 to an Arduino microcontroller to detect the ppm level of your breath.

The sensor produces an analog signal (usually interpreted into numerical values ​​from 150 to 1023, depending on the duration of heating of the sensor), which is processed and interpreted by Arduino software code, with the possibility of calibration.

Assembling the device
When connecting the MQ-3 to the board, please note that the polarity of the MQ-3 does not matter. Both terminals A are the same as terminals B. The center terminals on both sides are the heating element terminals. The sensor circuit operates from a +5V DC voltage source.


Note: The MQ-3 may become warm and even emit an odor when first used. It's quite normal.

Calibration: If you take your time, you can find out what numbers correspond to percentages and even blood alcohol concentration when using an alcohol breath tube.

Of course, you need to calibrate the MQ-3 sensor based on the sensor readings calculated by the Arduino code, as they may vary. For calibration, you can use a bottle of isopropyl alcohol to obtain different percentages while testing. Do not immerse the sensor in alcohol! Simply allow the alcohol vapor to hit the sensor and take a reading.

Description

The MQ-3 sensor is highly sensitive for detecting ethyl alcohol vapors and low sensitivity to gasoline vapors. Suitable for alcohol vapor detection projects, detection alcohol intoxication when exhaling. The analogue-digital module allows you to both receive data on the content of gases to which the gas analyzer is sensitive, and work directly with devices, issuing a digital signal about exceeding/decrease of the threshold value. It has a sensitivity regulator, which allows you to adjust the sensor to the needs of a specific project. The module has two LEDs: the first (red) is a power indication, the second (green) is an indication of exceeding/decrease of the threshold value.

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

Please note that sensor readings are affected by ambient temperature and humidity. Therefore, if the sensor is used in a changing environment, compensation for these parameters will be necessary.

Measuring range: 0.05 - 10 mg/l

Specifications

    Supply voltage: 5 V

    Current consumption: 160 mA

    Warm-up time when turned on: 1 min

Physical Dimensions

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

Pros of use

    High sensitivity to ethyl alcohol vapor (alcohol)

    Short response time

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

Disadvantages of use

    Requires a long warm-up period (at least 24 hours) before use.

    Warming up is 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. (The example was tested on the Smart UNO controller)

Connection diagram:

Sketch to download:

const int analogSignal = A0; //connect analog signal pin const int digitalSignal = 8 ; //connect digital signal pin boolean noGas; //variable for storing the value about the presence of gas int gasValue = 0 ; //variable for storing the amount of gas void setup() ( pinMode (digitalSignal, INPUT ) ; //set pin mode Serial.begin(9600); //initialize Serial port) void loop() ( noGas = digitalRead(digitalSignal); //read the value about the presence of gas gasValue = analogRead(analogSignal); // and about its quantity //output message 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 1 s)

Many people know that traffic police officers, in cases of suspected alcohol use, use a certain device about which they say “blow into a straw.” Today we will try to make an analogue of such a device based on the MQ-3 sensor, but in just such a situation it is not worth using it as a reference, since in the area of ​​its sensitivity there are not only alcohol vapors, but also gasoline, methane and hexane vapors, but to these Its sensitivity to gases is less, the maximum response is only to alcohol. In addition to this, there is another rake - the sensor readings also depend on external factors such as temperature, humidity. If you take a serious approach to using an alcohol tester, it is worth compensating for these factors. In general, the scope of application is not limited to monitoring the degree of alcohol intoxication, I don’t know why this MQ-3 sensor was developed in the first place, but they can be used in places where it is necessary to control the concentration of such a gas in the air, for example, when transporting alcoholic products, such a sensor will give a signal and damage to a batch of products (if a bottle breaks, the alcohol will begin to evaporate and fill the space with vapor; as soon as the limit is reached, the sensor will go off and give an alarm to the driver or someone else), or in production that requires the consumption of alcohol, if the consumption exceeds the concentration in air will increase and the sensor will work, giving a signal and reducing consumption, and so on, since alcohol is necessary in the production of perfumes. As usual, the application is limited only by the engineer's imagination.

So the sensor itself looks like this:

The sensor has 6 pins: pins H are a filament (made of Ni-Cr), pairs A and B are the sensor signal output.

The sensitive layer for alcohol vapor in this sensor is tin oxide, and the electrodes are made of gold and platinum. Speaking of the price of the sensor, this parameter significantly depends on the materials required to manufacture the sensor.

MQ-3 sensor parameters:

  • heating coil supply voltage - 5 volts
  • sensor supply voltage - 5 volts
  • heating coil power - up to 750 mW
  • Heating coil resistance 33 Ohm +-5%
  • vapor detection area by sensor - 0.05 mg/l - 10 mg/l
  • current consumption - approximately 150 mA

Before fully using the sensor in a circuit, it must be warmed up for 24 hours by connecting 5 volts to the heating coil. This is necessary to stabilize the sensor readings (apparently chemical processes are stabilized after the manufacturing process). And thus, before using the sensor, it needs to be warmed up a little. The subsequent warm-up cycle after a 24 hour period can be reduced to one minute. During operation, just because of the heating element, the sensor may be either warm or slightly hot - this is normal.

The design of the sensor is a kind of housing with leads at the bottom and a mesh at the top. Through the mesh, alcohol vapors reach the sensitive element, where a chemical reaction takes place, transforming physical quantity to electric. In fact, the sensitive element is protected only by a mesh from outside world, therefore, the sensor as a whole is also sensitive to physical contamination by dirt, dust, and so on (apparently, this is why “blow into a straw” devices are equipped with just a straw to interact only with the breath of the test subject, excluding external contamination, including gas).

The MQ-3 sensor can be purchased either separately, just one sensor, or as a module equipped with a comparator. The cost of such an item can vary from $3 or more depending on the mood of the seller. Sensors can be found on online trading platforms aliexpress and ebay.

In addition to the MQ-3 sensor, the module is equipped with a comparator, a trimming resistor for adjusting the comparator threshold, and an LED at the output of the comparator chip to indicate when the threshold has been reached. The module has pins for power supply, a comparator output pin and a pin directly connected to the sensor output.

Before considering the concentration detector circuit, it is necessary to note the fact that before use, the sensor readings must be calibrated. Why? When connected to power, the sensor, depending on the alcohol content in the air, will output a proportional signal level. So, in order to determine how this proportion is balanced (how many volts per concentration, say 1 mg/l), it is necessary to give the sensor exactly this concentration (or another) and determine the ratio. Next, use this coefficient to convert sensor readings into numbers. Without calibration, accurate data can only be obtained at random or by taking readings of the nature of alcohol vapors, there are none, there are many of them, there are few of them, that is, to determine “by eye”.

So, let's start with the alcohol vapor tester circuit:

The circuit is built on an Atmega8 microcontroller. This microcontroller can be used both in a DIP-28 package and in an SMD version in a TQFP-32 package. Resistor R4 is necessary to prevent spontaneous restarting of the microcontroller in the event of random noise on the PC6 pin. Resistor R4 pulls the power plus to this pin, reliably creating a potential across it. A liquid crystal display (LCD) is used for display. I used a large display 2004 (4 lines of 20 characters), but all the information will fit on the display 1602 (2 lines of 16 characters), the firmware was written with this calculation in mind.Variable resistor R2 is necessary to adjust the contrast of the characters on the display. By rotating the slider of this resistor we achieve the clearest readings on the screen for us. The backlight of the LCD display is organized through pins “A” and “K” on the display board. The backlight is turned on through a current-limiting resistor - R1. The higher the value, the dimmer the display will be backlit. However, this resistor should not be neglected to avoid damage to the backlight. The operation of the circuit involves the operation of the module microcontroller ADC, therefore, to power it, an inductor L1 and a capacitor C4 are required to ensure stable operation of the module - filtering power supply noise. Resistor R6 is necessary to limit the current passing through the LED. By the way, the LED can be replaced with another device or electrical circuit that is triggered when the alcohol vapor concentration limit, set using the S3 and S5 buttons, is exceeded. The adjustment interval for this parameter is plus or minus 0.05 mg/l per button press. Resistor R8 also limits the current flowing through the MQ-3 sensor's heating coil. This slightly reduces the maximum current through this coil and increases the reliability of the circuit. The signal from the alcohol sensor is fed to the ADC input of the microcontroller, which continuously monitors the potential at this pin. Next, in the microcontroller, the ADC value is converted into voltage and alcohol concentration, taking into account calibration coefficients (they can be set using the S2 and S4 buttons).

The manufacturer promises a more or less linear characteristic of the MQ-3 sensor readings. This simplifies calibration; you only need to enter two coefficients to correct the readings. To do this, we will use a simple school formula y=k*x+b, where y - alcohol concentration, x - voltage from the sensor, b - shift of the operating range (at zero concentration the voltage will always be greater than 0), k - coefficient of conversion of voltage to concentration. With coefficient k the most a big problem, because it can be set either by inventing it out of your head, or by a sensor signal from a reference concentration source. Both coefficients can be set using the device buttons. The b calibration should occur at a concentration completely zero at rest, when pressed the b factor will be stored and subtracted from the current value, thus at zero concentration the screen will show a value of zero, and not some small value (or not very small). Coefficient k specifies the ratio of voltage to alcohol concentration, that is, how many volts will a concentration of 1 mg/l be required. It is at this value that the device should be calibrated (naturally, it can be calibrated at a different concentration, but then this must be provided for in the microcontroller firmware).

  1. current value of the microcontroller ADC
  2. voltage calculated taking into account coefficient b (initially when turned on b=0, must be calibrated before each use)
  3. value of the concentration limit set by the device buttons
  4. alcohol concentration value in mg/l recalculated through voltage taking into account the coefficient k

The entire circuit will consume about 200 mA or more, therefore, in order not to heat the air, it is proposed to use pulse stabilizer voltage on the MC34063 chip. However, you can use any other stabilizer or stabilizer chip in accordance with its connection to the circuit.

All resistors in the circuit can be used with a power of 0.25 W or size 1206 in SMD version.

The circuit was compiled on breadboard for Atmega8 microcontroller:

In the breadboard, the MQ-3 sensor is connected to a separate 5 volt power supply from another USB port on the computer.

Although the alcohol vapor sensor module is used as a module, but only the pin is used, connected directly to the MQ-3 sensor itself. Nothing but it is used in the module anymore.

To program the microcontroller you need to know the fuse bit configuration:

The article includes firmware for the microcontroller, documentation for the MQ-3 sensor, a project (version 8) (the sensor is replaced with a potentiometer to change the readings and track them), as well as a short video demonstrating the operation of the device (when a bottle of alcohol is brought to the sensor, the readings begin to change and when the limit is reached, the LED lights up, then the bottle is removed and the readings begin to decrease, however, due to the inertia of the sensor, the readings decrease quite slowly, especially when approaching zero).

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
IC1 MK AVR 8-bit

ATmega8

1 To notepad
IC2 DC/DC pulse converter

MC34063A

1 To notepad
VD1 Schottky diode

1N5819

1 To notepad
U1 Gas sensorMQ-31 To notepad
C1, C4, C5 Capacitor0.1 µF3 To notepad
C2 100 µF1 To notepad
C3 Capacitor220 pF1 To notepad
C6 Electrolytic capacitor1000 µF1 To notepad
R1 Resistor

22 Ohm

1 To notepad
R2 Trimmer resistor10 kOhm1 To notepad
R3 Resistor

0.3 ohm

1 Or several in parallel To notepad
R4 Resistor

10 kOhm

1 To notepad
R5 Resistor


If you find an error, please select a piece of text and press Ctrl+Enter.