int UpperThreshold = 125; //Thresholding of where to read "beats" based on your signal input int LowerThreshold = 100; int reading = 0; int BPM = 0; bool IgnoreReading = false; bool FirstPulseDetected = false; unsigned long FirstPulseTime = 0; unsigned long SecondPulseTime = 0; unsigned long PulseInterval = 0; void setup(){ Serial.begin(74880); } void loop(){ reading = analogRead(A0); // 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 && reading > 2){ IgnoreReading = false; } BPM = (1.0/PulseInterval) * 60.0 * 1000; //Serial.println(A0); Serial.print("BPM = "); Serial.println(BPM); delayMicroseconds(3900); { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue;{ // read the input on analog pin 0: //int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): // print out the value you read: Serial.println(voltage); }; // print out the value you read: Serial.println(voltage); } }