A motion-based epilepsy detection prototype designed to support student safety and real-time monitoring in educational environments. The system uses an ESP32-DOIT microcontroller and MPU-6050 6-axis accelerometer/gyroscope to capture motion data. Using Edge Impulse, the device runs a lightweight machine learning model directly on the ESP32 for real-time classification of seizure-like movement patterns.
β οΈ Important: This is a defensive safety tool designed to assist with monitoring and early alert systems. It's not intended as a medical diagnostic device but rather as an assistive technology for educational environments.
EpiWatch combines affordable hardware with advanced machine learning to create a wearable device that can detect abnormal motion patterns associated with seizure activity. The system provides immediate alerts through multiple channels while maintaining privacy through on-device processing.
- Real-time Motion Analysis: 6-axis sensor data processed at 43Hz
- On-Device ML Inference: Edge Impulse model runs locally on ESP32
- Multi-Modal Alerts: buzzer and configurable output pins
- Low Power Design: Optimized for wearable applications
- Confidence Averaging: Reduces false positives through temporal smoothing
- Open Source: Complete hardware design and software stack
- ESP32-DOIT DevKit V1: Main microcontroller with WiFi/Bluetooth
- MPU-6050: 6-axis accelerometer/gyroscope sensor
- Alert Components: Buzzer (Pin 23)
- Power: 18650 lithium battery or USB power
ESP32 MPU-6050
----- --------
3.3V β VCC
GND β GND
GPIO 21 β SDA
GPIO 22 β SCL
ESP32 Alerts
----- ------
GPIO 23 β Buzzer
The project includes a custom 3D-printable enclosure designed in FreeCAD:
- Files:
CAD/Cover-Body.stl,CAD/Top_lid.FCStd - Material: PLA plastic recommended
- Design: Compact wearable form factor with sensor access
- Assembly: Snap-fit design for easy assembly
The system collects sensor data at 43Hz sampling rate:
- Accelerometer: X, Y, Z axes (Β±8G range)
- Gyroscope: X, Y, Z axes (Β±500Β°/s range)
- Window Size: 2 seconds (86 samples)
- Classes: Normal activity vs. seizure-like motion
- Platform: Edge Impulse
- Processing: Spectral analysis for frequency domain features
- Architecture: Neural network with 20-neuron hidden layer
- Performance: >85% accuracy with <50ms inference time
# Install PlatformIO
pip install platformio
# Install Python dependencies for data collection
pip install pandas numpy pyserial
# Install Edge Impulse CLI (optional)
npm install -g edge-impulse-cli-
Clone the repository
git clone <repository-url> cd epiwatch_deployment
-
Build the firmware
pio run
-
Flash to ESP32
pio run --target upload
-
Monitor output
pio device monitor
-
Normal Activity Data
cd data-collector-tool python3 script_collector.py -p /dev/ttyUSB0 -l "normal" -o ../dataset/normal.csv -d 60
-
Seizure Simulation Data
python3 script_collector.py -p /dev/ttyUSB0 -l "seizure" -o ../dataset/seizure.csv -d 60
cd data
python3 prepare_for_edge_impulse.py -i ../dataset -o edge_impulse_dataFollow the comprehensive guide in data/edge_impulse_training_guide.md for detailed steps on:
- Creating an Edge Impulse project
- Uploading training data
- Configuring the impulse
- Training and optimizing the model
- Deploying to ESP32
The device continuously monitors motion and provides:
- Confidence Scoring: Probability values for each prediction
- Temporal Averaging: Smooths predictions over 5 samples
- Threshold-based Alerts: Configurable seizure detection threshold (default: 0.7)
- Alert States: Visual and auditory feedback
Predictions (DSP: 3 ms, NN: 12 ms): normal: 0.95 seizure: 0.05
Average confidence over 5 samples: 0.04
β
Normal activity detected.
epiwatch_deployment/
βββ src/ # ESP32 source code
β βββ main.cpp # Main inference and alert logic
β βββ data_collection.cpp # Data collection mode
βββ data-collector-tool/ # Python data collection scripts
βββ data/ # Edge Impulse training utilities
βββ dataset/ # Raw training data (CSV)
βββ CAD/ # 3D printable enclosure files
βββ sample/ # Hardware photos and documentation
βββ lib/ # Edge Impulse library
- Seizure Threshold: Confidence level for triggering alerts
- Sample Rate: Data collection frequency (default: 43Hz)
- Confidence Samples: Number of samples for temporal averaging
- Alert Pins: GPIO assignments of buzzer
The system can be extended with:
- WiFi/Bluetooth connectivity for remote alerts
- Data logging to SD card
- Integration with smartphone apps
- Multiple sensor fusion (heart rate, temperature)
This is an open-source defensive safety project. Contributions are welcome for:
- Improved ML models and feature extraction
- Hardware optimizations and new sensor integration
- Enhanced alert mechanisms
- Documentation and educational resources
This project is licensed under the terms specified in the LICENSE file.
Built for educational and assistive purposes - helping create safer learning environments through technology.


