- π 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!
