In this project, we are building an end-to-end clinical-grade IoT biometric monitor. We will use an ESP32 to capture raw electrocardiogram (ECG) and photoplethysmography (PPG) data, send it over Wi-Fi to a Python Flask backend, process 19 Heart Rate Variability (HRV) metrics, and use a Machine Learning ensemble to predict "Stress" or "No Stress" in real-time on a beautiful React.js dashboard.
The Vision & Social Impact:
- Chronic stress and workplace burnout represent a modern silent epidemic, directly contributing to cardiovascular diseases and mental health crises.
- Traditional assessment relies on subjective, retrospective questionnaires prone to human bias. Our system introduces a paradigm shift in behavioral health by creating an objective, continuous, and completely non-invasive stress tracking pipeline.
- By providing instantaneous physiological feedback, users can actively modify their behavior, practice real-time down-regulation techniques, and manage their well-being before a physical crisis occurs.
This project shifts healthcare from reactive treatment to proactive, data-driven self-awareness.
Commercialization & Productization Prospects:
This architecture is custom-built for high scalability and seamless transition into an entrepreneurship program.
- Corporate Wellness SaaS: The React dashboard can scale into a multi-user corporate portal where enterprises monitor anonymous, aggregated workforce stress levels to optimize workplace environments.
- Wearable Integration: The entire hardware footprints of the ESP32, AD8232, and MAX30102 can easily be miniaturized onto a single custom PCB, fitting into a lightweight chest strap or smartwatch prototype.
B2B Licensing: The signal processing algorithm that converts raw values to 19 HRV metrics on a Flask server can be packaged as an API and licensed to existing health-tech applications.
Technology Practicality & Cost-Efficiency:
- Clinical ECG diagnostic equipment costs thousands of dollars and requires complex hospital setups.
- Our solution proves that high-performance medicine can be democratized.
Built entirely from off-the-shelf, low-cost commodity hardware totaling under $20, this system provides near-clinical observation accuracy at a fraction of the price, making continuous health tracking accessible to low-income populations and developing medical infrastructures.
Technical Architecture & Deep Design Detail:
The pipeline is engineered to extract clinical-grade biological markers on low-cost hardware through a three-tier architecture:
- The Edge Layer (MicroPython/ESP32): To prevent data loss during high-frequency sampling (~200Hz for ECG), we implemented an asynchronous dual-core threading architecture. Core 1 is dedicated entirely to precise sensor polling, while Core 0 handles Wi-Fi batching and network transmission.
- The Computational Brain (Flask/Python): Raw bio-signals are prone to motion artifacts. The backend applies digital bandpass filtering to isolate R-peaks cleanly. Instead of calculating basic heart rate, the system evaluates a moving 60-second sliding window to extract 19 distinct time-domain and frequency-domain Heart Rate Variability (HRV) metrics.
- The Ensemble Predictor: Rather than relying on a single classifier, we deployed a pre-trained Ensemble Machine Learning framework (trained on WESAD). This mitigates individual model biases, resulting in robust, reliable classifications ("Healthy", "Stressed") pushed to a React.js dashboard via WebSockets.
Components List:
| Component Name | Quantity | Purpose |
| ESP32 Dev Board | 1 | Acts as the Edge AI node. Reads sensor data and transmits payloads over Wi-Fi via HTTP POST. |
| MAX30102 Module | 1 | Optical sensor used to calculate live heart rate (BPM) and blood oxygenation (SpO2). |
| AD8232 Module | 1 | Amplifies and filters the micro-electrical signals of the heart to provide an ECG waveform. |
| ECG Electrodes | 3 | Disposable pads attached to the user's skin to pick up cardiac electrical activity. |
| Breadboard & Wires | 1 | Used to route 3.3V power and establish a common ground for the sensor network. |
Software Stack:
- Micro-Python (Thonny)
- Python 3
- Flask
- Scikit-learn
- React.js
Socket.io-client.
Circuit Connections:
| Component | Pin | Connected To (ESP32) |
| MAX30102 | VCC / VIN | 3.3V |
| MAX30102 | GND | GND |
| MAX30102 | SDA | GPIO 21 |
| MAX30102 | SCL | GPIO 22 |
| AD8232 | 3.3V | 3.3V |
| AD8232 | GND | GND |
| AD8232 | OUTPUT | GPIO 36 (VP / ADC0) |
| AD8232 | LO+ | GPIO 32 |
| AD8232 | LO- | GPIO 33 |

Implementation:
- Wire the Hardware: Connect the sensors to the ESP32 following the pinout table above. Ensure a common ground.
- Flash the Edge Device: Upload the MicroPython firmware to the ESP32 using Thonny IDE.
- Start the Brain: Run the Python Flask backend. It will begin listening on Port 5000 for the ESP32's TCP packets.
- Launch the UI: Start the React.js development server to initialize the WebSocket connection with Flask.
- Calibrate: Attach the ECG electrodes, place your finger on the MAX30102, and wait 60 seconds for the sliding window to fill and generate the first ML prediction.
Edge Programming:
- Reads the analog voltage from the AD8232.
- Rapidly polls the MAX30102 without blocking, checking for optical peaks to calculate BPM and SpO2.
Batches this data and transmits it via HTTP POST exactly once every 5 seconds.

Machine Learning Inference:
- Sliding Window: It appends the live data into a 60-second rolling buffer.
- Signal Processing: It applies bandpass filters to the raw waveform, detects precise R-peaks, and computes 19 clinical Heart Rate Variability (HRV) metrics (like RMSSD, LF/HF ratio).
Ensemble Machine Learning: It feeds these 19 metrics into a pre-trained Scikit-Learn Machine Learning pipeline (trained on the WESAD dataset) to instantly classify the data as "Healthy" or "Depressed."

Medical Dashboard:
- Sweeping line charts for ECG and optical pulse waveforms.
- Large metric cards for live BPM and Blood Oxygenation (SpO2).
A dynamic UI status ring that glows Green for Healthy or Red for Stress based on the ML confidence score.

Testing and Demonstration:
- Attach the three AD8232 biomedical pads to your chest/arms.
- Place your index finger gently on the red glowing LED of the MAX30102.
- Start your Flask server and React app.
Power up the ESP32.
Video:
Conclusion:
To conclude, by combining the raw hardware capabilities of the ESP32, the fast prototyping of MicroPython, and the predictive power of ensemble Machine Learning, we have created an open-source, edge-to-cloud biometric monitor. This architecture can be easily adapted for sports science, sleep studies, or personal mental health tracking.
Code: https://github.com/kathan-majithia/Smart_Physiological_Monitoring_System
