Skip to content

A real-time Raspberry Pi system for detecting driver drowsiness and vehicle crashes using facial landmarks, head pose, and motion sensors. Sends GPS-based emergency SMS alerts via Twilio and displays live driver status on an LCD.

Notifications You must be signed in to change notification settings

AbdullahAlokayl/RaspberryPi-Drowsiness-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💤 Drowsy Driver Detection System

Raspberry Pi Python License

🚘 Overview

This is a real-time drowsiness and impact detection system designed for drivers using a Raspberry Pi 4. It leverages computer vision, accelerometer data, and GPS location tracking to prevent accidents by alerting drivers and notifying emergency contacts through SMS.

🧠 Features

  • 👁️ Drowsiness Detection using eye blink ratio and head pose estimation via MediaPipe + OpenCV
  • 🌍 Real-time GPS tracking with BN-220 module
  • 📲 Emergency SMS Alerts using Twilio API
  • 📟 Live Status Display via 16x2 LCD
  • 💥 Impact Detection using MPU6050 accelerometer
  • 🧲 Button-triggered Execution from LCD display

🛠 Hardware Components

Component Description
Raspberry Pi 4 Model B Core processing unit for the system
Raspberry Pi Night Cam Night-vision camera for facial detection
BN-220 GPS Module Tracks live location
MPU6050 Accelerometer Detects sudden impacts
I2C LCD 16x2 Display Displays system status and thresholds
Active Buzzer & Button Audible alerts and physical interaction

🔧 Hardware: Design to Deployment

Fritzing Diagram – System Wiring Overview

System Wiring

This schematic shows the full wiring setup for the system using Raspberry Pi, including:

  • Sensors (MPU6050, GPS)
  • Output devices (LCD, buzzer)
  • Input (button) It visually represents how components connect to the Pi’s GPIO.

Real Prototype – Assembled Hardware

Prototype

A photo of the actual built prototype, showcasing the wired connections between the Raspberry Pi, night vision camera, GPS module, LCD, and other peripherals. It brings the Fritzing diagram to life in a practical setup.

💻 Software Architecture

Launch Script (run.py)

  • Executes the main script when a physical button is pressed.

Main Script (main0.1.py)

  • Real-time face mesh and eye detection using MediaPipe
  • Head pose estimation using OpenCV's solvePnP
  • GPS tracking via gpsd
  • Impact detection using mpu6050
  • SMS alerting via Twilio
  • LCD status update using rpi_lcd

🚦 Detection Logic

  • Blink Detection: Calculates eye aspect ratio. If the value exceeds eye_thresh, it's flagged.
  • Head Pose Estimation: Calculates the angle of head tilt. If x ≤ head_thresh, drowsiness is suspected.
  • Crash Detection: Detects high g-force values to identify collisions and immediately sends GPS + SMS.
  • Emergency Alerts: Sends alert via Twilio API to a preset emergency contact.

📍 Example SMS Alert

Hello Mr. Abdullah
Car Impact Alert From: Ahmed

Location: https://maps.google.com/?q=24.7136,46.6753

📦 Installation Instructions

  1. Install required libraries:

    pip install opencv-python mediapipe twilio gps3 gpiozero rpi_lcd mpu6050-raspberrypi
  2. Enable Camera & I2C on Raspberry Pi:

    sudo raspi-config
  3. Set up gpsd:

    sudo gpsd /dev/serial0 -F /var/run/gpsd.sock
  4. Run the system:

    python3 run.py

🔐 Twilio Setup

Replace your account_sid, auth_token, and messaging_service_sid in main0.1.py.

📈 Future Improvements

  • Detect phone usage with YOLO or MobileNet
  • Enhance facial gesture recognition (yawning, nodding)
  • Mobile App Integration via Bluetooth
  • Cloud-based real-time monitoring dashboard

📜 License

This project is licensed under the MIT License.

About

A real-time Raspberry Pi system for detecting driver drowsiness and vehicle crashes using facial landmarks, head pose, and motion sensors. Sends GPS-based emergency SMS alerts via Twilio and displays live driver status on an LCD.

Topics

Resources

Stars

Watchers

Forks

Languages