A Cyber-Physical System (CPS) and Machine Learning project designed to provide real-time, privacy-focused sleep quality estimation. This system integrates hardware sensing with a Random Forest model to process physiological data locally (Fog Computing), delivering an interpretable sleep score from 0-100.
Traditional sleep monitoring often relies on cloud-based processing, leading to latency issues and privacy concerns. This project addresses these gaps by:
| Feature | Description |
|---|---|
| π Local Processing (Fog Node) | Uses a laptop as a processing hub to ensure data privacy and low-latency feedback |
| β‘ Real-Time Sensing | Captures raw PPG (Photoplethysmogram) data via an Arduino-integrated pulse sensor |
| π§ Interpretable AI | Implements a Random Forest Classifier to categorize sleep quality and identify key physiological drivers |
The project is structured into three distinct layers:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CYBER/FOG LAYER β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β
β β Preprocessingβ β β ML Model β β β Streamlit Dashboard β β
β β (HeartPy) β β(RandomForest)β β (Real-time Visuals) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
USB Serial (PySerial)
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PHYSICAL LAYER β
β ββββββββββββββββββββββββββββββββββββββββ β
β β Arduino UNO + PPG Pulse Sensor β β
β β (Raw Physiological Data Acquisition)β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Layer Details:
- Physical Layer: PPG Pulse Sensor + Arduino UNO for raw physiological data acquisition
- Communication Layer: USB Serial bridge using
PySerialfor high-speed data transmission - Cyber/Fog Layer:
- Preprocessing: Feature extraction (BPM, HRV) from raw signals
- Inference: A pre-trained Random Forest model for classification and scoring
- Visualization: A Streamlit-based real-time dashboard
| Category | Technologies |
|---|---|
| Hardware | Arduino UNO R3, PPG Pulse Sensor, LEDs, Resistors |
| Languages | Python 3.9+, C++ (Arduino Sketch) |
| ML Framework | Scikit-learn (Random Forest) |
| Visualization | Streamlit |
| Key Libraries | pandas, joblib, pyserial, heartpy, numpy, matplotlib |
Sleep_Quality_Project/
βββ π data/ # Training datasets
β βββ Sleep_health_and_lifestyle_dataset.csv
βββ π firmware/ # Arduino source code (.ino)
βββ π models/ # Saved Machine Learning models
β βββ sleep_quality_model.pkl
βββ π scripts/ # Python scripts for ML and Dashboard
β βββ train.py # Model training and feature importance
β βββ dashboard.py # Streamlit real-time interface
βββ π requirements.txt # Python dependencies
βββ π .gitignore # Git ignore rules
βββ π LICENSE # MIT License
βββ π README.md # Project documentation (you are here!)
-
Connect the PPG Pulse Sensor to the Arduino:
SignalβA0VCCβ5VGNDβGND
-
Connect the Arduino to your laptop via USB
Clone the repository:
git clone https://github.com/GuruMohith24/Sleep_Quality_Project.git
cd Sleep_Quality_ProjectSet up Virtual Environment:
python -m venv .venv
# Activate on Windows:
.venv\Scripts\activate
# Activate on Mac/Linux:
source .venv/bin/activateInstall Dependencies:
pip install -r requirements.txtUpload the firmware/ppg_sensor.ino to your Arduino using the Arduino IDE.
Run the training script to see feature importance and save the model:
python scripts/train.pyExpected Output:
Loaded data from: .../data/Sleep_health_and_lifestyle_dataset.csv
--- Feature Importance ---
Sleep Duration 0.35
Heart Rate 0.30
Physical Activity Level 0.20
Daily Steps 0.10
Age 0.05
Model saved to: .../models/sleep_quality_model.pkl
Launch the real-time Streamlit interface:
streamlit run scripts/dashboard.pyThe model uses a Random Forest Classifier which provides high robustness against noisy sensor data.
| Feature | Weight | Description |
|---|---|---|
| ποΈ Sleep Duration | ~35% | Primary predictor of sleep quality |
| β€οΈ Heart Rate | ~30% | Key physiological indicator |
| π Physical Activity | ~20% | Daily exercise impact |
| π£ Daily Steps | ~10% | Movement patterns |
| π Age | ~5% | Demographic factor |
- Classification: Binary (Good/Poor Sleep Quality)
- Score: Heuristic score from 0-100
- Threshold: Sleep quality β₯ 7 classified as "Good"
| Challenge | Our Solution |
|---|---|
| Privacy Concerns | All processing happens locally on the Fog Node |
| Latency Issues | Edge computing eliminates cloud round-trips |
| Interpretability | Random Forest provides feature importance insights |
| Cost | Low-cost Arduino + open-source software stack |
- Add LSTM/RNN for temporal pattern recognition
- Integrate SpO2 sensor for oxygen saturation monitoring
- Mobile app for remote monitoring
- Sleep stage classification (REM, Deep, Light)
Guru Mohith
- GitHub: @GuruMohith24
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ for better sleep quality monitoring