Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32 Alcohol Detection System with MQ-3 Sensor and Buzzer

Image of ESP32 Alcohol Detection System with MQ-3 Sensor and Buzzer

Circuit Documentation

Summary

This circuit is designed to detect the presence of alcohol using an MQ-3 alcohol sensor and trigger a buzzer when alcohol is detected. The circuit is controlled by an ESP32 microcontroller, which reads the digital output from the MQ-3 sensor and activates the buzzer accordingly.

Component List

  1. MQ-3 Breakout

    • Description: Alcohol sensor module
    • Pins: VCC, GND, DO, AO
  2. Buzzer

    • Description: Piezoelectric buzzer
    • Pins: PIN, GND
  3. ESP32

    • Description: Microcontroller with Wi-Fi and Bluetooth capabilities
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT

Wiring Details

MQ-3 Breakout

  • VCC connected to ESP32 3V3
  • GND connected to ESP32 GND
  • DO connected to ESP32 D13

Buzzer

  • PIN connected to ESP32 D12
  • GND connected to ESP32 GND

ESP32

  • 3V3 connected to MQ-3 Breakout VCC
  • GND connected to MQ-3 Breakout GND and Buzzer GND
  • D13 connected to MQ-3 Breakout DO
  • D12 connected to Buzzer PIN

Code Documentation

/*
 * This Arduino Sketch is for an ESP32 microcontroller connected to an MQ-3
 * alcohol sensor and a buzzer. The code reads the digital output (DO) from
 * the MQ-3 sensor to detect the presence of alcohol. If alcohol is detected,
 * the buzzer is activated.
 */

// Pin definitions
const int mq3DO = 13; // MQ-3 digital output connected to ESP32 pin D13
const int buzzerPin = 12; // Buzzer connected to ESP32 pin D12

void setup() {
  // Initialize the digital pin as an input for MQ-3 DO
  pinMode(mq3DO, INPUT);
  // Initialize the digital pin as an output for the buzzer
  pinMode(buzzerPin, OUTPUT);
  // Ensure the buzzer is off initially
  digitalWrite(buzzerPin, LOW);
}

void loop() {
  // Read the digital output from the MQ-3 sensor
  int alcoholDetected = digitalRead(mq3DO);
  // If alcohol is detected, turn on the buzzer
  if (alcoholDetected == HIGH) {
    digitalWrite(buzzerPin, HIGH);
  } else {
    // Otherwise, turn off the buzzer
    digitalWrite(buzzerPin, LOW);
  }
  // Small delay to avoid rapid toggling
  delay(100);
}

This code initializes the pins connected to the MQ-3 sensor and the buzzer. In the loop function, it continuously reads the digital output from the MQ-3 sensor. If alcohol is detected, the buzzer is turned on; otherwise, it remains off. A small delay is added to avoid rapid toggling of the buzzer.