Arduino Nano ESP32 - MQ3 Alcohol Sensor

This tutorial guides you through using Arduino Nano ESP32 with the MQ3 alcohol sensor to detect and measure ethanol and alcohol vapor concentrations. The MQ3 sensor is ideal for building breath analyzer systems, alcohol vapor alarms, and air quality assessment tools.

In this tutorial, you will learn:

Arduino Nano ESP32 with MQ3 alcohol gas sensor module

Hardware Preparation

1×Arduino Nano ESP32
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 Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano ESP32

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

The MQ3 is a Metal Oxide Semiconductor (MOS) Chemiresistor that detects alcohol presence by monitoring resistance variations within its sensing element. This sensor specializes in ethanol vapor detection, providing consistent performance across a wide concentration spectrum.

The sensor's active component features a Tin Dioxide (SnO2) layer applied to an Aluminum Oxide ceramic substrate. Heat activation makes the SnO2 material reactive to surrounding alcohol molecules. A stainless steel protective mesh encases the sensor, safeguarding internal components while enabling gas molecules to access the detection chamber.

Typical applications include homemade breathalyzer systems, impaired driving detection devices, alcohol vapor warning systems, and environmental alcohol monitoring stations.

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 term ppm (parts-per-million) expresses the concentration ratio of target gas molecules to total molecules. For example, 500 ppm indicates 500 alcohol molecules exist within every 1,000,000 gas molecules, with the remaining 999,500 being other atmospheric components.

Pinout

The MQ3 sensor module provides four connection terminals:

  • VCC pin: Connect to +5V power source.
  • GND pin: Connect to ground (0V).
  • DO pin: Digital output switches to LOW when alcohol surpasses the threshold, or HIGH when below. The threshold is adjustable via the onboard potentiometer.
  • AO pin: Analog output provides voltage proportional to alcohol concentration. More alcohol creates higher voltage output.
MQ3 alcohol sensor module pinout diagram

Two LED indicators offer visual status:

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

How It Works

The MQ3's detection principle relies on resistance variations in its Tin Dioxide (SnO2) semiconductor:

In clean air: Heating causes oxygen molecules to adhere to the SnO2 surface, trapping electrons and forming a depletion layer. These trapped electrons create a conduction barrier, resulting in high electrical resistance.

During alcohol exposure: Alcohol molecules interact with surface oxygen, breaking bonds and releasing trapped electrons into the tin dioxide lattice. This electron release dramatically increases conductivity—greater alcohol concentrations produce lower resistance values.

The sensor offers two output modes:

Digital Output (DO pin):

  • An onboard trim potentiometer controls the detection threshold.
  • Alcohol detection above the threshold sets DO to LOW and activates the LED indicator.
  • Detection below the threshold keeps DO at HIGH with the LED off.

Analog Output (AO pin):

  • Voltage varies directly with alcohol concentration.
  • Increased alcohol vapor = elevated voltage output.
  • Decreased alcohol vapor = reduced voltage output.
  • Note: The trim potentiometer affects only digital threshold, not analog output.

Warm-up and Calibration

Pre-heating Requirements

The MQ3 sensor needs proper heating for reliable measurements:

  • Initial deployment or prolonged storage (30+ days): Maintain continuous heating for 24-48 hours to stabilize the sensor and ensure measurement accuracy.
  • Recent use: A brief 5-10 minute warm-up is sufficient. Initial values may appear high but will normalize quickly.

To warm the sensor, connect VCC and GND to 5V and ground—either through a dedicated power supply or directly to your Arduino Nano ESP32's power pins.

Finding Your Threshold Values

Gas sensors with heating elements like the MQ3 can experience calibration drift after storage. For breathalyzer projects, establish proper threshold values through this calibration sequence:

  1. Measure clean air baseline: Run the sensor in fresh air without alcohol present. Record the analog value (typically 100-150).
  2. Test with alcohol vapor: Position isopropyl alcohol or hand sanitizer near (not touching) the sensor, allowing vapor to reach the detector. Record the increased readings (commonly 400-900 based on vapor concentration).
  3. Define detection thresholds: Using your recorded data, establish detection zones:
  • Sober range: Values below baseline + 20 (example: < 120)
  • Moderate range: Mid-range values (example: 120-400)
  • High range: Values exceeding moderate limit (example: > 400)

Important: Individual sensor units and environmental conditions produce varying values. Always calibrate using your specific hardware before deployment.

Setting the Digital Threshold

Configure the DO pin's activation point using the module's potentiometer:

  1. Expose the sensor to alcohol vapor.
  2. Rotate the potentiometer clockwise until the LED activates.
  3. Gradually turn counterclockwise until the LED just deactivates.
  4. The digital threshold is now calibrated.

Wiring Diagram

The MQ3 module offers both digital and analog outputs. Select either output or use both concurrently based on your application requirements.

  • The wiring diagram between Arduino Nano ESP32 and the MQ3 alcohol sensor when powering via USB port.
The wiring diagram between Arduino Nano ESP32 and MQ3 alcohol sensor

This image is created using Fritzing. Click to enlarge image

MQ3 Alcohol SensorArduino Nano ESP32
VCC5V
GNDGND
DOD2
AOA5
  • The wiring diagram between Arduino Nano ESP32 and the MQ3 alcohol sensor when powering via Vin pin.
The wiring diagram between Arduino Nano ESP32 and alcohol detector

This image is created using Fritzing. Click to enlarge image

Arduino Nano ESP32 Code - Digital Output Reading

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-mq3-alcohol-sensor */ #define PIN_DO D2 // The Arduino Nano ESP32's pin connected to the DO pin of the MQ3 sensor void setup() { // Initialize serial communication Serial.begin(9600); // Initialize the Arduino Nano ESP32's 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

  • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
  • Copy the code above into Arduino IDE
  • Click the Upload button to program Arduino Nano ESP32
  • Bring an alcohol vapor source near the MQ3 sensor (hand sanitizer or rubbing alcohol on cotton works well)
  • View the detection results in 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  

Keep in mind that if the LED status stays constantly on or off, adjust the potentiometer to fine-tune the sensor's sensitivity for accurate detection.

Arduino Nano ESP32 Code - Analog Output Reading

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-mq3-alcohol-sensor */ #define PIN_AO A5 // The Arduino Nano ESP32's pin connected to the AO pin of the MQ3 sensor void setup() { // Initialize serial communication Serial.begin(9600); // Set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); // 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 code above into Arduino IDE
  • Click the Upload button to program Arduino Nano ESP32
  • Introduce alcohol vapor to the sensor (hand sanitizer or isopropyl alcohol vapors)
  • Monitor the values in 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  

Using either digital or analog outputs, you can create threshold-based logic to trigger alarms, control warning indicators, or capture data for breathalyzer applications.

Arduino Nano ESP32 Code - Breathalyzer with Threshold Detection

This code demonstrates interpreting analog output through calibrated thresholds to assess alcohol consumption levels.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-mq3-alcohol-sensor */ #define PIN_AO A5 // The Arduino Nano ESP32's 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); // Set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); // 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

  • Essential: First calibrate your specific sensor using the analog reading example to find appropriate threshold values.
  • Replace the SOBER_THRESHOLD and DRUNK_THRESHOLD constants in the code with your calibrated values.
  • Upload the modified code to Arduino Nano ESP32
  • Test by exposing to alcohol vapor (isopropyl alcohol or hand sanitizer vapor)
  • Observe the status messages in 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 is strictly an educational project. Never use this device as a legal breathalyzer or for assessing driving safety.

※ 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 Arduino Nano 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 Arduino Nano ESP32's ADC is not perfectly accurate and might require calibration for correct results. Each Arduino Nano 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 Arduino Nano 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 Arduino Nano ESP32's ADC, refer to the ESP32 ADC Calibration Driver.

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!