Raspberry Pi Heartbeat / Pulse measuring

Not only with fitness watches, but also with the Raspberry Pi it is possible to measure pulse / heart rates. With a small module – the Raspberry Pi pulse sensor – you can easily measure your own pulse and thus monitor permanently your health condition. This sensor can also be used in mobile Raspberry Pi applications (fitness tracker project? ;-)) thanks to low power consumption.

What is still needed and which libraries can be used are shown in this tutorial.

Heart Rate Monitor Accessories

The Raspberry Pi pulse sensor can not be read out digitally, thus we need an analog-to-digital converter. Such an ADC makes it possible to read out analog signals on the Raspberry Pi because. Unlike the Arduino, the Pi has no integrated analog IO pins.

I used the following components in the video below:

  • Heart rate Pulse sensor: US / UK
  • MCP3008 ADC: US / UK
  • Small Breadboard: US / UK
  • Jumper Wire: US / UK

Some sensors are shipped with a Velcro fastener for the finger, which is advantageous for the measurement, since there is not too much pressure on the finger.


Raspberry Pi Heart Rate Monitor – Connection

Since this sensor has also been designed for the Arduino, it does not provide a digitally readable signal. In order to be able to read the analogue signal, an ADC such as the MCP3008 is required. It doesn’t matter which channel of the ADC you are using, as long as you adjust it later in the code.

The positive pole of the pulse sensor is connected to 3.3V from the Raspberry Pi, as well as Minus to Ground. I have connected the signal / data pin (marked with an “S”) to channel 0 of the MCP3008.


The ADC uses the SpiDev library, which must be installed.


Code for reading the Heart / Pulse Rate

If you don’t use a current Raspbian / NOOBS operating system, you may need to update and install git.

sudo apt-get update
sudo apt-get upgrade sudo apt-get install git

On GitHub I have provided a library for recording the heart rate. You can download it as follows:

git clone https://github.com/tutRPi/Raspberry-Pi-Heartbeat-Pulse-Sensor

Also attached is a sample file, which reads the heart rate every second. In the video below you can see this visualized.
To start the example we switch to the folder and call the example.py.

cd Raspberry-Pi-Heartbeat-Pulse-Sensor/
sudo python example.py

If you want to stop, press CTRL+C.

If you look at the example more closely, you will find that with p.startAsyncBPM() a thread is started, which measures the pulse in the background. By p.stopAsyncBPM() you can stop this thread – and thus the measurement. Feel free to customize the code.


Raspberry Pi Pulse Sensor Example and Extension

In the following video I have run the sample file and the measurement of my pulse is shown. Before that, I measured my heart rate with my smartphone (integrated heart rate monitor), which showed me a resting pulse of 55 BPM.


As you can see, the measurement is not always accurate, especially if the finger does not touch the pulse sensor. Here, one could use an additional pressure sensor or something similar. Then, it should only measure if you are sure that the finger touches the pulse sensor. It also takes a few seconds for the pulse to be recorded correctly, but this is not the case with commercially available pulse meters.


For the module (originally developed for Arduino), there is also some sample code. In addition, there is a nice visualisation of the values on Github. It should not be too much effort to customize these files for my library. If you want to change the code, you may also change my library according to the requirements. I would be happy about a comment 🙂

Raspberry Pi Puls Heartbeat Monitor

The data provide a better overview of the pulse history, when visualized.


67 Responses

  1. Traceback (most recent call last):
    File “example.py”, line 4, in
    p = Pulsesensor()
    File “/home/pi/Raspberry-Pi-Heartbeat-Pulse-Sensor/pulsesensor.py”, line 11, in __init__
    self.adc = MCP3008(bus, device)
    File “/home/pi/Raspberry-Pi-Heartbeat-Pulse-Sensor/MCP3008.py”, line 18, in __init__
    File “/home/pi/Raspberry-Pi-Heartbeat-Pulse-Sensor/MCP3008.py”, line 21, in open
    self.spi.open(self.bus, self.device)
    IOError: [Errno 2] No such file or directory

    I am getting these errors. what is the problem??? PLEASE HELP!!

  2. My set up does not read the heart rate reliably. The bmp jumps all over the place. Can anyone help?

  3. I’m trying to put this together and having a little trouble. I have spidev installed and everything else running as it should. Are there any code modifications necessary? Any help would be greatly appreciated.

  4. Hello I need some help. Sensor always showing no heartbeat found.
    Can you please help.

  5. Hi,

    I am trying this out. I am able to see variation in the signal, however they are not consistent. I am able to confirm MCP3008 is processing signals when I send in a specific signal through a variable resistor. That channel shows consistent signal out.
    Bu when I connect the pulse sensor, reading shows values at random and looks like they jump all over.
    Question is, is there a way that the pulse sensor and the MCP3008 are working as it should?

    • Same issue here. I do have receive the signal through the example code above,however the BMP fluctuate around 220 even though the sensor was attached to nothing. Any help plz 🙂

  6. Hi, I have followed your tutorial and it works initially, but it could not read bpm and shows “No heartbeat found” after i format my sd card with the latest Raspbian, can you help me with this problem?

  7. How can I use Ad8232 sensor with raspberry pi 3b . I have also mcp3008 adc

  8. I have connected everything exactly as you have suggested, installed everything that you asked. It wont work anyways. Please help.

    Using Raspberry Pi 3 with this module.

  9. Has anybody find a solution using the raspberry pi 3? I am getting “No Heartbeat found”

    • Thank you!! It worked , but…… The values are highly fluctuating like
      Like this.
      Could you please reply, what to do?

  10. Hi.. I am facing the same issue..value fluctuate around 220 and also it shows value when it is not touched.. how to fix it..? can anyone please help ?

  11. Hi,
    I having trouble actually connecting it all together i have a raspberry pi and all the attachments needed but having difficultly putting them together.
    Can anyone help.? step by step would be great.
    Thanks in advance

  12. Hello,
    I have set up the circuit as instructed and also the code is set. I am getting values, but the values hike all of a sudden eg : 70 to 115, detect beats even when no finger is pressed. Can anyone help me with the false signals.

  13. hello I have to use High-Precision AD/DA Board for the same project. i dont know how start with it. can anyone help me.

  14. No heartbeat found. Mcp 3008 working correctly with lm35 sensor but not with heart rate sensor.. please help me… I am stucked….

  15. i tryed self.spi.max_speed_hz = 13500000 but my values is very high and when i try to download i see my bcm2835 is that why the problem ?


Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!