The Raspberry Pi is increasingly being used in health applications – here’s how one maker made his own DIY Pi health device: Heartbeat Monitor.
You can tell a lot of things from a heartbeat, so Daniel Fernandez has decided to create his own heart tracker with help from a Raspberry Pi.
The current surge of smart watches, however long it lasts, probably owes something to the activity trackers that are synonymous with anyone trying to keep track of their fitness. These devices track the user’s heartbeat and use it to calculate things like periods of rest, calories burnt, and more.
This article first appeared in The MagPi Issue #55. Click here to download a free copy of The MagPi magazine.
Build a Heartbeat Monitor from a Raspberry Pi
“I have always liked to monitor my heartbeat while I run on the treadmill,” Daniel tells us. “There is simply no cheap, commercial solution that did everything I wanted: to plot the results in a graph that’s easy to monitor, so that you can look at them while you run, and then save the data so that you can work with it later. Furthermore, I wanted some flexibility in how the data was plotted and how often the heartbeat was updated, and to be able to retrieve the data from the device in an easy-to-process format like CSV.”
So began Daniel’s build. He selected the Raspberry Pi 3 as it was a fully fledged computer with built-in Bluetooth that could fit on his treadmill. He coupled it with a Polar H7 heart sensor and a 3.5˝ screen, and 3D-printed a little case to fit it all in.
“It’s not very difficult to build as most of the project is based on software,” explains Daniel. “If you have the sensor, screen, and software, you could have it working in less than a few hours. I have made the software open source and available via a GitHub repository.”
Using a Raspberry Pi fitness device
He’s been successfully using it for its intended purpose, having run 20 miles with it since he finished the project.
“So far, the Raspberry Pi has always worked correctly with my heartbeat sensor,” Daniel says. “The program has always provided smooth plots and a very responsive display of my real-time heartbeat. I have been able to save my run data files and perform some more extensive mathematical analysis to better understand how my heart reacts to changes in intensity, cadence, inclination, and so on.
- Starting up: When the Pi boots up, it loads up a Python script that checks the heartbeat data from the sensor, and a Free Pascal program that plots the data.
- Sending data: The heartbeat monitor automatically connects to the Pi and sends heartbeat data to the Python script. It’s saved to a text file, which is used to plot the results.
- Saved: A reset button on the display resets the plot and saves the on-screen data to a CSV file for analysis at a later date.
“I would want to include some functionality to save my heartbeat files to my Dropbox and even have the option to share the data on my social media accounts when I finish each run. I was also thinking about connecting the treadmill’s control panel to the Raspberry Pi so that the treadmill could adjust intensity automatically to match a target heartbeat.”
Other heartbeat sensors that follow the same standard as the Polar H7 should work with the project if you decide to make your own. Maybe it’s a good excuse to keep up with your New Year’s resolution?
Heartbeat Monitor facts
- It took two days for Daniel to develop the software
- Daniel wants to make an open-source voice assistant
- If you use the project, make sure the code launches at boot
- Daniel is an old hand with the Raspberry Pi, using it to automate several projects
- The case is to protect the Pi from sweat and spilt water