HeartStream: Real-Time ECG Monitoring and AI Analysis Using ESP8266 & Deep Learning


π Introduction
In todayβs healthcare landscape, early detection of heart anomalies can save lives. With that vision, I created HeartStream, a real-time ECG monitoring system powered by ESP8266, AD8232 ECG sensor, and an AI-driven backend built using PyTorch. The model is trained on the MIT-BIH Arrhythmia Database and achieves an impressive 99.7% accuracy in detecting 5 classes of heartbeats.
Try the live app here: heartstream.streamlit.app
π Project Architecture
Hardware:
ESP8266 NodeMCU
AD8232 ECG Sensor (single-lead)
ECG Electrodes (Red-Yellow-Green placement)
Software:
ECGNet Model (PyTorch)
ThingSpeak (Cloud Sync)
Streamlit (Frontend Web App)
FastAPI Websocket Server
GitHub Repo
π§ ECGNet: Custom Deep Learning Model
HeartStream uses a 1D Convolutional Neural Network called ECGNet. It has been trained on the gold-standard MIT-BIH Arrhythmia Database and identifies 5 different heartbeat types.
π Accuracy and Results
Overall Accuracy: 99.7%
Test Samples: 22,530
Macro Avg: Precision: 98%, Recall: 98%, F1: 98%
Per-Class Breakdown:
Normal: 100% precision & recall
LBBB/RBBB: 100% precision, 99% recall
APB: 91% precision, 93% recall
PVC: 97% precision, 98% recall
Confusion Matrix:
Model saved as: best_model.pth
π Dataset: MIT-BIH Arrhythmia
Records Used: 100-124, 200-234
Sampling Rate: 250Hz
Preprocessing: Standardized with
StandardScaler
Beat Segment Size: 250 samples (1 second)
Classes:
Normal (N)
LBBB (L)
RBBB (R)
APB (A)
PVC (V)
More info: MIT-BIH on PhysioNet
π Real-Time Monitoring with ESP8266
The ESP8266 sends ECG values from the AD8232 sensor to the ThingSpeak cloud every second. The data is visualized and analyzed live on the web app.
Workflow:
Sensor collects ECG signal (analog)
ESP8266 transmits to ThingSpeak
Streamlit app fetches recent data
AI backend predicts the ECG beat class
Visual + Diagnostic report is shown to user
π Features of HeartStream
β Real-time ECG waveform from Arduino Serial Plotter
β Live ECG + BPM chart from ThingSpeak
β AI-powered Arrhythmia classification
β Diagnostic PDF Report
β AI chatbot for basic explanation (on roadmap)
π Hardware Setup
AD8232 connected to ESP8266 A0
GND and 3.3V supply
ECG electrodes: Red (RA), Yellow (LA), Green (LL)
View the hardware setup and demonstration: Real-Time ECG Monitoring
π Performance Metrics Snapshot
Accuracy : 99.7%
Precision : 99%
Recall : 99%
F1-Score : 99%
Total Test Samples: 22,530
π Try It Yourself
GitHub: HeartStream Code
Demo: Watch on YouTube
MIT-BIH Dataset: PhysioNet MIT-BIH
π Future Improvements
Add multi-lead ECG support (12-lead mapping)
Use RNN/Attention-based architectures (e.g., AttentionECG)
Alert system via Telegram or WhatsApp
Upload ECG PDF to cloud
π Let's Connect!
Hashnode: @ayushilathiya
Portfolio: ayushilathiya.xyz
LinkedIn: Ayushi Lathiya
Thanks for reading! Stay healthy β₯ and keep building π
Subscribe to my newsletter
Read articles from Ayushi Lathiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
