Join Milos as he puts together an open source heart rate monitor built around an ECG front end and an ESP32 C3, then takes it out for a run to see how it performs next to his everyday fitness gear. He walks through the signal processing, the BLE connection to his phone and the real world results from a full workout. It is a hands on build that shows what works, what drifts and what he plans to improve in the next version.
Time to Get Running!
Please note: Due to the nature of this project, it does involve placing electrodes onto the skin. The design of this project is intended with opto-isolation to prevent problems involving electricity and voltage levels, if you choose to recreate this project, you do so at your own risk and with the understanding that you're expected to have appropriate training and be a sufficiently 'competent' person. This project is also not presented with any health or medical certifications and as such is 'proof of concept' and not expected to be used in any official capacity as a medical device.
In this video, Milos went for a run! Before he did that though, he decided he wanted to try making his own heart rate tracker for running using an AD8232 ECG module and a XIAO ESP32 C3 microcontroller. The device sends the heart rate data to a phone over BLE and is recognized as a heart rate tracker by all fitness apps like Strava!

Idea and Plan
For a little while now Milos has gotten into running and he likes to keep track of his heart rate while he does that. He started off by using a smartwatch that has a built in PPG sensor, but later switched over to a chest strap with a heart rate sensor that measures electrical activity. He got curious to how hard it would be to make his own, and this is what he tries tackling in this video. He decided to make his device compatible with the chest strap that most other running tracker use as well.

To begin his work on this project, Milos decided to start off by selecting an AFE (Analog Front End) IC and go from there. He decided on using the AD8232 since it’s a popular IC because of the ECG module and because he already used in a previous project in his Open Cardiography Signal Measuring Device:
Building an Open Source Blood Pressure & Heart Signal Monitor -- Episode 674
The initial plan was for him to design a PCB using this IC, a Raspberry Pi Pico and a bunch of other things he wanted to try out like wireless charging and a microSD card slot, but in the end the ECG section on the PCB didn’t work. He tried resoldering multiple times and doing any modifications that came to his mind, but in the end, the signal he would get from the board just wasn’t good enough. At that point, he knew he had to do a full redesign of the PCB but decided to first try making a fully DIY version using small modules so he can test out the software side. Because of this, he decided to go with the AD8232 module and a XIAO ESP32 C3 MCU. Both are small, and the XIAO board provides really good BLE capabilities which is what he needed to send the data to the phone. Besides these two modules, the only other things that are needed are a battery, a switch and a small boost converter to increase the battery voltage to 5V.

Before putting the chest strap and going for a run, the hard part of the project had to be completed, the software. This includes first getting the data acquistion working properly and then trying to implement an algorithm to calculate the heart rate from the ECG signal. Below are pictures of the captured ECG signal using the modules described above.


Pan Tompkins
The Pan Tompkins algorithm is one of the most significant and widely used methods for ECG signal processing. It originates from a paper titled “A Real-Time QRS Detection Algorithm” that was published by Jiapu Pan and Willis J. Tompkins in 1985. The full paper can be viewed for free on the following link:
https://www.robots.ox.ac.uk/~gari/teaching/cdt/A3/readings/ECG/Pan+Tompkins.pdf
Because of the significance of this algorithm and paper, and the fact that it’s still a widely used method even though it has been 40 years since the paper was published, Milos decided to implement it in his project. This was by far the most challenging part of the project because he wanted to go step by step to get a good understanding of how the algorithm works.

In the video, he goes into a lot of detail first explaining on a drawing the whole process of the algorithm and then shows the implementation that he has written in Python in Google Colaboratory. For more details, check the full video. The final results from his PT integration can be seen in the two figures below.
To convert the whole algorithm from Python to C++ so he could use it on his ESP32 board, he decided to try using Cursor AI for the first time, which turned out to be a pretty good experience, since he managed to generate code by feeding it his PanTompkins Python script and the ESP codes for sampling the data and sending the data over BLE. While there were mistakes initially, they were relatively easy to fix!


Results
While the results looked promising on a really clean signal, it was now time for Milos to test it out on a run. He went for an easy 5K in his neighborhood wearing the device he made as well as he smartwatch as a control device (even though the smartwatch itself isn’t that super accurate as Milos notes in the video). To analyze the data, he recorded his run using Strava, which is one of the more popular fitness tracking apps. Strava initially recoreded the run using the ESP32 heart rate running tracker, but also records another parallel session that gets later added to strava because of a third party app to which the smartwatch is connected. In that way, Milos double recoreded the same activity with the only difference being the heart rate sensor. This was perfect for actually comparing the results, and if you go to your activity in Strava using a browser, you can actually download the whole activity as a FIT file and analyze it further using Python! Here is the heart rate data from his smart watch and the ESP32 Heart rate tracker.


While there are some similarities when you look at the signal, it is clear that they don’t match up properly. This is even more evident if we put both signals on the same graph. You can see that the ESP32 Heart rate tracker followed the smart watch pretty good in the beginning and in some sections, but in others, the readings were just off.

If we zoom in on certain segments, we can see that there are times when we can say both devices were essentially showing the same heart rate (within some amount of tolerance of course), while at other times, there really wasn’t much correlation between the two signals. Both cases can be seen in the figures below.


Since not even the smartwatch can be fully trusted and since Milos couldn’t see the raw data, he couldn’t determine the exact point where the algorithm was failing, or whether this was just to the input signal being too noisy. To determine that, he said he would need to make a device with proper data logging capabilities and with an AFE IC that could accomplish this task better than the AD8232 using two electrodes.
Milos is still happy with the results he got, the Pan Tompkins algorithm worked on the signals he put it through and the device was recognized without any issues by the fintess tracking apps. His next goal is to redesign a PCB with a different AFE IC and also add a microSD card slot for data logging so he could properly analyze the data. These are all plans for the V2 of this project, if you have any other ideas that you would like him to add to the heart rate fitness tracker, leave them in the comments below and you might see them pop in the next video!
Supporting Files and Links
- https://www.robots.ox.ac.uk/~gari/teaching/cdt/A3/readings/ECG/Pan+Tompkins.pdf
- Building an Open Source Blood Pressure & Heart Signal Monitor -- Episode 674
Bill of Materials
| Product Name | Manufacturer | Quantity | Buy Kit |
|---|---|---|---|
| XIAO ESP32C3 - 113991054 | SEEED STUDIO | 1 | Buy Now |
| AD8232 ECG Module - SEN0213 | DFROBOT | 1 | Buy Now |
| White PLA - MC002554 | MULTICOMP PRO | 1 | Buy Now |
Additional Parts
| Product Name | Manufacturer | Quantity |
|---|---|---|
| Wires | ||
| Snap Buttons | ||
| Heart Monitor Chest Strap | ||
| 1S LION/LIPO Cell | ||
| Tiny Boost Converter |