This project implements a Drowsiness Detection System for drivers using computer vision and embedded electronics. It monitors eye activity through a webcam and alerts the driver via buzzer and LCD if signs of drowsiness are detected. The system uses Python (OpenCV + dlib) for image processing, an Arduino for alerting, and Proteus for circuit simulation. It was also physically implemented on PCB.
- Overview
- How It Works
- Hardware Required
- Software Used
- Folder Structure
- Setup Instructions
- Circuit Connections
- Simulation (Proteus)
- Code Breakdown
- Photos
- License
- Python captures webcam input and uses dlib to detect eyes.
- It calculates Eye Aspect Ratio (EAR) to determine if the driver is sleeping.
- Based on the status, it sends
'a'(sleepy) or'b'(awake) to Arduino via Serial. - Arduino receives the data and:
- Displays status on LCD
- Triggers a buzzer and LED for alert
- The full setup is simulated in Proteus and implemented physically using PCB.
- Laptop webcam continuously monitors the user’s face.
- Eye landmarks are detected and Eye Aspect Ratio (EAR) is calculated.
- If EAR drops below threshold for a defined period:
- Python sends
'a'to Arduino. - Arduino activates buzzer, LED and LCD alert.
- Python sends
- If user is awake:
'b'is sent to Arduino to show “Safe journey”.
| Component | Quantity |
|---|---|
| Arduino Uno | 1 |
| 16x2 LCD | 1 |
| Buzzer | 1 |
| Red LED | 1 |
| NPN Transistor | 1 |
| Resistors | Few |
| PCB or Breadboard | 1 |
| Jumper Wires | As needed |
| 5V/9V Transformer | 1 (if powering externally) |
- Python 3.x
- OpenCV
- dlib
- imutils
- Arduino IDE
- Proteus 8 (for simulation)
- Git LFS (for large
.datfile)
Drowsiness-Detection/
├── arduino/
│ └── drowsiness_alert.ino
├── python/
│ └── drowsiness_detection.py
├── model/
│ └── shape_predictor_68_face_landmarks.dat
├── images/
│ ├── proteus_schematic.jpg
│ └── pcb_hardware.jpg
├── README.md
└── requirements.txt
-
Install dependencies:
pip install -r requirements.txt
-
Clone and set up Git LFS for the
.datfile:GitHub uses Git LFS (Large File Storage) to store the large
.datmodel file used by dlib.Run the following after cloning the repo:
git lfs install git lfs pull
This will download the required model:
model/shape_predictor_68_face_landmarks.dat -
Run the Python script:
python python/drowsiness_detection.py
- Open
drowsiness_alert.inoin Arduino IDE. - Connect Arduino via USB.
- Upload the sketch.
- Keep the Serial Monitor closed to avoid conflict with Python serial communication.
| Arduino Pin | Connects To | Description |
|---|---|---|
| D2–D7 | 16x2 LCD | Used to display status messages |
| D8 | Buzzer (via transistor) | For audible alert |
| D9 | Red LED | For visual alert |
| GND | Common ground | Shared with all components |
| 5V | Power supply to LCD and buzzer | Power from Arduino |
| USB | Laptop | For power + serial communication |
- Transistor is used between buzzer and Arduino for current control.
- Resistors are used for base control of transistor and current limiting for LED.
We used Proteus 8 to simulate the complete circuit.
- LCD shows messages from Arduino
- Buzzer and LED trigger based on serial input
- You can simulate sending
'a'or'b'using Proteus Serial Terminal
- Captures webcam feed using OpenCV.
- Detects facial landmarks using the pre-trained
.datmodel from thedliblibrary. - Calculates Eye Aspect Ratio (EAR) using 6 key points around each eye.
- Decision logic based on EAR:
EAR < 0.21→ Driver is likely sleeping.0.21 ≤ EAR ≤ 0.25→ Driver is drowsy.EAR > 0.25→ Driver is awake.
- Based on the EAR, the Python script sends a serial signal:
'a'→ Drowsy or sleeping (alerts Arduino)'b'→ Awake (no alert needed)
- Uses
LiquidCrystallibrary to control LCD - Listens to serial input from Python:
'a'= show alert, trigger buzzer + LED'b'= show safe message, no alert
- Uses delay intervals for blink and visibility
- File:
shape_predictor_68_face_landmarks.dat - Used by dlib to locate 68 key facial points
- Pre-trained, required for face/eye tracking
This project is intended for academic and demonstration purposes. It was originally created by YouTube. Feel free to use, modify, and expand upon it.