Arduino Alcohol Sensor Code

1,442 views

MQ3 is one of the most commonly used sensors in the MQ sensor series. This sensor is suitable for detecting alcohol concentration in the air or from the breath and is used to detect different gasses present in the air. It is a metal oxide semiconductor (MOS) type of sensor. Metal oxide sensors are also known as chemiresistors. Because sense is based on the change of resistance of the sensing material when exposed to alcohol.  These sensors are made of iron mesh on the surface and a plastic cover on the outside. Therefore only gaseous elements can travel inside. These are heater-driven sensors. There are 6 legs, connected to the sensing element. Two of these six legs are used to heat the sensing element, via a nickel-chromium coil.

The other 4 legs are connected to the body of the sensing element, by using the platinum element. If we talk about this sensing element, is made of ceramic containing aluminum oxide and coated with tin dioxide on the outside. Also, these tin dioxides are very sensitive to alcohol. The ceramic substrate here controls the heat as needed. MQ3 alcohol sensor works on 5V DC and draws around 800mW. It can detect alcohol concentrations anywhere from 25 to 500 ppm. Along with high sensitivity to detect alcohol, it can also detect benzine with a lower sensitivity. As the concentration of alcohol rises in the air, the conductivity of the sensor becomes higher. This change in conductivity is converted to an output value, that indicates the concentration of alcohol. It is very popular and widely used, because of its fast response time and high sensitivity, which can be changed via a potentiometer attached to the module. Now for interfacing gas sensors with Arduino, you just need to put the correct code to the Arduino microcontroller through IDE. In this case, we used an Arduino Uno board.

Hardware Required

S.noComponentValueQty
1.Arduino UNO1
2.USB Cable Type A to B1
3.Jumper Wires
4.Alcohol Sensor MQ31
5.Resistor 10KΩ1

Arduino Alcohol Sensor MQ-3 Interfacing

Working Explanation

Gas Sensor MQ3 will have 6 pins and two A and B sides, for sensing output to connect analog output pin (A0), we can use either A side or B side terminals (there are breakout boards for MQ3 (Alcohol) Sensor available in the market, you can use those boards also). Here two middle pins are dedicated for the heater (H1, H2 terminals), connecting +5V supply to A1, A2, and H1 terminals. and connect the GND supply to H2 and B2, through a 10KΩ resistor. And then connect the B1 terminal to analog input pin A0.

The tin dioxide-coated sensing element (we talked about above) absorbs oxygen to the surface when heated to a high temperature. When fresh air enters the sensor, electrons are attracted to oxygen molecules from the tin dioxide zone. Then a layer of electron decay forms below the tin dioxide particles. Also, a potential barrier is created. The tin dioxide film then blocks the flow of the electric current. So the output voltage decreases, which shows that the air is clean.

Now when the alcohol mixture is brought close to the air sensor, it reacts with the tin dioxide (reducing the surface absorption of oxygen). Then the potential barrier decreases. The electrons are then released into the tin dioxide, and the current flows freely. Therefore the output voltage increases, and we can get this output voltage in the form of analog input and digital input. The task is performed by the module, to which this sensor is connected.

Arduino Alcohol sensor code

int mq3_analogPin = A0; // connected to the output pin of MQ3

void setup(){
Serial.begin(9600); // open serial at 9600 bps
}

void loop()
{
// give ample warmup time for readings to stabilize

int mq3_value = analogRead(mq3_analogPin);
Serial.println(mq3_value);

delay(100); //Just here to slow down the output.
}

Code Explanation

Firstly, we will define the AOUT pin connection with Arduino UNO. We have used A0 in this case.

Inside the setup() function, we will open the serial communication at a baud rate of 9600.

In the loop() block, we will use analogRead() on the A0 pin and save the value in ‘mq3_analogPin’. This will be displayed on the serial monitor, after every 0.1 seconds. 

Once the code is uploaded to Arduino, open the serial monitor and set the baud rate to 9600. Bring the sensor closer to isopropyl alcohol/ sanitizer/ perfume vapors, the serial monitor will start showing the presence of alcohol vapors.

To connect the Analog output pin (A0), we can use either A-side or B-side terminals. There are breakout boards for MQ3 (Alcohol) sensor available in the market, you can use those boards also.

Applications

Can be used as a breath analyzer, portable alcohol detection, background sensing device, gas level over limit alarm, environmental monitoring equipment, and so on.