KY-039 heart beat sensor

I've used KY-039 heart-beat sensor. Which is the heart beat value getting from the code.??

Code:

int sensorPin = 0;
double alpha = 0.75;
int period = 100;
double change = 0.0;
double minval = 0.0;
void setup ()
{
Serial.begin (9600);
}
void loop ()
{
static double oldValue = 0;
static double oldChange = 0;

int rawValue = analogRead (sensorPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;

Serial.print (rawValue);
Serial.print (",");
Serial.println (value);
oldValue = value;
delay (period);
}

OUTPUT

I've got o/p like following:

886,221.50
885,387.38
888,512.53
888,606.40
887,676.55
887,729.16
886,768.37
886,797.78
885,819.58
888,836.69
888,849.52
887,858.89
887,865.92

So,which is the heart-beat value??

So,which is the heart-beat value??

None of them.

The sensor just measures how much light get reflected from your finger. The pulsing blood in it changes that reflection. If you measure that fast enough you get a curve that usually looks like a saw. If you count the spikes within one minute you get your pulse. If you measure really fast you can use the time difference between two spikes to calculate the heartbeat rate without waiting for a minute.

This page is in German but it includes some code that does that calculation: SensorKit - SensorKit. You can use Google Translator to get an English version.

I'm happy with mine. I got 2 for 0.99$.
I bent IR LED and phototransistor so that they face each other.

Arduino LED is happily blinking in the ritam of my heart, and serial monitor is displaying my heart rate. :slight_smile:

DannyTheBoy:
I'm happy with mine. I got 2 for 0.99$.
I bent IR LED and phototransistor so that they face each other.

Arduino LED is happily blinking in the ritam of my heart, and serial monitor is displaying my heart rate. :slight_smile:

hey! could you show me your code?

It is just slightly modified basic code that is availible everywere.
I incrised double alpha to 0.9 so that every new measured value does not influence avarage value to much (10% influence instead 25%).
I also changed the period value (100 miliseconds is to much, you only get 10 measurements per seconds, and arduino ADC is much, much faster then that).
After seeing sensor output oscillogram:

I wanted at least 100 measurements per second, so I changed the period value to 9 milliseconds.