- 📘 Overview
- 🧠 Tech Stack
- 🗂️ Project Structure
- 💾 Shape Predictor
- ⚙️ Hardware Requirements
- 🧰 Software Requirements
- 🔑 Environment Setup
- 🧠 How It Works
- ⚡ Wiring Diagram
- 💻 Flashing ESP32-CAM via TTL to USB
- 🚀 Running the Project
- ⚡ Troubleshooting
- 🧑💻 Contributors
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
| 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) |
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
| 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 |
- Python 3.8+
- Arduino IDE
- Git
- Supabase account
- Telegram Bot (via BotFather)
git clone https://github.com/Avadhut2/AwakeGuard.git
cd AwakeGuard
python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
pip install -r requirements.txt
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
-
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.
-
Trigger IoT Alert
- Sends a request to the ESP32 endpoint to activate the buzzer.
-
Capture Evidence
- Captures the driver’s image frame.
-
Send Telegram Alert
- Sends photo, time, and GPS location to Telegram via bot.
-
Store Alert Data
- Saves all alert info (time, location, image path) into Supabase.
-
Dashboard Monitoring
- The dashboard fetches data from Supabase and displays alert logs in real time.
Below is the correct wiring for flashing your ESP32-CAM using a TTL-to-USB module.
| 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.
- Connect ESP32-CAM and TTL adapter as per the wiring above.
- Hold IO0 → GND for flash mode.
- Open Arduino IDE or esptool.
- Select:
- Board: ESP32 Wrover Module
- Flash Size: 4MB
- Upload Speed: 115200
- Choose the correct COM port.
- Click Upload.
- Once done, disconnect IO0 from GND and press the RST button.
- The ESP32-CAM should start running your code 🎉.
1️⃣ Start ESP32
- Open Arduino IDE
- Install ESP32 board support (via Preferences → Additional Board Manager URLs)
- Open esp32/awake_guard.ino
- Update Wi-Fi credentials:
const char* ssid = "Your_WiFi_Name";
const char* password = "Your_WiFi_Password";
- Connect ESP32 to your PC and select correct COM port.
- Click Upload.
python main.py
Frame 128: 1 face(s) detected
Drowsiness detected!
🚨 DROWSINESS ALERT TRIGGERED!
📸 Image captured and sent to Telegram!
📍 Location saved to Supabase!
- Navigate to /dashboard
- Open login.html in a browser
- Login using your Supabase credentials
- View all alerts with time, date, location, and driver photo
Tip: Host Website on https://www.netlify.com
| 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 |
| 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!
