Skip to content

Avadhut2/AwakeGuard

Repository files navigation

πŸ’€ AWAKE GUARD – AI Powered Driver Drowsiness Detection & Smart Alert System

πŸš— Real-time Driver Safety Powered by AI, IoT, and Machine Learning


πŸ“‘ Table of Contents


πŸ“˜ Overview

Awake Guard is an advanced AI + IoT-based driver safety system designed to detect driver drowsiness in real-time.
It uses Computer Vision, Dlib facial landmark detection, and ESP32 IoT integration to automatically detect fatigue and prevent accidents.

When the driver becomes drowsy:

  • 🚨 The system triggers a buzzer via ESP32
  • πŸ“Έ Captures the driver’s photo
  • πŸ“© Sends an alert with location + timestamp to a Telegram Bot
  • ☁️ Saves all alert data (time, date, location, image) to Supabase
  • πŸ’» Displays it on a web dashboard

🧠 Tech Stack

Component Technology
Programming Language Python 3.x
AI/ML Libraries OpenCV, Dlib, Imutils, Scipy
Backend Flask (Python)
Database Supabase
IoT Hardware ESP32
Frontend Dashboard HTML, CSS, JavaScript
APIs Used Telegram Bot API, Google Geolocation API
Environment Python Virtual Environment (venv)

πŸ—‚οΈ Project Structure

AwakeGuard/
β”‚
β”œβ”€β”€ esp32/                                # ESP32-related files
β”‚ └── ESP32 sketch files
β”œβ”€β”€ frontend/                             # Frontend for dashboard/UI
β”‚ └── (HTML, CSS, JS files)
β”‚
β”œβ”€β”€ .env                                  # Git ignore file
β”‚
β”œβ”€β”€ alert_handler.py                      # Handles alert queue & saves alerts
β”œβ”€β”€ api.py                                # API endpoints for communication
β”œβ”€β”€ database_handler.py                   # Database interaction logic
β”œβ”€β”€ db_config.py                          # Database credentials/config
β”œβ”€β”€ drowsiness_detector.py                # Core ML/AI detection logic
β”œβ”€β”€ main.py                               # Main entry point (AI + alert system)
β”œβ”€β”€ main_webcam.py                        # Webcam control and testing
β”œβ”€β”€ telegram_alert.py                     # Sends alerts via Telegram bot
β”œβ”€β”€ shape_predictor_68_face_landmarks.dat # Model for facial landmark detection
β”‚
β”œβ”€β”€ requirements.txt                      # Python dependencies
β”œβ”€β”€ README.md                             # Project documentation
β”‚
└── captures/                             # Captured frames/images during detection


βš™οΈ Hardware Requirements

Component Quantity Description
ESP32 / ESP32-CAM 1 IoT microcontroller
Buzzer 1 Alert signal
Webcam 1 Drowsiness detection
Laptop / PC 1 Runs Python scripts
Internet 1 For APIs and Telegram alerts

🧰 Software Requirements

  • Python 3.8+
  • Arduino IDE
  • Git
  • Supabase account
  • Telegram Bot (via BotFather)

πŸ”‘ Environment Setup

1️⃣ Clone Repository

git clone https://github.com/Avadhut2/AwakeGuard.git

cd AwakeGuard

2️⃣ Create and Activate Virtual Environment

python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

3️⃣ Install Requirements

pip install -r requirements.txt

4️⃣ Create .env File

Create a .env in the root folder with:

ESP32_IP=http://192.168.168.254/buzz
ESP32_CAM_URL=http://YOUR_LOCAL_IP:4747/video
BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN
CHAT_ID=YOUR_TELEGRAM_CHAT_ID
PG_HOST=db.yourprojectid.supabase.co
PG_PORT=5432
PG_DB=postgres
PG_USER=postgres
PG_PASSWORD=YOUR_DB_PASSWORD
PG_SSLMODE=require
DATABASE_URL=postgresql://postgres:YOUR_DB_PASSWORD@db.yourprojectid.supabase.co:5432/postgres?sslmode=require
SUPABASE_URL=https://yourprojectid.supabase.co
SUPABASE_KEY=YOUR_SUPABASE_SERVICE_KEY

🧠 How It Works

  1. Face Detection & Eye Aspect Ratio (EAR)

    • The system uses Dlib’s facial landmarks to calculate the EAR.
    • If the EAR drops below a threshold for a few consecutive frames, the driver is considered drowsy.
  2. Trigger IoT Alert

    • Sends a request to the ESP32 endpoint to activate the buzzer.
  3. Capture Evidence

    • Captures the driver’s image frame.
  4. Send Telegram Alert

    • Sends photo, time, and GPS location to Telegram via bot.
  5. Store Alert Data

    • Saves all alert info (time, location, image path) into Supabase.
  6. Dashboard Monitoring

    • The dashboard fetches data from Supabase and displays alert logs in real time.

⚑ Wiring Diagram

Below is the correct wiring for flashing your ESP32-CAM using a TTL-to-USB module.

ESP32-CAM Wiring

ESP32-CAM Pin TTL Module Pin
5V 5V
GND GND
U0R (RX) TX
U0T (TX) RX
IO0 β†’ GND Flash Mode

πŸ”Έ Connect IO0 to GND only while flashing. Remove it after uploading the code.


πŸ’» Flashing ESP32-CAM via TTL to USB

  1. Connect ESP32-CAM and TTL adapter as per the wiring above.
  2. Hold IO0 β†’ GND for flash mode.
  3. Open Arduino IDE or esptool.
  4. Select:
    • Board: ESP32 Wrover Module
    • Flash Size: 4MB
    • Upload Speed: 115200
  5. Choose the correct COM port.
  6. Click Upload.
  7. Once done, disconnect IO0 from GND and press the RST button.
  8. The ESP32-CAM should start running your code πŸŽ‰.

πŸš€ Running the Project

1️⃣ Start ESP32

  1. Open Arduino IDE
  2. Install ESP32 board support (via Preferences β†’ Additional Board Manager URLs)
  3. Open esp32/awake_guard.ino
  4. Update Wi-Fi credentials:
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
  1. Connect ESP32 to your PC and select correct COM port.
  2. Click Upload.

2️⃣ Run Python Detection Script

python main.py

βœ… Output Example:

Frame 128: 1 face(s) detected
Drowsiness detected!
🚨 DROWSINESS ALERT TRIGGERED!
πŸ“Έ Image captured and sent to Telegram!
πŸ“ Location saved to Supabase!

3️⃣ Run Dashboard

  1. Navigate to /dashboard
  2. Open login.html in a browser
  3. Login using your Supabase credentials
  4. View all alerts with time, date, location, and driver photo

Tip: Host Website on https://www.netlify.com


⚑ Troubleshooting

Issue Solution
ESP32 not connecting Check COM port and baud rate
Dlib install error Use prebuilt wheels: pip install cmake dlib
Telegram not receiving alert Verify bot token and chat ID
No image captured Ensure webcam is accessible (cv2.VideoCapture(0))
Supabase error Check URL & API key in .env

πŸ§‘β€πŸ’» Contributors

Name Role
Avadhut Satpute IOT, Backend, Database, Testing
Komal Sabarad Frontend, Dashboard, API's
Swayam Patil Frontend, Dashboard, API's
Rajvardhan Varpe Telegram Integration

⭐ If you find this project useful, please star this repository to support future development!

About

A smart IoT-based Driver Drowsiness Detection System built using ESP32-CAM, AI, and Supabase, capable of image capture, and Telegram alerts with integrated cloud dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors