Build your own pulsemeter
Close to Your Heart

© Lead Image © Nelli Valova, 123RF.com
A pulsemeter built with a Raspberry Pi, a digital-to-analog converter, and an optical sensor monitors your heart rate just as well as many far more expensive medical devices.
Monitoring your pulse helps you determine the health of your vascular system. If you are interested in fitness, it is one of the vital metrics in sports monitoring. Whether you are taking measurements out of scientific interest, as a metric to gauge the intensity of your workout, as a measure of fitness, or as a cautionary measure against excessive stress, a DIY pulsemeter provides quick and easy feedback.
The module used in the example here is based on an optical method that measures light absorption of the red blood cells in your veins to determine the rhythm of your heartbeat. Typically, you will want to deploy sensors like this at the wrist, the arch of the foot, temple, or neck, where the veins are just under the skin.
The sensor has an operating voltage of 3-5V, and the output voltage varies depending on how well you position the sensor. Occasionally, it will not output a value at all (e.g., if you press it against the skin so hard that it blocks the blood flow).
While taking a measurement, you should keep the sensor in the same position. The pulse sensor [1] uses green light, which is best suited for measuring at the wrist. Modules with red light, on the other hand, are used for fingertip measurements. The accuracy of the optical sensors is almost equivalent to that of an ECG.
Test Setup
Before setting up the test, you should note that the sensor provides analog values, whereas the Raspberry Pi only processes digital values. Therefore, you need an analog-to-digital converter (ADC). My choice was the MCP3008 [2], because its 10-bit resolution measures with sufficient accuracy.
The schematic (Figure 1) for the test setup is quite clear: It comprises only the MCP3008 ADC, which you connect to the Raspberry Pi through the serial peripheral interface (SPI; specifically, pins 19, 21, 23, and 24), and the sensor, which is connected to the MCP3008 analog input (CH0).

In my tests, I used two different oscilloscopes to monitor the analog values provided by the sensor, so I could get a feel for the pressure needed to get correct readings. In one test, I connected a BitScope Micro [3] to my desktop PC via USB, with the BitScope input channel connected to the S output of the pulse sensor.
The output is shown in the BitScope Meter software [4] (Figure 2). The 1.4Hz output frequency corresponds to a pulse of 84 beats per minute. The hertz unit (Hz) indicates the measured oscillations per second; multiply this value by 60 to get the oscillations per minute.

BitScope is an interesting mini-oscilloscope for your PC. If you don't have a BitScope, though, you can use any oscilloscope (in Figure 3, I use a DSO138 kit [5]) to monitor the signal of the sensor.
Software
A current Raspbian Stretch Lite [6] provides the underpinnings of this project. After downloading, write it to an SD card with a tool of your choice. After booting, start the raspi-config
tool and activate the Rasp Pi's SPI under 5 Interfacing Options | P4 SPI. This setting is required to control the MCP3008.
Additionally, enable the SSH service under 5 Interfacing Options | P2 SSH. Once running, you will be able to manage the Raspberry Pi with PuTTY [7] or from a desktop terminal.
Last but not least, you will want change the password for the pi
account, either in raspi-config
or with the passwd
command. Running the commands in Listing 1 updates the software and installs all the programs you need to control the sensor. To ensure that you have loaded all components correctly, reboot the computer and launch the sample program (Listing 2), which is available on GitHub [8].
Listing 1
Install and Update Software
sudo apt update sudo apt upgrade sudo apt install git python-dev git clone https://github.com/doceme/py-spidev.git cd py-spidev/ sudo python setup.py install cd .. git clone https://github.com/tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor
Listing 2
Sample Program
$ cd Raspberry Pi Heartbeat Pulse Sensor $ python example.py No Heartbeat found BPM: 80 BPM: 80 BPM: 83 BPM: 85
Conclusions
The pulse sensor presented here works quite accurately. Initially, you might need some time to figure out the pressure needed at the sensor to get clean readings. A small oscilloscope helps to get the desired result.
Infos
- Pulse sensor: https://www.sparkfun.com/products/11574
- MCP3008: https://www.adafruit.com/product/856
- BitScope Micro: https://www.bitscope.com/product/BS05/
- BitScope Meter: http://www.bitscope.com/software/meter/
- Oscilloscope kit: https://www.nooelec.com/store/dso138.html
- Raspbian Stretch Lite: https://www.raspberrypi.org/downloads/raspbian/
- PuTTY: https://putty.org
- example.py code:https://github.com/tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
PipeWire 1.0 Officially Released
PipeWire was created to take the place of the oft-troubled PulseAudio and has finally reached the 1.0 status as a major update with plenty of improvements and the usual bug fixes.
-
Rocky Linux 9.3 is Available for Download
The latest version of the RHEL alternative is now available and brings back cloud and container images for ppc64le along with plenty of new features and fixes.
-
Ubuntu Budgie Shifts How to Tackle Wayland
Ubuntu Budgie has yet to make the switch to Wayland but with a change in approaches, they're finally on track to making it happen.
-
TUXEDO's New Ultraportable Linux Workstation Released
The TUXEDO Pulse 14 blends portability with power, thanks to the AMD Ryzen 7 7840HS CPU.
-
AlmaLinux Will No Longer Be "Just Another RHEL Clone"
With the release of AlmaLinux 9.3, the distribution will be built entirely from upstream sources.
-
elementary OS 8 Has a Big Surprise in Store
When elementary OS 8 finally arrives, it will not only be based on Ubuntu 24.04 but it will also default to Wayland for better performance and security.
-
OpenELA Releases Enterprise Linux Source Code
With Red Hat restricting the source for RHEL, it was only a matter of time before those who depended on that source struck out on their own.
-
StripedFly Malware Hiding in Plain Sight as a Cryptocurrency Miner
A rather deceptive piece of malware has infected 1 million Windows and Linux hosts since 2017.
-
Experimental Wayland Support Planned for Linux Mint 21.3
As with most Linux distributions, the migration to Wayland is in full force. While some distributions have already made the move, Linux Mint has been a bit slower to do so.
-
Window Maker Live 0.96.0-0 Released
If you're a fan of the Window Maker window manager, there's a new official release of the Linux distribution that champions the old-school user interface.