0

I am new to arduino and trying to display the heart rate (BPM) using Pulse sensor. I have found a code from internet that calculates the heart rate:

#include <Wire.h>
#include <LiquidCrystal.h> 

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 
   double alpha=0.75;
   int period=20;
   double refresh=0.0;

void setup(void)
{
   pinMode(A0,INPUT);
   lcd.begin(16,2);
//   lcd.backlight(); //Uncomment when using a I2C
   lcd.clear();
   lcd.setCursor(0,0);
}

void loop(void)
{
   static double oldValue=0;
   static double oldrefresh=0;

   int beat=analogRead(A0);

   double value=alpha*oldValue+(0-alpha)*beat;
   refresh=value-oldValue;

   lcd.setCursor(0,0);
   lcd.print(" Heart Monitor "); 
   lcd.setCursor(0,1);
   lcd.print("          ");
   lcd.setCursor(0,1); 
   lcd.print(beat/10);
   oldValue=value;
   oldrefresh=refresh;
   delay(period*10);

}

Here, inside the loop function I am displaying the beat/10 each time in LCD display. But my question is why do I need to calculate value=alpha*oldValue+(0-alpha)*beat while I am not using it anywhere in display and also why am I using oldValue and oldrefresh variables?

  • The calculations don't return the heartrate. The code doesn't seem finished. I guess the pulsesensor is just some pressure sensor, that outputs the rise and fall of blood pressure as analog voltage. So what get's printed is just this analog value. To get the actual heart rate, you would have to count the pulses, that are over a specific threshold, and divide that by the time range. – chrisl Sep 23 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.