hi guys i need your help please.
Ok so i am using pulse sensor like https://cdn.sparkfun.com//assets/parts/7/5/5/9/11574-02.jpg
i need to measure the heart rate beat per min to display on my Blynk terminal widget…
i keep on getting extreme value and the sensor doesn’t seems to be responding according to my finger placement… if i didn’t put my finger onto the sensor , it still showing beat per min … and the result seems to be weird… showing 1.xx beat per minute or 4.xx beat per minute…
i have my code reference through arduino uno - Getting BPM from the given code - Arduino Stack Exchange
i cant use the two- timer setting , it may cause my other sensors (not pulse sensor) to run too fast
i cant use serial printer because i am using USB connection for my blynk app…
and my baud rate are 9600 cannot be higher or lower since i have other sensor running with this pulse sensor at the same time…
P/S: i will add in anything that i missed out when i realised later on.
#include <BlynkSimpleStream.h>
char auth [] = "my token";
//Declare the variables
int UpperThreshold = 518;
int LowerThreshold = 490;
int reading = 0;
float BPM = 0.0;
bool IgnoreReading = false;
bool FirstPulseDetected = false;
unsigned long FirstPulseTime = 0;
unsigned long SecondPulseTime = 0;
unsigned long PulseInterval = 0;
void setup()
{
Serial.begin(9600); //BaudRate
Blynk.begin(Serial, auth);
}
void loop()
{
reading = analogRead(0);
// Heart beat leading edge detected.
if(reading > UpperThreshold && IgnoreReading == false){
if(FirstPulseDetected == false){
FirstPulseTime = millis();
FirstPulseDetected = true;
}
else{
SecondPulseTime = millis();
PulseInterval = SecondPulseTime - FirstPulseTime;
FirstPulseTime = SecondPulseTime;
}
IgnoreReading = true;
}
// Heart beat trailing edge detected.
if(reading < LowerThreshold){
IgnoreReading = false;
}
BPM = (1.0/PulseInterval) * 60.0 * 1000 ;
Blynk.virtualWrite(V7, "\n Heart Rate =", BPM);
Blynk.virtualWrite(V7, " BPM");
}