KY039 Arduino Heart rate code

Jurs is correct. My code works all the same but detection is much improved.

=> This sensor is actually becoming good enough to be used as a heart rate monitor! <=

The way the board is sold, the sensor ishorizontal (detector faces up), and the LED is bent 90 degrees, facing the sensor but emiting the light at right angle from the sensor.

By bending the LED to face down onto the sensor, the fully lit sensor now reads in the 20's instead or mid 40's.
When I put my finger the signal is now in the 700's. The dynamic range has not much improved but I suspect since there's more LED light there's more rejection from reflected lights and such.

So same code, new readout from the serial console: The blue signal is when the LED blips, the red is the RAW signal.

Overall the code could be simplified to just detect the light RAW and do the same max detectin on the RAW value instead of the math blurb done that generates a delta. No math, no floats, nothing...