AlcoAlert

AlcoAlert is a compact system that detects high alcohol levels using an MQ-3 sensor and alerts users with a buzzer and flashing 'Danger!!'

BeginnerShowcase (no instructions)100
AlcoAlert

Things used in this project

Hardware components

Male/Female Jumper Wires
Male/Female Jumper Wires
×1
LED Dot Matrix Display, Red
LED Dot Matrix Display, Red
×1
Seeed Studio XIAO ESP32S3 Plus
Seeed Studio XIAO ESP32S3 Plus
×1
Passive Buzzer
×1
Breadboard
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

AlcoAlert Schematic

Code

alcoalert.ino

Arduino
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// --- MAX7219 Display Configuration ---
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN   5
#define DATA_PIN  3
#define CS_PIN    4

// --- MQ-3 Sensor Configuration ---
#define MQ3_SENSOR_PIN 1  // Analog-capable pin

// --- Active Buzzer Configuration ---
#define BUZZER_PIN 6

// Display object
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Flashing timing for danger alert
const unsigned long buzzerOnTime = 200;
const unsigned long buzzerOffTime = 300;
unsigned long lastFlashTime = 0;
bool flashState = false;

// Low alert flag
bool lowBeepPlayed = false;

void setup() {
  Serial.begin(115200);
  Serial.println("--- MQ-3 Alcohol Sensor Display ---");

  P.begin();
  P.setIntensity(5);
  P.displayClear();
  P.setTextAlignment(PA_CENTER);
  P.setSpeed(50);

  analogReadResolution(12);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  int rawValue = analogRead(MQ3_SENSOR_PIN);
  Serial.print("MQ-3 Raw Value: ");
  Serial.println(rawValue);

  unsigned long now = millis();

  if (rawValue > 3000) {
    // High alcohol level - Danger!!
    unsigned long interval = flashState ? buzzerOnTime : buzzerOffTime;

    if (now - lastFlashTime >= interval) {
      flashState = !flashState;
      lastFlashTime = now;

      digitalWrite(BUZZER_PIN, flashState ? HIGH : LOW);
      P.displayClear();
      if (flashState) {
        P.displayText("Danger!", PA_CENTER, P.getSpeed(), 0, PA_PRINT, PA_NO_EFFECT);
      }
    }

    lowBeepPlayed = false;  // Reset one-time beep flag
    P.displayAnimate();

  } else if (rawValue > 2000) {
    // Low alcohol level
    digitalWrite(BUZZER_PIN, LOW);
    flashState = false;
    lastFlashTime = now;

    if (!lowBeepPlayed) {
      digitalWrite(BUZZER_PIN, HIGH);
      delay(200);  // Short beep
      digitalWrite(BUZZER_PIN, LOW);
      lowBeepPlayed = true;
    }

    if (P.displayAnimate()) {
      P.displayText("Warning", PA_CENTER, P.getSpeed(), 0, PA_NO_EFFECT, PA_NO_EFFECT);
    }

  } else {
    // Clean air
    digitalWrite(BUZZER_PIN, LOW);
    flashState = false;
    lowBeepPlayed = false;
    lastFlashTime = now;

    if (P.displayAnimate()) {
      P.displayText("Clean", PA_CENTER, P.getSpeed(), 0, PA_NO_EFFECT, PA_NO_EFFECT);
    }
  }

  delay(10);  // Stability
}

Credits

Aditya Dwi Kurniawan
1 project • 0 followers
Muhammad Ryan Alim Fasah 76644
1 project • 0 followers
Wildan Syahid Al Farisi 90227
1 project • 0 followers
Sodaqo Wadah 69712
1 project • 0 followers
Hendra Kusumah
49 projects • 163 followers
Love hacking and making new things from IoT to robotics

Comments