๐Ÿง  DriveSense AI โ€” Adaptive Driver Fatigue & Attention Monitor

"Every year, 100,000 people die from drowsy driving. DriveSense AI predicts fatigue before it kills."

๐ŸŽฏ Judge's Pitch

Existing driver monitoring systems detect drowsiness after your eyes close. DriveSense AI uses a multi-factor fatigue fusion model that combines PERCLOS, blink anomalies, head pose drift, yawn frequency, and circadian rhythm data to predict dangerous fatigue levels 10 minutes before they happen โ€” giving drivers time to save their own lives. It's the difference between a near-miss and a funeral.


๐Ÿ’ก Inspiration

We started with a question: Why do driver monitoring systems only react instead of predict?

openpilot has a driver-facing camera that checks if you're looking at the road. But alertness isn't binary. Fatigue is a gradual physiological process โ€” it shows up in your blink patterns 20 minutes before you feel sleepy. Your head starts micro-drifting. Your yawns cluster together.

We built DriveSense AI to catch what humans can't feel happening to themselves.


๐Ÿš— What It Does

DriveSense AI is a real-time driver fatigue monitoring and prediction dashboard that:

  • ๐Ÿ” Tracks 6+ biometric signals โ€” PERCLOS (eye closure percentage), blink rate, head yaw/pitch, yawn frequency, gaze direction, mouth openness
  • ๐Ÿง  Runs a multi-factor AI fatigue model โ€” Weighted fusion of all signals through an exponential moving average pipeline
  • ๐Ÿ“ˆ Predicts fatigue 10 minutes ahead โ€” Linear regression on trend data projects when you'll cross danger thresholds
  • ๐Ÿ† Computes a real-time Safety Score (0โ€“100, Aโ€“F grade) โ€” With component breakdowns showing exactly what's degrading
  • ๐Ÿšจ 3-tier alert system โ€” Info nudges โ†’ Warning chimes โ†’ Critical "PULL OVER" full-screen overlay with audio
  • ๐ŸŒ™ Circadian rhythm modeling โ€” Knows that 3 AM and 2 PM are biologically dangerous times
  • โ˜• Coffee break simulation โ€” Models temporary alertness recovery after a rest stop
  • ๐Ÿ—บ๏ธ Gaze attention heatmap โ€” Visualizes where the driver is looking over time

4 Realistic Driving Scenarios

Scenario Description
๐ŸŒ™ Night Highway Monotonous highway at 11 PM โ€” fatigue builds fast
๐ŸŒ… Morning Commute Rush hour at 7:30 AM โ€” stop-and-go keeps you alert
๐Ÿ˜ด Post-Lunch Dip Afternoon drive at 2 PM โ€” the circadian dip strikes
๐Ÿš› Long Haul Trucker 6-hour interstate haul โ€” relentless fatigue accumulation

๐Ÿ—๏ธ How We Built It

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Dashboard UI                     โ”‚
โ”‚  (index.html + glassmorphism CSS)                โ”‚
โ”‚                                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Driver   โ”‚ โ”‚ Chart.js  โ”‚ โ”‚ Alert Feed     โ”‚  โ”‚
โ”‚  โ”‚ Face     โ”‚ โ”‚ Timeline  โ”‚ โ”‚ + Toast        โ”‚  โ”‚
โ”‚  โ”‚ Canvas   โ”‚ โ”‚ + Gauge   โ”‚ โ”‚ Notifications  โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ”‚
โ”‚               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”                     โ”‚
โ”‚               โ”‚  app.js     โ”‚ โ† Main Controller   โ”‚
โ”‚               โ”‚  (60fps)    โ”‚                     โ”‚
โ”‚               โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”˜                     โ”‚
โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚
โ”‚     โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚     โ”‚AI Eng. โ”‚ โ”‚Simulationโ”‚ โ”‚Scoring  โ”‚         โ”‚
โ”‚     โ”‚Fatigue โ”‚ โ”‚Scenario  โ”‚ โ”‚Safety   โ”‚         โ”‚
โ”‚     โ”‚Model   โ”‚ โ”‚Generator โ”‚ โ”‚Score    โ”‚         โ”‚
โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ”‚                                                   โ”‚
โ”‚     config.js    utils.js    alerts.js            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Tech Stack

Technology Why We Chose It
Vanilla JS Zero build step, instant demo, max portability. Opens from a file.
Canvas API Real-time face visualization at 60fps without DOM overhead
Chart.js 4 Beautiful animated charts with 5 lines of config
CSS Glassmorphism Premium dark theme that wows judges instantly
Web Audio API Alert sounds without loading audio files
requestAnimationFrame Smooth, battery-efficient render loop

Key Technical Decisions

  1. Multi-factor fusion over binary detection โ€” Real fatigue is a spectrum. Our weighted model captures gradients that threshold-based systems miss.
  2. Predictive regression โ€” Instead of just reporting current state, we project the fatigue trajectory forward using linear regression on rolling history.
  3. Circadian rhythm modeling โ€” Physiological alertness follows a 24-hour curve. Our model factors in time-of-day to correlate with biological fatigue patterns.
  4. Simulation with realistic noise โ€” Gaussian noise, smooth sine-based drift, and Box-Muller transforms create data that feels organic, not robotic.

๐ŸŽฎ Demo

Running Locally

# No build step needed! Just serve static files:
npx -y serve .

# Then open http://localhost:3000

Controls

  • Scenario Selector โ€” Switch between 4 driving scenarios
  • Speed Controls โ€” 1ร—, 2ร—, 5ร—, 10ร— simulation speed
  • Pause/Resume โ€” Freeze the simulation to inspect state
  • Reset โ€” Start the scenario fresh

What to Watch For

  1. Start with Night Highway at 5ร— speed
  2. Watch the fatigue line climb on the timeline chart
  3. Notice the face canvas โ€” eyes start closing, head drifts
  4. Info alerts appear first, then warnings
  5. At ~80% fatigue: PULL OVER overlay with urgent audio
  6. The Safety Score drops from A (green) to F (red) in real-time
  7. Check the gaze heatmap โ€” attention scatter increases with fatigue

๐Ÿงฉ Challenges

  1. Making simulated data feel real โ€” Purely random data looks fake. We used Gaussian noise, Box-Muller transforms, and multi-frequency sine wave composition to create organic physiological patterns.
  2. Alert fatigue โ€” Ironic for a fatigue system! We implemented cooldown timers per alert level to prevent notification spam while still catching every real danger.
  3. Predictive accuracy โ€” Linear regression is simple but effective on monotone fatigue curves. More complex scenarios (coffee breaks, conversation) required modeling recovery dynamics.
  4. 60fps Canvas rendering โ€” Drawing a face + indicators + eyes every frame while updating Chart.js and managing alerts required careful throttling of expensive operations.

๐Ÿ† Accomplishments

  • Full real-time fatigue prediction โ€” Not just detection, but a 10-minute lookahead
  • 5-component weighted AI model running at 60fps with no jank
  • Production-quality UI with glassmorphism, micro-animations, and responsive design
  • Zero dependencies (except Chart.js CDN) โ€” opens from any file server
  • Realistic simulation engine that models circadian rhythms, microsleeps, coffee breaks, and yawn clustering
  • Multi-modal alerts โ€” visual toasts, feed history, audio chimes, and emergency overlay

๐Ÿ“š What We Learned

  • PERCLOS (Percentage of Eye Closure) is the gold standard metric in fatigue research โ€” we implemented it using a rolling 60-second window
  • Circadian rhythms create two daily valleys of alertness: 2โ€“4 AM and 1โ€“3 PM โ€” both are peak crash windows
  • Alert design matters as much as detection accuracy โ€” a system that annoys the driver is a system that gets turned off
  • Exponential Moving Averages are surprisingly effective for real-time signal smoothing with minimal computational cost
  • Canvas 2D can render surprisingly expressive face visualizations with basic shape primitives

๐Ÿ”ฎ Future Improvements

  • Real camera integration โ€” Replace simulation with MediaPipe Face Mesh for actual driver monitoring via webcam
  • openpilot plugin โ€” Deploy as a companion app that reads openpilot's driver monitoring camera feed
  • ML model upgrade โ€” Train an LSTM on real fatigue datasets (like DROZY or UTA-RLDD) for higher accuracy
  • Heart rate variability โ€” Integrate smartwatch HRV data for cardiovascular fatigue markers
  • Fleet management dashboard โ€” Multi-driver monitoring for commercial trucking companies
  • V2X communication โ€” Share fatigue state with nearby vehicles and infrastructure
  • Personalized baselines โ€” Learn individual driver patterns to customize thresholds

๐Ÿ“ Project Structure

car/
โ”œโ”€โ”€ index.html              # Main dashboard (single page)
โ”œโ”€โ”€ README.md               # This file
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ config.js           # All tunable constants
โ”œโ”€โ”€ css/
โ”‚   โ””โ”€โ”€ style.css           # Premium dark glassmorphism theme
โ””โ”€โ”€ js/
    โ”œโ”€โ”€ utils.js            # Helpers (EMA, noise, color interpolation)
    โ”œโ”€โ”€ ai-engine.js        # Multi-factor fatigue AI model
    โ”œโ”€โ”€ simulation.js       # Driving scenario simulator
    โ”œโ”€โ”€ scoring.js          # Safety score engine (0โ€“100, Aโ€“F)
    โ”œโ”€โ”€ alerts.js           # 3-tier alert manager + Web Audio
    โ”œโ”€โ”€ charts.js           # Chart.js timeline + canvas gauge + heatmap
    โ””โ”€โ”€ app.js              # Main controller + face renderer

๐Ÿ“„ License

MIT License โ€” Free to use, modify, and distribute.


Because the best safety system is the one that works before you need it.

Built With

Share this project:

Updates