Go Down

Topic: Getting BPM using sensor pulse (Read 40 times) previous topic - next topic

Bonjor

hey guys…i know its arduino forum, but idont know who to ask..

So i need to measure the heart rate BPM to display on my Blynk.
but the sensor doesn't seems to be responding according to my finger placement. if i put my finger the sensor wont showing anything, the sensor showing some result only when i try tapping the sensor, and it get random BPM.

i got code from https://github.com/vamsikikkuri/Pulse-Sensor IoT/blob/master/Pulse_Sensor_Final.ino.

code tht i use :
#define pulsePin A0
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";//yourauthtoken
char ssid[] = "Pocophone";//name of your wifi
char pass[] = "12345678";//password of wifi

int rate[10];
unsigned long sampleCounter = 0;
unsigned long lastBeatTime = 0;
unsigned long lastTime = 0, N;
int BPM = 0;
int IBI = 0;
int P = 512;
int T = 512;
int thresh = 510;
int amp = 100;
int Signal;
boolean Pulse = false;
boolean firstBeat = true;
boolean secondBeat = true;
boolean QS = false;

void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop() {

Blynk.run();
if (QS == true) {
Serial.println("BPM : "+ String(BPM));
Blynk.virtualWrite(V1, BPM);
QS = false;
} else if (millis() >= (lastTime + 2)) {
readPulse();
lastTime = millis();
}
}

void readPulse() {

Signal = analogRead(pulsePin);
sampleCounter += 2;
int N = sampleCounter - lastBeatTime;

detectSetHighLow();

if (N > 250) {
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI / 5) * 3) )
pulseDetected();
}

if (Signal < thresh && Pulse == true) {
Pulse = false;
amp = P - T;
thresh = amp / 2 + T;
P = thresh;
T = thresh;
}

if (N > 2500) {
thresh = 510;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = true;
}

}

void detectSetHighLow() {

if (Signal < thresh && N > (IBI / 5) * 3) {
if (Signal < T) {
T = Signal;
}
}

if (Signal > thresh && Signal > P) {
P = Signal;
}

}

void pulseDetected() {
Pulse = true;
IBI = sampleCounter - lastBeatTime;
lastBeatTime = sampleCounter;

if (firstBeat) {
firstBeat = false;
return;
}
if (secondBeat) {
secondBeat = false;
for (int i = 0; i <= 9; i++) {
rate = IBI;
}
}

word runningTotal = 0;

for (int i = 0; i <= 8; i++) {
rate = rate[i + 1];
runningTotal += rate;
}

rate[9] = IBI;
runningTotal += rate[9];
runningTotal /= 10;
BPM = 60000 / runningTotal;
QS = true;

}

thank you
PS : sorry if my english bad

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up