Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Alcohol Detection System with Relay-Controlled Motor and Buzzer Alert

View and Edit Project In Cirkit DesignerImage of ESP32-Based Alcohol Detection System with Relay-Controlled Motor and Buzzer Alert

Circuit Documentation

Summary

This circuit is designed to monitor alcohol levels using an MQ-3 Alcohol Sensor and control a relay module to start or stop a DC motor based on the state of a Reed Switch. Additionally, it uses LEDs to indicate the status and a buzzer to alert when alcohol levels exceed a certain threshold. The ESP32 microcontroller is used to read sensor data and control the output devices.

Component List

  1. MKE-S07 MQ-3 Alcohol Sensor

    • Pins: GND, 5V, SIG
    • Description: Detects alcohol levels in the air.
    • Purpose in Circuit: Provides an analog signal proportional to the alcohol concentration.
  2. ESP32

    • 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
    • Description: Microcontroller with Wi-Fi and Bluetooth capabilities.
    • Purpose in Circuit: Reads sensor data and controls the relay, LEDs, and buzzer.
  3. Relay Module 5V-30V

    • Pins: Common contact, Normally open, Normally closed, Trigger, V-, V+
    • Description: Controls high-power devices.
    • Purpose in Circuit: Starts or stops the DC motor based on the Reed Switch state.
  4. Buzzer

    • Pins: PIN, GND
    • Description: Emits sound when activated.
    • Purpose in Circuit: Alerts when alcohol levels exceed a threshold.
  5. LED: Two Pin (Red)

    • Pins: Cathode, Anode
    • Description: Red LED indicator.
    • Purpose in Circuit: Indicates the motor is off.
  6. LED: Two Pin (Green)

    • Pins: Cathode, Anode
    • Description: Green LED indicator.
    • Purpose in Circuit: Indicates the motor is on.
  7. Reed Switch

    • Pins: Pin 1, Pin 2
    • Description: Magnetic switch.
    • Purpose in Circuit: Detects the presence of a magnetic field to control the relay.
  8. Resistor (1000 Ohms)

    • Pins: Pin1, Pin2
    • Description: Limits current.
    • Purpose in Circuit: Used in series with LEDs to limit current.
  9. Resistor (200 Ohms)

    • Pins: Pin1, Pin2
    • Description: Limits current.
    • Purpose in Circuit: Used in series with the MQ-3 sensor.
  10. DC Motor

    • Pins: Pin 1, Pin 2
    • Description: Converts electrical energy into mechanical motion.
    • Purpose in Circuit: Controlled by the relay to start or stop based on the Reed Switch state.

Wiring Details

MKE-S07 MQ-3 Alcohol Sensor

ESP32

Relay Module 5V-30V

Buzzer

LED: Two Pin (Red)

LED: Two Pin (Green)

Reed Switch

Resistor (1000 Ohms)

Resistor (200 Ohms)

DC Motor

Code Documentation

// Define pin connections
#define RELAY_PIN 25
#define REED_SWITCH_PIN 32
#define BUZZER_PIN 26
#define RED_LED_PIN 27
#define GREEN_LED_PIN 14
#define ALCOHOL_SENSOR_PIN 36 // VP pin

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize pins
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(REED_SWITCH_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(ALCOHOL_SENSOR_PIN, INPUT);

  // Initial state
  digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off initially
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(GREEN_LED_PIN, LOW);
}

void loop() {
  // Read the state of the Reed Switch
  int reedSwitchState = digitalRead(REED_SWITCH_PIN);

  // Read the value from the alcohol sensor
  int alcoholSensorValue = analogRead(ALCOHOL_SENSOR_PIN);

  // Print the sensor values to the serial monitor
  Serial.print("Reed Switch State: ");
  Serial.println(reedSwitchState);
  Serial.print("Alcohol Sensor Value: ");
  Serial.println(alcoholSensorValue);

  // Control the relay based on the Reed Switch state
  if (reedSwitchState == HIGH) {