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.
MQ-3 Breakout
Buzzer
ESP32
/*
* 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.