ESP32 - MQ3 Alcohol Sensor

This tutorial guides you through interfacing the MQ3 alcohol sensor with ESP32 to detect and measure ethanol and alcohol vapor concentrations in the surrounding air. The MQ3 sensor serves as a fundamental component for breathalyzer projects, alcohol detection systems, and air quality monitoring applications.

In this guide, we will cover:

ESP32 with MQ3 alcohol gas sensor module

Hardware Used In This Tutorial

1×ESP-WROOM-32 Dev Module
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×MQ3 Alcohol Sensor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32
1×Recommended: Breakout Expansion Board for ESP32
1×Recommended: Power Splitter for ESP32

Or you can buy the following kits:

1×DIYables ESP32 Starter Kit (ESP32 included)
1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links in this section are Amazon affiliate links, meaning we may earn a commission at no additional cost to you if you make a purchase through them. Additionally, some links direct you to products from our own brand, DIYables .

Introduction to MQ3 Alcohol Sensor

Classified as a Chemiresistor, the MQ3 utilizes Metal Oxide Semiconductor (MOS) technology to sense alcohol through resistance variations in its detection layer. This sensor demonstrates exceptional sensitivity to ethanol vapor across varying concentration levels.

The sensor's heart consists of Tin Dioxide (SnO2) coated onto an Aluminum Oxide ceramic substrate. Heating this material enables it to interact with alcohol molecules. A protective stainless steel mesh (anti-explosion screen) encases the sensor element, safeguarding the heating component while allowing gas diffusion into the sensing chamber.

Common applications include breathalyzer devices, DUI detection equipment, alcohol alarm systems, and environmental alcohol vapor monitoring.

Technical Specifications

  • Operating Voltage: 5V DC
  • Load Resistance: 200 KΩ
  • Heater Resistance: 33Ω ± 5%
  • Heating Consumption: < 800mW
  • Sensing Resistance: 1 MΩ – 8 MΩ
  • Detection Range: 25 – 500 ppm (parts per million)
  • Preheat Time: 24-48 hours for first use

About ppm: Parts-per-million (ppm) expresses the concentration ratio of target molecules to total gas molecules. For instance, a 500 ppm reading means 500 alcohol molecules exist per 1,000,000 total molecules, with 999,500 being other atmospheric components.

Pinout

The MQ3 sensor module features four connection pins:

  • VCC pin: Connect to +5V power supply.
  • GND pin: Connect to ground (0V).
  • DO pin: Digital output—goes LOW when alcohol exceeds threshold, HIGH otherwise. Adjust threshold via the onboard potentiometer.
  • AO pin: Analog output—voltage varies with alcohol concentration. Higher alcohol produces higher voltage.
MQ3 alcohol sensor module pinout diagram

Visual indicators include two LEDs:

  • PWR-LED: Lights up when the module receives power.
  • DO-LED: Mirrors the digital output state—illuminates during alcohol detection, stays dark otherwise.

How It Works

The MQ3 operates through resistance changes in its Tin Dioxide (SnO2) semiconductor material:

Clean air state: Heating the SnO2 causes oxygen molecules to adhere to its surface, capturing electrons and forming a depletion layer. This electron capture creates a conductivity barrier, maintaining high resistance.

Alcohol presence: Alcohol molecules react with surface oxygen, breaking bonds and releasing trapped electrons back into the tin dioxide. This boosts conductivity—higher alcohol levels mean lower resistance.

The sensor provides two output modes:

Digital Output (DO pin):

  • Threshold setting via onboard potentiometer.
  • DO outputs LOW (LED on) when alcohol surpasses threshold.
  • DO outputs HIGH (LED off) when alcohol stays below threshold.

Analog Output (AO pin):

  • Voltage output proportional to alcohol concentration.
  • Increased alcohol = increased voltage output.
  • Decreased alcohol = decreased voltage output.
  • Note: Potentiometer affects only digital output, not analog readings.

Warm-up and Calibration

Pre-heating Requirements

The MQ3 requires heating before producing accurate measurements:

  • First use or long storage (30+ days): Maintain power for 24-48 hours for sensor stabilization and measurement accuracy.
  • Frequent use: A 5-10 minute warm-up suffices. Early readings may spike but will stabilize.

Simply connect VCC and GND to 5V power or your ESP32's power pins for the warm-up period.

Determining Threshold Values

Heater-based sensors like the MQ3 can drift during storage. Establish accurate breathalyzer thresholds through this calibration:

  1. Clean air baseline: Run sensor in fresh air and record analog values (typically 100-150).
  2. Alcohol exposure: Position isopropyl alcohol or hand sanitizer near (not touching) the sensor, allowing only vapors to reach it. Note the elevated readings (usually 400-900 depending on vapor strength).
  3. Establish ranges: Use recorded values to define zones:
  • Sober state: Below baseline + 20 (e.g., < 120)
  • Light consumption: Mid-range values (e.g., 120-400)
  • Heavy consumption: Above moderate threshold (e.g., > 400)

Critical: Sensor characteristics vary between units and environments. Always calibrate with your specific hardware before use.

Adjusting Digital Threshold

Set the DO pin trigger level using the trim potentiometer:

  1. Expose sensor to alcohol vapor.
  2. Turn potentiometer clockwise until LED activates.
  3. Turn counterclockwise slowly until LED just deactivates.
  4. Threshold is now calibrated.

Wiring Diagram

The MQ3 module offers both output pins. Use one or both depending on your project needs.

MQ3 Alcohol SensorESP32
VCC3.3V
GNDGND
DOGPIO 19
AOGPIO 36 (ADC0)
ESP32 and MQ3 alcohol sensor wiring diagram showing pin connections

This image is created using Fritzing. Click to enlarge image

If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: The best way to Power ESP32 and sensors/displays.

ESP32 Code - Digital Output Reading

/* * This ESP32 code is created by esp32io.com * * This ESP32 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-mq3-alcohol-sensor */ // Define the pin for digital output from the sensor #define PIN_DO 14 // ESP32 pin GPIO14 connected to DO pin of MQ3 sensor void setup() { // Initialize serial communication at 9600 baud rate Serial.begin(9600); // Set the DO pin as an input pinMode(PIN_DO, INPUT); // Give the MQ3 sensor time to warm up (20 seconds) Serial.println("Warming up the MQ3 sensor..."); delay(20000); // Wait 20 seconds for sensor warm-up Serial.println("MQ3 sensor is ready!"); } void loop() { // Read the digital output from the sensor int alcoholState = digitalRead(PIN_DO); // Check if alcohol is detected if (alcoholState == LOW) { Serial.println("Alcohol is detected"); } else { Serial.println("Alcohol is NOT detected"); } delay(1000); // Wait 1 second before next reading }

Quick Instructions

  • If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP32
  • Place alcohol vapor source near the MQ3 sensor (hand sanitizer or rubbing alcohol on cotton works well)
  • See the result on Serial Monitor
COM6
Send
Alcohol is NOT detected Alcohol is NOT detected Alcohol is NOT detected Alcohol is detected Alcohol is detected Alcohol is detected Alcohol is detected Alcohol is NOT detected Alcohol is NOT detected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Note: If readings don't align with reality (false triggers or missed detections), adjust the module's potentiometer. Clockwise increases sensitivity; counterclockwise decreases it. Fine-tune until accuracy improves.

ESP32 Code - Analog Output Reading

/* * This ESP32 code is created by esp32io.com * * This ESP32 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-mq3-alcohol-sensor */ // Define the pin for analog output from the sensor #define PIN_AO 36 // ESP32 pin GPIO36 (ADC0) connected to AO pin of MQ3 sensor void setup() { // Initialize serial communication at 9600 baud rate Serial.begin(9600); // Give the MQ3 sensor time to warm up (20 seconds) Serial.println("Warming up the MQ3 sensor..."); delay(20000); // Wait 20 seconds for sensor warm-up Serial.println("MQ3 sensor is ready!"); } void loop() { // Read the analog output from the sensor int alcoholValue = analogRead(PIN_AO); // Print the analog value to Serial Monitor Serial.print("MQ3 sensor AO value: "); Serial.println(alcoholValue); delay(1000); // Wait 1 second before next reading }

Quick Instructions

  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP32
  • Introduce alcohol vapor to the sensor (hand sanitizer or isopropyl alcohol)
  • Check out the result on the Serial Monitor
COM6
Send
MQ3 sensor AO value: 120 MQ3 sensor AO value: 125 MQ3 sensor AO value: 128 MQ3 sensor AO value: 450 MQ3 sensor AO value: 620 MQ3 sensor AO value: 850 MQ3 sensor AO value: 920 MQ3 sensor AO value: 980 MQ3 sensor AO value: 950 MQ3 sensor AO value: 680 MQ3 sensor AO value: 420
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

With either digital or analog output, you can implement threshold logic to trigger alarms, activate warning lights, or log data for breathalyzer applications.

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a sensor or component. The ESP32's ADC is suitable for projects that do not require high accuracy. However, for projects needing precise measurements, keep the following in mind:

  • The ESP32's ADC is not perfectly accurate and might require calibration for correct results. Each ESP32 board can vary slightly, so calibration is necessary for each individual board.
  • Calibration can be challenging, especially for beginners, and might not always yield the exact results you want.

For projects requiring high precision, consider using an external ADC (e.g ADS1115) with the ESP32 or using another Arduino, such as the Arduino Uno R4 WiFi, which has a more reliable ADC. If you still want to calibrate the ESP32's ADC, refer to the ESP32 ADC Calibration Driver.

ESP32 Code - Breathalyzer with Threshold Detection

This example shows how to interpret analog output through calibrated thresholds to estimate intoxication levels.

/* * This ESP32 code is created by esp32io.com * * This ESP32 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-mq3-alcohol-sensor */ // Define the pin for analog output from the sensor #define PIN_AO 36 // ESP32 pin GPIO36 (ADC0) connected to AO pin of MQ3 sensor // Define threshold values (calibrate these based on your sensor and environment) const int SOBER_THRESHOLD = 120; // Below this value = sober const int DRUNK_THRESHOLD = 400; // Above this value = drunk void setup() { // Initialize serial communication at 9600 baud rate Serial.begin(9600); // Give the MQ3 sensor time to warm up (20 seconds) Serial.println("Warming up the MQ3 sensor..."); delay(20000); // Wait 20 seconds for sensor warm-up Serial.println("MQ3 sensor is ready!"); Serial.println("=== Breathalyzer Test ==="); } void loop() { // Read the analog output from the sensor int alcoholValue = analogRead(PIN_AO); // Print the sensor value Serial.print("Sensor Value: "); Serial.print(alcoholValue); Serial.print(" | Status: "); // Determine intoxication level based on thresholds if (alcoholValue < SOBER_THRESHOLD) { Serial.println("Stone Cold Sober"); } else if (alcoholValue < DRUNK_THRESHOLD) { Serial.println("Drinking but within limits"); } else { Serial.println("DRUNK"); } delay(2000); // Wait 2 seconds before next reading }

Quick Instructions

  • Important: Calibrate your sensor first using the analog reading example to find proper threshold values for your setup.
  • Modify SOBER_THRESHOLD and DRUNK_THRESHOLD constants with your calibrated values.
  • Copy the modified code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP32
  • Test with alcohol vapor (isopropyl alcohol or hand sanitizer vapor)
  • Check status messages on Serial Monitor
COM6
Send
Sensor Value: 115 | Status: Stone Cold Sober Sensor Value: 118 | Status: Stone Cold Sober Sensor Value: 350 | Status: Drinking but within limits Sensor Value: 480 | Status: DRUNK Sensor Value: 520 | Status: DRUNK Sensor Value: 290 | Status: Drinking but within limits Sensor Value: 125 | Status: Stone Cold Sober
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Disclaimer: This project is for educational purposes only. Never use this device for legal breathalyzer purposes or driving safety assessments.

Video Tutorial

Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.

Function References

※ OUR MESSAGES