A Cyber-Physical System that monitors sleep quality in real-time using wearable sensors, Fog Computing, and a TensorFlow Lite LSTM model — all processed locally with zero cloud dependency.
┌──────────────────────────────────────────────────────┐
│ FOG LAYER (Laptop) │
│ │
│ Preprocessing → TFLite LSTM → Streamlit Dashboard│
│ (Feature Eng.) (64→32 units) (Live Score + HR) │
└──────────────────────────────────────────────────────┘
↑
USB Serial (115200 baud)
↑
┌──────────────────────────────────────────────────────┐
│ EDGE LAYER (Arduino) │
│ │
│ Arduino UNO + MPU-6050 (Accel) + PPG Pulse Sensor │
│ Output: timestamp, AcX, AcY, AcZ, Pulse @ 10Hz │
└──────────────────────────────────────────────────────┘
Flow: Arduino reads sensors → sends CSV over serial → Laptop (Fog Node) runs TFLite inference → Streamlit shows live results.
MMASH (PhysioNet) — 22 real subjects, 1.4M data points of accelerometer + heart rate during sleep.
Citation: Schmidt, P. & Reiss, A. (2018). MMASH Dataset. PhysioNet. https://doi.org/10.24432/C57K5T
| Detail | Value |
|---|---|
| Architecture | LSTM(64) → Dropout(0.2) → LSTM(32) → Dropout(0.2) → Dense(1) |
| Input | 30 timesteps × 6 features (movement magnitude, variance, avg HR, HRV, movement frequency, sleep duration) |
| Output | Sleep Score 0–100 → Good (≥70) / Poor (<70) |
| Format | TensorFlow Lite (.tflite) — optimized for edge inference |
| Scaler | MinMaxScaler fitted on training set, serialized as scaler.pkl |
FogSleepMonitor/
├── dashboard/app.py # Streamlit real-time dashboard
├── fog_node/fog_service.py # Fog processing + TFLite inference
├── hardware/arduino_code/ # Arduino .ino firmware
├── models/
│ ├── sleep_model.tflite # Optimized LSTM model (~64KB)
│ ├── sleep_lstm_model.h5 # Original Keras model
│ └── scaler.pkl # MinMaxScaler
├── config.py # All settings
├── prepare_mmash_dataset.py # Dataset preprocessor (MMASH)
├── train_model.py # LSTM training pipeline
├── convert_to_tflite.py # Keras → TFLite conversion
└── requirements.txt # Python dependencies
git clone https://github.com/guhya-16/FogSleepMonitor.git
cd FogSleepMonitor
python -m venv .venv
.venv\Scripts\Activate.ps1 # Windows
pip install -r requirements.txtpython prepare_mmash_dataset.py # Downloads MMASH dataset
python train_model.py # Trains LSTM
python convert_to_tflite.py # Converts to TFLite| MPU-6050 | Arduino | Pulse Sensor | Arduino | Actuators | Arduino | ||
|---|---|---|---|---|---|---|---|
| VCC | 5V | + | 5V | LED (+) | Pin 13 | ||
| GND | GND | – | GND | Buzzer (+) | Pin 8 | ||
| SDA | A4 | S | A0 | Both (–) | GND | ||
| SCL | A5 |
Flash hardware/arduino_code/arduino_code.ino via Arduino IDE (baud: 115200).
Terminal 1 — Fog Node:
$env:SLEEP_SERIAL_PORT="COM3" # Set your port
python fog_node/fog_service.py # Falls back to mock data if no ArduinoTerminal 2 — Dashboard:
streamlit run dashboard/app.pyOpen http://localhost:8501 to view the live dashboard.
- Privacy — Health data stays on your machine, never uploaded to cloud
- Low Latency — No network round-trips, instant predictions
- Offline — Works without internet after model is trained
- Low Cost — Arduino (~₹500) + free Python stack
| Layer | Tools |
|---|---|
| Edge | Arduino UNO, MPU-6050, PPG Pulse Sensor |
| Fog | Python, TensorFlow Lite, NumPy, Pandas, Scikit-learn |
| Dashboard | Streamlit |
| Communication | PySerial (USB Serial) |
MIT