Driver Attention System: Technical Implementation Guide
This guide provides a comprehensive overview of implementing a driver attention monitoring system using EEG signals, Arduino, and visual feedback mechanisms.
EEG (Electroencephalography) Overview
EEG measures electrical activity in the brain using scalp electrodes. It detects voltage fluctuations from neuronal communication, categorized into frequency bands:

Key EEG Parameters
- Frequency Bands:
- Delta (0.5–4 Hz): Deep sleep, unconscious states
- Theta (4–8 Hz): Drowsiness, meditation, creativity
- Alpha (8–12 Hz): Relaxed wakefulness (eyes closed)
- Beta (12–30 Hz): Active concentration, alertness
- Gamma (30–100 Hz): Cognitive processing, problem-solving
- Amplitude:
Signal strength (microvolts, μV). Higher amplitude = synchronized neural activity. - Attention/Meditation Scores:
Derived metrics (0–100) from algorithms analyzing band ratios:- Attention: Beta/(Alpha+Theta) → Focus level
- Meditation: Theta/Alpha → Mental calmness
- Artifacts:
- Eye blinks (spikes in frontal electrodes)
- Muscle noise (high-frequency bursts)
In Driver Monitoring
- Drowsiness Detection: ↑Theta, ↓Beta
- Distraction: ↓Attention score, erratic Beta
- Blink Rate: ↑Frequency correlates with fatigue


MindWave Mobile 2 Overview
A single-channel EEG headset that measures brainwave activity via a forehead sensor and earlobe reference. Designed for developers and researchers, it outputs raw EEG data + processed metrics via Bluetooth.
Key Features
- Hardware:
- Dry electrode (no gel required)
- TGAM1/ThinkGear ASIC Module: Onboard EEG signal processing
- Bluetooth 4.0 (Low Energy) connectivity
- Battery: 8+ hours (rechargeable)
- Data Output:
- Raw EEG (512Hz sampling rate)
- Power spectrum (Delta/Theta/Alpha/Beta/Gamma)
- Derived metrics:
- Attention (0–100): Focus level (Beta dominance)
- Meditation (0–100): Mental calmness (Alpha/Theta ratio)
- Blink detection: Voltage spikes in frontal lobe
- Technical Specs:
- Voltage range: ±200μV
- Bandpass filter: 3–100 Hz
- Noise floor: <1μV
How It Works in Your System
- Signal Path:
Forehead electrode → TGAM1 (amplifies/filters signals) → ESP32 (UART serial at 57600 baud) - Code Integration:
mindwave.update(mindwaveSerial, onMindwaveData); // Parses serial data
int* eeg = mindwave.eeg(); // Array: [delta, theta, alpha, beta, gamma]
- Drowsiness Detection Logic:
- High Theta + Low Beta → Drowsy state
- Blink rate ↑ + Attention ↓ → Fatigue warning
Limitations
- Single-channel: Limited spatial resolution (only frontal lobe)
- Motion artifacts: Sensitive to head movement
- Noise susceptibility: Requires quiet environment
Hardware Components
- Arduino-compatible microcontroller (ESP32 recommended)
- NeuroSky MindWave EEG headset
- SSD1306 OLED display (128×64)
- WS2812B addressable LEDs (6-unit strip)
- Piezo buzzer for auditory feedback

System Architecture
The system follows a modular architecture with these key components:
1. EEG Signal Acquisition Module
2. Signal Processing & Analysis
3. State Detection Engine
4. Feedback System (Visual/Auditory)
5. User Interface
Implementation Details
1. EEG Signal Processing
The system processes raw EEG signals to extract attention and meditation values, along with frequency band data:
float calculateDrowsinessScore(int attention, int meditation, int* eeg, bool blinkDetected) {
// AI Model Parameters
const float THETA_WEIGHT = 0.3;
const float ALPHA_WEIGHT = 0.3;
const float BETA_PENALTY = -0.15;
const float MEDITATION_WEIGHT = 0.25;
const float ATTENTION_PENALTY = -0.2;
const float BLINK_PENALTY = -0.3;
const float HISTORY_WEIGHT = 0.2;
// Normalize inputs
float theta = eeg[1] / 250000.0;
float lowAlpha = eeg[2] / 60000.0;
float highAlpha = eeg[3] / 40000.0;
float lowBeta = eeg[4] / 15000.0;
float med = meditation / 100.0;
float att = attention / 100.0;
// Calculate score with historical context
float score = THETA_WEIGHT * theta +
ALPHA_WEIGHT * (lowAlpha + highAlpha) +
MEDITATION_WEIGHT * med +
BETA_PENALTY * lowBeta +
ATTENTION_PENALTY * att;
if (blinkDetected) {
score += BLINK_PENALTY;
}
return constrain(score, 0.0, 1.0);
}
2. State Detection Engine
Your system uses a hysteresis-based state machine to classify the driver’s cognitive state based on EEG inputs. This prevents rapid toggling between states due to signal noise.
Key States & Triggers
State | EEG Signature | Thresholds (Example) | Feedback Action |
---|---|---|---|
ALERT | High Beta, Low Theta | DrowsinessScore < 0.4 | Blue LEDs, no buzzer |
DROWSY | Rising Theta, Falling Beta | 0.4 ≤ Score ≤ 0.7 | Yellow LEDs, single beep |
ATTENTION_LOST | Theta dominance, Blink spikes | Score > 0.7 | Red LEDs, triple beep |
DISTRACTED | Low Attention score, erratic Beta | Attention < 40% | Purple LEDs |
Core Logic
- Input Processing:
- Raw EEG → Bandpower ratios (Theta/Beta, Alpha/Theta)
- Blink detection → Short-duration spikes in raw signal
- Hysteresis Guard
// Prevents rapid state changes
if (newState == STATE_DROWSY && currentState == STATE_ALERT) {
if (score > 0.4 + HYSTERESIS_THRESHOLD) confirmStateChange();
}
Time Confirmation:
States require 1-second persistence (your STATE_CONFIRMATION_TIME
) to activate.
Why It Works
- Theta (4–8Hz): ↑ during drowsiness
- Beta (12–30Hz): ↓ when focus wanes
- Blinks: ↑ frequency correlates with fatigue
3. Feedback Mechanisms
Visual Feedback
RGB LEDs provide color-coded feedback:
- Blue: Alert state
- Yellow: Drowsy warning
- Red: Critical attention loss
Auditory Feedback
Buzzer patterns escalate with severity:
- Single beep: Warning
- Triple beep: Critical alert
Installation Guide
Hardware Setup



Software Installation
- Install Arduino IDE
- Add required libraries (FastLED, Adafruit_SSD1306, Mindwave)
- Upload the provided sketch
- Calibrate the system
Firmware Guide GITHUB link
https://github.com/m-haider-iqbal/Automotive-Driver-Attention-Monitoring
Troubleshooting
Issue | Solution |
---|---|
No EEG signal | Check MindWave connection and battery |
LEDs not working | Verify data pin connection and power supply |
Display issues | Check I2C address and wiring |
Conclusion
This driver attention system provides real-time monitoring of cognitive states using affordable hardware. The modular design allows for customization and integration with additional sensors as needed.
This intelligent system continuously monitors the driver’s cognitive state using multiple physiological indicators:
- Brainwave Analysis:
- Processes EEG data (theta, alpha, beta waves) to detect drowsiness patterns
- Uses attention/meditation levels to assess focus
- Implements hysteresis to prevent state oscillation
- Multi-Modal Detection:
- Blink detection identifies prolonged eye closure
- Historical data analysis (10-point buffer) provides context
- Real-time scoring algorithm weights different factors
- Adaptive Feedback:
- Progressive alert system (LED colors + patterns)
- Escalating audible alerts based on severity
- Safety timeout prevents over-alerting
- State Management:
- 4 distinct driver states with clear thresholds
- Confirmation delay prevents false transitions
- Visual dashboard shows current status
The system combines neurotechnology with embedded systems design to create a responsive safety solution that adapts to the driver’s condition in real-time, providing timely interventions to prevent accidents caused by fatigue or distraction.
For questions or support, please leave a comment below or contact us through our support portal.