Skip to content

GuruMohith24/Sleep_Quality_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

😴 Sleep Quality Estimation Using Wearable Sensors

Python License Scikit-learn Streamlit

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.


πŸš€ Project Overview

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

πŸ—οΈ System Architecture

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:

  1. Physical Layer: PPG Pulse Sensor + Arduino UNO for raw physiological data acquisition
  2. Communication Layer: USB Serial bridge using PySerial for high-speed data transmission
  3. 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

πŸ› οΈ Tech Stack

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

πŸ“‚ Project Structure

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!)

βš™οΈ Installation & Setup

1. Hardware Connection

  1. Connect the PPG Pulse Sensor to the Arduino:

    • Signal β†’ A0
    • VCC β†’ 5V
    • GND β†’ GND
  2. Connect the Arduino to your laptop via USB

2. Software Installation

Clone the repository:

git clone https://github.com/GuruMohith24/Sleep_Quality_Project.git
cd Sleep_Quality_Project

Set up Virtual Environment:

python -m venv .venv

# Activate on Windows:
.venv\Scripts\activate

# Activate on Mac/Linux:
source .venv/bin/activate

Install Dependencies:

pip install -r requirements.txt

πŸ“ˆ Usage

1. Upload Firmware

Upload the firmware/ppg_sensor.ino to your Arduino using the Arduino IDE.

2. Train Model (Optional)

Run the training script to see feature importance and save the model:

python scripts/train.py

Expected 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

3. Run Dashboard

Launch the real-time Streamlit interface:

streamlit run scripts/dashboard.py

🧠 Machine Learning Insights

The model uses a Random Forest Classifier which provides high robustness against noisy sensor data.

Feature Importance

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

Model Output

  • Classification: Binary (Good/Poor Sleep Quality)
  • Score: Heuristic score from 0-100
  • Threshold: Sleep quality β‰₯ 7 classified as "Good"

πŸ”¬ Why This Approach?

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

🎯 Future Enhancements

  • 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)

πŸ‘¨β€πŸ’» Author

Guru Mohith


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❀️ for better sleep quality monitoring

About

created by guru mohith

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages