KY039 Arduino Heart rate code

sonyhome:
I managed to tweak generic ebay code after looking at the output to generate a somewhat responsive heart monitor code. Since there is no amplification, the resolution of the signal is very low, since the dynamic range is small while the finger is on the sensor (960~967), but it is enough to get a coarse heart rate signal (see included graph for about 2 sec of data).

I think the signal becomes better when more light arrives at the detector.
Most likely the LED sends its beam a bit in the wrong direction.

Most likely you have to bend the LED a bit so that max. IR beam intensity is sent directly to the IR receiver.

I think if your signal is detected in the range of 400...600 it will be much better than at nearly end of range at 950+.