A prototype system for non-invasive glucose level estimation using PPG signals from MAX30102 sensor and machine learning algorithms.
- Introduction
- Features
- Hardware Requirements
- Setup Instructions
- Data Collection Process
- Machine Learning Training
- Deployment
- Usage
- Data Management
- Future Improvements
- License
This project demonstrates a proof-of-concept for non-invasive glucose monitoring using photoplethysmography (PPG) signals. The system captures infrared and red light absorption data from a MAX30102 sensor, processes the signals to extract meaningful features, and uses a machine learning model to estimate glucose levels. This repository contains the Arduino code for the embedded system and Python scripts for model training.
Disclaimer: This is a research prototype only. Not for medical use. Accuracy depends on individual calibration and has not been clinically validated.
- Real-time PPG signal acquisition from MAX30102 sensor
- Dual-wavelength (IR + Red) optical measurement
- Feature extraction (IR/Red ratio, signal variability, waveform slope)
- Glucose level prediction using linear regression
- OLED display for real-time readings
- Alert system for hypo/hyperglycemia
- SD card data logging
- Cloud data upload via WiFi
- Model update capability
| Component | Quantity | Notes |
|---|---|---|
| ESP32 Development Board | 1 | Main microcontroller |
| MAX30102 Sensor | 1 | PPG sensor for IR/Red signals |
| SSD1306 OLED Display | 1 | 128x64 resolution |
| MicroSD Card Module | 1 | For data logging |
| Buzzer | 1 | For alert signals |
| Breadboard & Jumper Wires | As needed | For connections |
| Power Source | 1 | 5V power supply or battery |
| ESP32 Pin | MAX30102 | SSD1306 | SD Module | Buzzer |
|---|---|---|---|---|
| 3.3V | VIN | VCC | VCC | |
| GND | GND | GND | GND | GND |
| GPIO 21 | SDA | SDA | ||
| GPIO 22 | SCL | SCL | ||
| GPIO 5 | CS | |||
| GPIO 18 | SCK | |||
| GPIO 23 | MOSI | |||
| GPIO 19 | MISO | |||
| GPIO 15 | + |
- Install Arduino IDE (v1.8.x or newer)
- Add ESP32 board support:
- Add this URL to Preferences > Additional Boards Manager URLs:
https://dl.espressif.com/dl/package_esp32_index.json - Install "ESP32" from Boards Manager
- Add this URL to Preferences > Additional Boards Manager URLs:
- Install required libraries:
Adafruit MAX3010x LibraryAdafruit SSD1306Adafruit GFX LibrarySDWiFi
- Clone this repository:
git clone https://github.com/yourusername/glucose-monitor.git
- Connect the hardware as shown in the circuit diagram
- Place finger on the MAX30102 sensor
- Upload
GlucoseMonitor.inoto ESP32 - Open Serial Monitor (115200 baud)
- In Training Mode:
- System captures PPG signals every 5 seconds
- Features are displayed on OLED
- Enter reference glucose value via Serial Monitor when prompted
- Data is saved to SD card and uploaded to cloud
- Collect data across different physiological states (fasting, post-meal, etc.)
- Collect training data on SD card as CSV files
- Transfer data to computer
- Run the Python training script:
pip install pandas numpy scikit-learn python train_model.py
- The script will:
- Load and preprocess collected data
- Train a linear regression model
- Generate model coefficients
- Evaluate model performance
- Save coefficients to
model.csv
- Copy
model.csvto SD card root directory
- Place
model.csvon SD card - Switch system to Prediction Mode (modify code):
// Change in setup() currentMode = PREDICTION; - Upload modified code to ESP32
- System will:
- Load model coefficients during startup
- Capture PPG signals in real-time
- Extract features and predict glucose levels
- Display results on OLED
- Trigger alerts when thresholds are exceeded
- Log prediction data to SD card
- Power on the system
- Place finger steadily on sensor
- Wait for 10-20 seconds for stable readings
- Interpret results:
- Normal: 70-180 mg/dL
- Hypoglycemia alert: <70 mg/dL (buzzer sounds)
- Hyperglycemia alert: >180 mg/dL (buzzer sounds)
- For continuous monitoring:
- System updates prediction every 5 seconds
- Data logs to SD card every minute
- Cloud uploads occur every 10 minutes
/SD_CARD_ROOT
├── /training.csv # Training data (features + reference values)
├── /predictions.csv # Prediction logs
├── /model.csv # Current model coefficients
└── /backup/ # Archived data files
Data is sent to a REST API endpoint in JSON format:
{
"timestamp": 1678901234567,
"ratio": 1.2345,
"variability": 45.67,
"slope": 12.34,
"glucose": 125.0,
"prediction": 128.5
}To configure your endpoint:
// In the Arduino code
const char* serverUrl = "http://your-api-endpoint.com/data";- Implement motion artifact detection
- Add temperature compensation
- Include heart rate variability features
- Develop TinyML model with TensorFlow Lite
- Create mobile app for calibration and visualization
- Implement user authentication for cloud data
- Add battery management system
- Develop enclosure for wearable use
This project is licensed under the MIT License - see the LICENSE file for details.
