MQ3 alcohol sensor Arduino code | Step by step instructions

MQ3 alcohol sensor Arduino code

            Hello guys, welcome back to another tutorial from the SriTu Hobby. In this tutorial, we will learn how to work the MQ3 alcohol sensor with Arduino code. With this sensor, we can measure the alcohol level in the air. Also, this MQ3 sensor can be used mainly to create projects to get the level of alcohol in the human body. So, we can buy this sensor in the market at a low price.

MQ3 alcohol sensor Arduino




The structure of this MQ3 sensor

These sensors are made of iron mesh on the surface and a plastic cover on the outside. Also, these sensors are designed so that only gaseous elements can travel inside. These are also known as heater-driven sensors. If we talk about the interior of these sensors, there are 6 legs connected to the sensing element. Two of these six legs are used to heat the sensing element. Also, these are connected via a nickel-chromium coil. The other 4 legs are connected to the body of the sensing element using the platinum element. If we talk about this sensing element, it 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 Arduino
MQ3 alcohol sensor Arduino
MQ3 alcohol sensor Arduino

Sensor activation on clean air

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 electric current. So, the output voltage decreases.

Sensor activation on alcohol.

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. Then the current flows freely. So, the output voltage increases.
We can get this output voltage in the form of analog input and digital input. That task is performed by the module to which this sensor is connected. The Potentiometer in this module can also change the sensitivity of the digital input.




OK, now let’s see the pin structure of this sensor.

MQ3 alcohol sensor Arduino
OK, now we will learn step by step how this sensor works with Arduino. The required components are as follows.

Step 1

Firstly, identify these components.

Arduino UNO board.

MQ3 sensor.

Breadboard.

5V buzzer.

LED bulb

180-ohm Resistor

Jumper wires




Step 2

Secondly, connect these components. For that, use the circuit diagram below.
MQ3 alcohol sensor Arduino circuit diagram

Step 3

Thirdly, let’s create a program for this project. It is as follows.
The complete program of this project – Download
/*MQ-3 sensor with Arduino.
  created by the SriTu Tech team.
  Read the code below and use it for any of your creations.
  http://srituhobby.com
*/
#define sensorDigital 2
#define LED 3
#define buzzer 4
#define sensorAnalog A1
 
void setup() {
  pinMode(sensorDigital, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  bool digital = digitalRead(sensorDigital);
  int analog = analogRead(sensorAnalog);
 
  Serial.print("Analog value : ");
  Serial.print(analog);
  Serial.print("t");
  Serial.print("Digital value :");
  Serial.println(digital);
 
  if (digital == 0) {
    digitalWrite(LED, HIGH);
    digitalWrite(buzzer, HIGH);
  } else {
    digitalWrite(LED, LOW);
    digitalWrite(buzzer, LOW);
  }
}

Code explanation

First, sensor-connected PIN, LED connected PIN, and buzzer connected PIN is defined.
#define sensorDigital 2
#define LED 3
#define buzzer 4
#define sensorAnalog A1
 
Second, these PINs are converted to OUTPUT and INPUT PIN. Also, the serial monitor is enabled in the void setup.
void setup() {
  pinMode(sensorDigital, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}
In the void loop, the digital and analog values received through the sensor are inserted into two separate variables and printed on a serial monitor. Also, if the digital value is 0, the LED and the buzzer turn ON, and if the digital value is 1, the LED and the buzzer turns off.
void loop() {
  bool digital = digitalRead(sensorDigital);
  int analog = analogRead(sensorAnalog);
 
  Serial.print(“Analog value : “);
  Serial.print(analog);
  Serial.print(“t”);
  Serial.print(“Digital value :”);
  Serial.println(digital);
 
  if (digital == 0) {
    digitalWrite(LED, HIGH);
    digitalWrite(buzzer, HIGH);
  } else {
    digitalWrite(LED, LOW);
    digitalWrite(buzzer, LOW);
  }
}

Step 4

Lastly, select the correct board and port. Afterward, upload this program to the Arduino board.




Step 5

OK, now test this project, For that, use Alcohol. The full video guide is given below. So, we will meet in the next tutorial.

MQ3 alcohol sensor Arduino code | Step by step instructions

Similar Posts

Leave a Reply

Your email address will not be published.