Your Heart, Your Data
Milos Rasic built a custom, open source ECG heart monitor using an ESP32-C3 development board and a chest strap with electrodes.
Fitness trackers are not in short supply, so you can buy just about whatever you want off the shelf. But there are plenty of reasons to take the longer path and build your own devices as well. If nothing on the market quite matches your requirements, if you are worried about privacy, or if you are just interested in learning some new things, DIY is the only way to go.
For reasons such as these, engineer Milos Rasic of element14 Presents recently set out to build a custom heart rate monitor. And fortunately for the rest of us, Rasic open sourced all of his work, so we can learn from it, or use it as a base for our own fitness trackers.
The goal was to create a chest-strap-style monitor that measures electrical heart activity via ECG, rather than optical PPG sensors found in most smartwatches. After an initial attempt to design a custom printed circuit board failed due to signal noise, Rasic pivoted to a modular approach for this proof-of-concept build. The processing unit for the monitor is a tiny Seeed Studio XIAO ESP32C3 microcontroller. This board also has a Bluetooth Low Energy radio, allowing it to transmit data directly to standard fitness apps like Strava.
To detect the heart's electrical signals, Rasic employed the widely available AD8232 ECG module. The hardware stack was rounded out with a single lithium-ion battery cell, a switch, and a tiny boost converter to step the voltage up to the required 5V. These components were wired together and housed inside a custom 3D-printed enclosure designed to snap onto standard heart monitor chest straps with electrode pads.
Hardware, however, is only half the battle. Interpreting noisy electrical signals generated by a body in motion requires robust software. For this reason, Rasic implemented the classic Pan-Tompkins algorithm, a method for detecting QRS complexes in ECG signals that dates back to 1985. After prototyping the complex mathematics in Python, he successfully ported the algorithm to C++ for the ESP32 board, aided by AI coding tools to streamline the process.
During a 5K test run, the device successfully connected to Strava and provided heart rate readings, which were paired with measurements from a smartwatch used as a control. There were significant differences between the two devices, suggesting that noise was being introduced somewhere along the way. Rasic is currently working to better understand the source of this noise. There are already plans for a new version of the system, which will likely include onboard microSD data logging and a more advanced ECG chip to better filter out noise.
If you'd rather monitor your heart rate with Wi-Fi, check out this DIY project.