// Pin Definitions
const int sensorPin = 13; // MQ sensor data input
const int defaultLed = 3; // Standard LED (Always on initially)
const int buzzerPin = 2; // Buzzer for alert
const int alarmLed = 4; // Yellow LED for alert
void setup() {
// Initialize Pin Modes
pinMode(sensorPin, INPUT);
pinMode(defaultLed, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(alarmLed, OUTPUT);
// Initial State: Default LED on, others off
digitalWrite(defaultLed, HIGH);
digitalWrite(buzzerPin, LOW);
digitalWrite(alarmLed, LOW);
Serial.begin(9600); // For monitoring status
}
void loop() {
// Read the sensor state (HIGH if alcohol detected, LOW otherwise)
int sensorStatus = digitalRead(sensorPin);
if (sensorStatus == HIGH) {
// Alcohol Detected!
digitalWrite(defaultLed, LOW); // Turn off default LED
digitalWrite(buzzerPin, HIGH); // Activate Buzzer
digitalWrite(alarmLed, HIGH); // Turn on Yellow LED
Serial.println("Warning: Alcohol Detected!");
}
else {
// No Alcohol Detected
digitalWrite(defaultLed, HIGH); // Keep default LED on
digitalWrite(buzzerPin, LOW); // Silence Buzzer
digitalWrite(alarmLed, LOW); // Turn off Yellow LED
Serial.println("Status: Clear");
}
delay(100); // Small delay for stability
}