Hi there,
Im making a project and part of it im using a heart rate sensor and want to display BPM to serial for a start. Im having problems where im getting the right values for beats per minute but rather than display a new value, all im doing is adding it to the old value and displaying the last and next BPM. It goes like;
BPM : 55
BPM :110
BPM :170
BPM :225
Rather than;
BPM : 55
BPM : 55
BPM : 60
BPM : 55
Can anyone please help??
LarryD
March 23, 2016, 10:44pm
2
Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
void beatsCounted(int);
unsigned long measurementTime = 10000;
byte heartSensorPin = A0;
int beats = 0;
int SensorValue=0;
boolean count = false;
int bpm = 0;
void setup()
{
Serial.begin(9600);
pinMode(heartSensorPin, INPUT);
}
void loop()
{
unsigned long currentTime = millis();
if(millis()-currentTime >= measurementTime && beats > 0){
bpm = beats*6;
Serial.print("BPM : ");
Serial.println(bpm);
currentTime = millis();
}
SensorValue = analogRead(heartSensorPin);
if (SensorValue > 550 && count==false)
{
count = true;
beats++;
}
else if (SensorValue < 550)
{
count = false;
}
}
LarryD
March 23, 2016, 11:08pm
4
Move this before setup()
unsigned long currentTime = millis();
You don't need this
pinMode(heartSensorPin, INPUT);
Where is
void beatsCounted(int) {}
You probably want to change
currentTime = millis();
to
currentTime = currentTime + measurementTime;
Ok thanks, ill try that. Sorry i was trying to set up a function earlier and decided against it and forgot to delete the prototype