[Updated]
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 https://arduino.stackexchange.com/questions/43956/getting-bpm-from-the-given-code
i cant use two timer method because it cause my other sensor(not pulse sensor) to run too fast.
(when i do the testing without blynk code):
if i use the coding without two timer, it show INF BPM in serial monitor
if i use two timer coding, it showing 2xx BPM up to 3000+ BPM in serial monitor …
so for testing purpose, i decided to test the output in serial monitor
and i deleted everything in the loop fn except analogRead and serialprint…
when i place my finger onto the sensor, i show 0 value reading whereas i lift my hand up (nothing on sensor) will show 995 value reading…
hmm…
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 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");
}