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 🙂
97 Comments
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__
self.open()
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!!
I think you haven’t installed spidev.
thanks bro… It worked… But it shows garbage values even if not touched… What is the solution????
It gives always 228,229 and 230 values. I think calculation is wrong…. !!!!
Why? See the video 🙂
Hello, even I am getting the same error… how do I fix it??
Im still havin this issue even after installing SpiDev !!!
Can someone help!!
enable SPI in Raspberry pi by preference>Raspberry pi configuration > Interfaces
Check Enable respective to SPI
welcome..!!
Hi bro im using High-Precision AD/DA Board instead of MCP3008. Do u have solution for it.
I’m also getting the same problem but I already installed spidev. Please help!!!
Same problem for me. How to solve it???????
My set up does not read the heart rate reliably. The bmp jumps all over the place. Can anyone help?
same problem for me too
for me too
Hello! could you solve the problem?
The Pulse Sensor you are using is a knock-off of the original.
Support the original makers by purchasing their products
http://www.pulsesensor.com
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.
Hello..my sensor show zero value pulse..can anyone help?
I am also having same problem. Can someone please help?
my output values always gives zero “0”. Please help me ?
kindly can you give me the source code for heart beat rate monitoring
It is all on github (see the link).
any code to run in c…
Hello I need some help. Sensor always showing no heartbeat found.
Can you please help.
I’m having the same problem too..Did you find the reason?
same here
It is the same for me, “no heartbeat found”. Anyone who can help, please?
I have the same problem.It is showing no heartbeat found.Any solution for it?
i had found the same error no heartbeat found did you find the solution please help
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 🙂
Hi, I have the same problem, did you find a solution plz??
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?
Le Jia, I have the same problem like you, did you found what is wrong ?
Use Wheezy instead of raspbian jessie
Can grove ear clip heart rate sensor be used instead of heart rate pulse sensor?
Have you a link to that sensor?
How can I use Ad8232 sensor with raspberry pi 3b . I have also mcp3008 adc
iam also using the same components… can you help me?pleaseeeeee
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.
Has anybody find a solution using the raspberry pi 3? I am getting “No Heartbeat found”
I am getting ‘No Heartbeat found’ msg always
Had a similar “No Heartbeat found” issue.
Works after adding this to MCP3008 code module before spi.xfer2 line
spi.max_speed_hz = 1350000
Found the solution here:
https://www.raspberrypi.org/forums/viewtopic.php?t=115971
Reducing 1350000 to 700000 also works.
Thank you!! It worked , but…… The values are highly fluctuating like
65
88
99
140
186
Like this.
Could you please reply, what to do?
did you ever find out how to fix this?
hi, i got a similar problem with u but when i adding the spi.max_speed_hz = 1350000 i got an error that “spi” is not defined?
use this.spi insted of spi
No Heartbeat found
BPM: 47
BPM: 47
No Heartbeat found
No Heartbeat found
No Heartbeat found
No Heartbeat found
No Heartbeat found
No Heartbeat found
No Heartbeat found
BPM: 50
BPM: 52
BPM: 76
BPM: 144
BPM: 233
BPM: 231
BPM: 230
BPM: 230
BPM: 230
BPM: 228
BPM: 228
BPM: 229
BPM: 231
BPM: 231
BPM: 231
BPM: 239
BPM: 239
BPM: 239
No Heartbeat found
It really worked for me too….thank you
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 ?
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
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.
did you ever find out how to fix this?
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.
No heartbeat found. Mcp 3008 working correctly with lm35 sensor but not with heart rate sensor.. please help me… I am stucked….
how to measure heart rate by this sensor help of arduino uno
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 ?
Every time I run the code it says ‘No Hearbeat Found’and I’ve tried changing the code and switching sensors but it’s still the same.
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__
self.open()
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
Im using mcp3208 and it come this error pls help me
sudo raspi-config
turn on the SPI
thanks, put now I run the code it says ‘No Hearbeat Found’ what the solution pls help
Can someone help me set up the pins in the program? I am very confused because I have just started working with RaspberryPi. I just want someone to send me a code with which pins I connect what to
heyy did you get the code working?
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__
self.open()
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
This error still occurs even though i have turned on my SPI and installed Spidev, anybody can help me please T.T I beg you
can you read pulsations from your hands palm ?
I’m getting ‘no Heatbeat found’ msg every time. I’m unable to read the signal from MCP3008. could anyone plz help me out
I tried all advices but still I got ‘No Heartbeat Found’ message. What can I do now?
Can some one help me
I’m using ADS1115 with Pulse sensor .
How can i connect pulse sensor with ads1115. its my first time and i’m dont understand how to start it.
kindly help me it will be big help in final year project.
Thnaks in advance …!!!!!
Read the comments and made the changes, works good,getting consistent values.
Below is the code block:
def read(self, channel = 0):
self.spi.max_speed_hz = 1350000
adc = self.spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
Still got msg ‘ No heartbeat Found’ any alternative solution?
No Heartbeat found
No Heartbeat found
No Heartbeat found
No Heartbeat found
BPM: 41
BPM: 41
BPM: 41
BPM: 46
BPM: 53
BPM: 91
BPM: 168
BPM: 230
BPM: 231
BPM: 230
BPM: 230
BPM: 231
BPM: 230
BPM: 230
BPM: 230
BPM: 231
BPM: 230
BPM: 230
BPM: 230
BPM: 230
BPM: 230
BPM: 230
BPM: 203
BPM: 203
BPM: 203
BPM: 229
value will raise sudden why?
Can you check the voltage?
I can give only 3.5 v
No heartbeat found – tried code changes mentioned above (PI 4 b)
i got result no heartbeat found.ithink i’m mistake between breadboard and raspberry pi.plz. show me real connection picture.Thank you so much
excuce me, can you help me I just followed your way, but the phrase appears not found
It worked for me when I swapped to the 5 volts pin… but before you do that just make sure your pulsemeter can handle 5 volts
My pulse sensor doesn’t glow what should I do??