DFRobot Heart Rate Sensor

I have a DFRobot Heart Rate Sensor. I have a working code but am having trouble making the sensor work. Any suggestions?

2 Likes

Hello Ella,

Welcome to the forum! What’s the microcontroller and interface that you’re using with the Heart Rate Sensor? Could you please also put up some photos of the sensor and its connections to your project, that’ll be very helpful in troubleshooting. Thanks

Bryce
Core Electronics | Support

Hi Ella,

I think I answered a call about this one. I believe you’re using a PPG Sensor from DF Robot: https://core-electronics.com.au/gravity-heart-rate-monitor-sensor-for-arduino.html ?

I believe he said the on-board LED would blink a few times, detecting a pulse but then stop?

As Bryce said, if you could share the code you’re using and give us some photos of how you’ve got it all wired up and being used that would be fantastic! The more relevant info you can provide us, the better.

Regards,
Oliver
Support | Core Electronics

1 Like

Hello,

I am using an arduino uno with a shield;

Here is the code I have been using;

#define heartratePin A1
#include “DFRobot_Heartrate.h”

DFRobot_Heartrate heartrate(DIGITAL_MODE);

void setup() {
Serial.begin(115200);
}

void loop() {
uint8_t rateValue;
heartrate.getValue(heartratePin);
rateValue = heartrate.getRate();
if(rateValue) {
Serial.println(rateValue);
}
delay(20);
}

Thanks!

Hi Ella,

In the photo it looks like you’ve left the switch on the sensor set to A for Analogue mode. Can you try switching it to D and testing again?

Regards,
Oliver
Support | Core Electronics

1 Like

Hey Ella,

Here’s another test you can perform, if you can upload and run this very simple script that I’ve written below so we can check to see whether there’s a proper output from the sensor that should assist in troubleshooting (Note: You can use CTRL+SHIFT+L to access the serial plotter to graph this output).

#define READ_PIN A1

void setup() {
  Serial.begin(9600);
  pinMode(READ_PIN, INPUT);
}

void loop() {
  Serial.println(analogRead(READ_PIN));
  delay(20);
}

Bryce
Core Electronics | Support

1 Like

Hey Bryce,

I have tried that code but it appears to be returning similar results as seen in the photo.

Thanks Ella

Hey Oliver,

When in Digital mode it returns special characters rather than numbers (eg ??YK).

Thanks Ella

Ella, looks like your code is for digital mode at a baud rate of 115200. Have you set the serial monitor to this baud rate or did you leave it at 9600 when testing in digital mode?

With Bryce’s code, you’ll need to make sure you set the switch on the sensor back to analogue mode. It looks like you might have left it in digital mode judging by that data trace jumping between 0v and 5v (1023).

Hi Oliver,

When set to 9600 it says “Waiting for valid data!” in both analogue and digital mode. It continues to return special characters in digital mode, is this an error further down in my code?

I have switched it back to analogue mode and tested Bryce’s code and it appears to be working now!

image

Thanks Ella

1 Like

Hi Ella,

Glad to see it’s at least partially working! I’ve looked at the DFRobot_Heartrate library to get a handle on how it’s determining heartbeats and when it shows .“Wait for valid data !”

Expectedly, it is relatively simplistic. It determines that a heartbeat has started when the voltage reading increases 4x in a row, and determines a heartbeat has stopped after the reading decreases 4x in a row.

In analogue mode it needs the 4th and 8th beats t measures to be less than 150 bpm different, and it needs to measure at least 10 heartbeats before it will show a reading.

In digital mode,it needs the 4th and 8th beats it measures to be less than 120bpm different, and it needs to measure at least 10 heartbeats before it will show a reading.

All this just means that when using the sample code you need to sit very still for at least 20 seconds before you can expect to get a reading when using the example code from the DFRobot wiki.

The heart rate it returns is a moving average of 5 heartbeats, (your second last and 7th last heart beats).

I haven’t followed the algorithm super carefully, but this appears to be how it works. I hope this helps!

Regards,
Oliver
Support | Core Electronics

3 Likes

Hi Oliver,

I will do a few test using that theory and see if anything pays off!

Thanks Ella

4 Likes