ESP32-Based Alcohol Detection System with Relay-Controlled Motor and Buzzer Alert
View and Edit Project In Cirkit Designer
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
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.
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.
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.
Buzzer
- Pins: PIN, GND
- Description: Emits sound when activated.
- Purpose in Circuit: Alerts when alcohol levels exceed a threshold.
LED: Two Pin (Red)
- Pins: Cathode, Anode
- Description: Red LED indicator.
- Purpose in Circuit: Indicates the motor is off.
LED: Two Pin (Green)
- Pins: Cathode, Anode
- Description: Green LED indicator.
- Purpose in Circuit: Indicates the motor is on.
Reed Switch
- Pins: Pin 1, Pin 2
- Description: Magnetic switch.
- Purpose in Circuit: Detects the presence of a magnetic field to control the relay.
Resistor (1000 Ohms)
- Pins: Pin1, Pin2
- Description: Limits current.
- Purpose in Circuit: Used in series with LEDs to limit current.
Resistor (200 Ohms)
- Pins: Pin1, Pin2
- Description: Limits current.
- Purpose in Circuit: Used in series with the MQ-3 sensor.
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
GND connected to:
- Resistor (1000 Ohms) Pin2
- Resistor (1000 Ohms) Pin2
- ESP32 GND
- ESP32 3V3
- Relay Module V-
- Buzzer GND
- DC Motor Pin 2
5V connected to:
- ESP32 VIN
- Resistor (200 Ohms) Pin1
- ESP32 GND
- Relay Module V+
SIG connected to:
- ESP32 VP
ESP32
VP connected to:
- MKE-S07 MQ-3 Alcohol Sensor SIG
D32 connected to:
- Reed Switch Pin 2
D25 connected to:
- Relay Module Trigger
D26 connected to:
- Buzzer PIN
D27 connected to:
- LED (Red) Anode
D14 connected to:
- LED (Green) Anode
GND connected to:
- MKE-S07 MQ-3 Alcohol Sensor GND
- Resistor (1000 Ohms) Pin2
- Resistor (1000 Ohms) Pin2
- ESP32 3V3
- Relay Module V-
- Buzzer GND
- DC Motor Pin 2
VIN connected to:
- MKE-S07 MQ-3 Alcohol Sensor 5V
- Resistor (200 Ohms) Pin1
- ESP32 GND
- Relay Module V+
Relay Module 5V-30V
V- connected to:
- ESP32 GND
- MKE-S07 MQ-3 Alcohol Sensor GND
- Resistor (1000 Ohms) Pin2
- Resistor (1000 Ohms) Pin2
- ESP32 3V3
- Buzzer GND
- DC Motor Pin 2
V+ connected to:
- ESP32 VIN
- MKE-S07 MQ-3 Alcohol Sensor 5V
- Resistor (200 Ohms) Pin1
- ESP32 GND
Trigger connected to:
- ESP32 D25
Normally Closed connected to:
- DC Motor Pin 1
Buzzer
PIN connected to:
- ESP32 D26
GND connected to:
- ESP32 GND
- MKE-S07 MQ-3 Alcohol Sensor GND
- Resistor (1000 Ohms) Pin2
- Resistor (1000 Ohms) Pin2
- ESP32 3V3
- Relay Module V-
- DC Motor Pin 2
LED: Two Pin (Red)
Anode connected to:
- ESP32 D27
Cathode connected to:
- Resistor (1000 Ohms) Pin1
LED: Two Pin (Green)
Anode connected to:
- ESP32 D14
Cathode connected to:
- Resistor (1000 Ohms) Pin1
Reed Switch
Pin 1 connected to:
- Resistor (200 Ohms) Pin2
Pin 2 connected to:
- ESP32 D32
Resistor (1000 Ohms)
Pin1 connected to:
- LED (Red) Cathode
Pin2 connected to:
- MKE-S07 MQ-3 Alcohol Sensor GND
- Resistor (1000 Ohms) Pin2
- ESP32 GND
- ESP32 3V3
- Relay Module V-
- Buzzer GND
- DC Motor Pin 2
Resistor (200 Ohms)
Pin1 connected to:
- MKE-S07 MQ-3 Alcohol Sensor 5V
- ESP32 VIN
- ESP32 GND
- Relay Module V+
Pin2 connected to:
- Reed Switch Pin 1
DC Motor
Pin 1 connected to:
- Relay Module Normally Closed
Pin 2 connected to:
- ESP32 GND
- MKE-S07 MQ-3 Alcohol Sensor GND
- Resistor (1000 Ohms) Pin2
- Resistor (1000 Ohms) Pin2
- ESP32 3V3
- Relay Module V-
- Buzzer GND
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) {