ESP8266 - MQ3 Alcohol Sensor

This tutorial explains how to interface ESP8266 with the MQ3 alcohol sensor for measuring ethanol and alcohol vapor in the environment. The MQ3 sensor proves valuable in breath testing devices, alcohol detection alarms, and air quality monitoring applications.

In this guide, we will cover:

ESP8266 NodeMCU with MQ3 alcohol gas sensor module

Hardware Preparation

1×ESP8266 NodeMCU
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×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for ESP8266
1×Recommended: Power Splitter for ESP8266 Type-C

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of MQ3 Alcohol Sensor

Designed as a Metal Oxide Semiconductor (MOS) Chemiresistor, the MQ3 senses alcohol via resistance shifts within its active material. This sensor specializes in ethanol vapor detection with dependable sensitivity throughout its measurement range.

Its sensing component features a Tin Dioxide (SnO2) layer on an Aluminum Oxide ceramic foundation. Heating activates the SnO2 to respond to airborne alcohol molecules. A protective stainless steel mesh surrounds the element, shielding it while permitting gas access to the detection zone.

Common implementations include DIY breathalyzer construction, impairment detection systems, alcohol vapor warning devices, and atmospheric alcohol measurement.

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

What is ppm? The ppm (parts-per-million) measurement indicates concentration ratio. With 500 ppm, you have 500 alcohol molecules per 1,000,000 total gas molecules, the remaining 999,500 being atmospheric gases.

Pinout

Four pins are present on the MQ3 sensor module:

  • VCC pin: Supply +5V power here.
  • GND pin: Connect to ground (0V).
  • DO pin: Digital output goes LOW when alcohol exceeds threshold, HIGH when below. Adjust threshold with onboard potentiometer.
  • AO pin: Analog output voltage scales with alcohol concentration. Higher alcohol yields higher voltage.
MQ3 alcohol sensor module pinout diagram

Two indicator LEDs provide visual feedback:

  • PWR-LED: Illuminates when module has power.
  • DO-LED: Reflects digital output—lights during detection, dark otherwise.

How It Works

The MQ3's sensing mechanism depends on Tin Dioxide (SnO2) resistance variation:

In uncontaminated air: The heated SnO2 binds oxygen molecules to its surface, capturing electrons in a depletion layer. These captured electrons establish a conduction barrier, producing high resistance.

With alcohol present: Alcohol molecules interact with surface oxygen, releasing captured electrons into the tin dioxide matrix. Released electrons enhance conductivity—greater alcohol means reduced resistance.

Two output modes are provided:

Digital Output (DO pin):

  • Onboard potentiometer sets the threshold level.
  • Alcohol above threshold drives DO to LOW and activates LED.
  • Alcohol below threshold maintains DO at HIGH with LED off.

Analog Output (AO pin):

  • Output voltage tracks alcohol concentration.
  • Increased alcohol = elevated voltage.
  • Decreased alcohol = reduced voltage.
  • Note: Potentiometer affects only digital threshold, not analog voltage.

Warm-up and Calibration

Pre-heating Requirements

Proper MQ3 sensor operation requires adequate heating:

  • First deployment or extended storage (30+ days): Maintain continuous heating for 24-48 hours to stabilize the sensor for accurate measurements.
  • Regular usage: A quick 5-10 minute warm-up suffices. Early readings may be elevated but will normalize rapidly.

Warm the sensor by connecting VCC and GND to 5V and ground—use either a power supply or ESP8266's power pins.

Finding Your Threshold Values

Heated sensors like the MQ3 may drift during storage. For breathalyzer uses, establish thresholds through this calibration procedure:

  1. Record baseline in clean air: Operate sensor in fresh air and record analog output (typically 100-150).
  2. Introduce alcohol vapor: Position isopropyl alcohol or hand sanitizer near (without contacting) the sensor, allowing vapor to reach it. Note elevated readings (commonly 400-900 depending on vapor density).
  3. Establish detection ranges: From your measurements, define threshold zones:
  • No alcohol present: Below baseline + 20 (example: < 120)
  • Moderate alcohol: Mid-range values (example: 120-400)
  • High alcohol: Above moderate range (example: > 400)

Critical: Individual sensors and environments yield different values. Always calibrate your specific hardware before implementation.

Setting the Digital Threshold

Adjust DO pin trigger level using the module's potentiometer:

  1. Expose sensor to alcohol vapor.
  2. Turn potentiometer clockwise until LED activates.
  3. Slowly rotate counterclockwise until LED just deactivates.
  4. Threshold is configured.

Wiring Diagram

Since the MQ3 alcohol sensor module has two outputs, you can choose to use one or both of them, depending on what you need.

The wiring diagram between ESP8266 NodeMCU and MQ3 alcohol sensor

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

ESP8266 Code - Digital Output Reading

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ /* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ #define PIN_DO D7 // The ESP8266 pin D7 connected to the DO pin of the MQ3 sensor void setup() { // Initialize serial communication Serial.begin(9600); // Initialize the ESP8266 pin as an input pinMode(PIN_DO, INPUT); // Warm-up message Serial.println("Warming up the MQ3 sensor"); delay(20000); // 20 seconds warm-up time for recently used sensor } void loop() { int gasState = digitalRead(PIN_DO); if (gasState == HIGH) { Serial.println("Alcohol is NOT detected"); } else { Serial.println("Alcohol is detected"); } delay(1000); }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP8266
  • Place an alcohol vapor source near the MQ3 sensor (hand sanitizer or rubbing alcohol on cotton works well)
  • Check out the result on the 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  

Please keep in mind that if you notice the LED status remaining on constantly or off, you can adjust the potentiometer to fine-tune the sensitivity of the sensor.

ESP8266 Code - Analog Output Reading

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ /* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ #define PIN_AO A0 // The ESP8266 pin connected to the AO pin of the MQ3 sensor void setup() { // Initialize serial communication Serial.begin(9600); // Warm-up message Serial.println("Warming up the MQ3 sensor"); delay(20000); // 20 seconds warm-up time for recently used sensor } void loop() { int gasValue = analogRead(PIN_AO); Serial.print("MQ3 sensor AO value: "); Serial.println(gasValue); delay(1000); }

Detailed Instructions

  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP8266
  • Introduce alcohol vapor to the sensor (hand sanitizer or isopropyl alcohol vapors)
  • 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  

From values read from DO or AO, you can build threshold-based logic to trigger alarms, control warning indicators, or log data for breathalyzer functionality.

ESP8266 Code - Breathalyzer with Threshold Detection

This example demonstrates using analog output with calibrated thresholds to estimate intoxication levels.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ /* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-mq3-alcohol-sensor */ #define PIN_AO A0 // The ESP8266 pin connected to the AO pin of the MQ3 sensor // Threshold values - REPLACE THESE with your calibrated values! // Run calibration first to find these values for your sensor #define SOBER_THRESHOLD 120 // Below this = sober #define DRUNK_THRESHOLD 400 // Above this = drunk, between = drinking but within limits void setup() { // Initialize serial communication Serial.begin(9600); // Warm-up message Serial.println("MQ3 Alcohol Sensor - Breathalyzer"); Serial.println("Warming up sensor..."); delay(20000); // 20 second warm-up for recently used sensor Serial.println("Sensor ready!"); Serial.println(); } void loop() { int gasLevel = analogRead(PIN_AO); // Read the analog value from sensor // Print sensor value Serial.print("Sensor Value: "); Serial.print(gasLevel); Serial.print(" | Status: "); // Determine status based on thresholds if (gasLevel < SOBER_THRESHOLD) { Serial.println("Stone Cold Sober"); } else if (gasLevel >= SOBER_THRESHOLD && gasLevel < DRUNK_THRESHOLD) { Serial.println("Drinking but within limits"); } else { Serial.println("DRUNK"); } delay(1000); // Wait 1 second between readings }

Detailed Instructions

  • Critical: First calibrate your sensor using the analog reading example to determine appropriate threshold values for your environment.
  • Update SOBER_THRESHOLD and DRUNK_THRESHOLD constants in the code with your calibrated numbers.
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP8266
  • Test with alcohol vapor (isopropyl alcohol or hand sanitizer vapor)
  • Check out the result on the 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 serves educational purposes exclusively. Never rely on this device for legal breathalyzer functions or driving safety assessments.

※ NOTE THAT:

This tutorial uses the analogRead() function to get data from an ADC (Analog-to-Digital Converter) that's connected to a sensor or another part. The ESP8266's ADC works well for projects where you don't need very precise readings. But remember, the ESP8266's ADC isn't very accurate for detailed measurements. If your project needs to be very precise, you might want to use a separate ADC like the ADS1115 with the ESP8266, or use Arduino like the Arduino Uno R4 WiFi, which has a more reliable ADC.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!