top of page

KY-039 Finger Heart beat detector

Updated: Jul 2, 2021

In this project I describe how this signal is converted into a heartbeat rate like BPM (beats per minute).



KY-039

This KY-039 Finger Detection Heartbeat Measuring Sensor Module uses bright infrared (IR) LED and a phototransistor to detect the pulse of the finger, a red LED flashes with each pulse.

The LED is the light side of the finger, and the phototransistor on the other side of the finger, phototransistor used to obtain the flux emitted, when the blood pressure pulse by the finger when the resistance of the phototransistor will be slightly changed.

We chose a very high resistance resistor R1 because most of the light through the finger is absorbed, it is desirable that the phototransistor is sensitive enough. Resistance can be selected by experiment to get the best results. The most important is to keep the shield stray light into the phototransistor.


For home lighting that is particularly important because the lights at home mostly based 50HZ or 60HZ fluctuate, so faint heartbeat will add considerable noise.


Features :

  • Use IR LED and an optical transistor to detect pulsation in fingers

  • Small and Compact module

  • Easy to use.

Connection

  • Sensor pin S connect to Arduino pin Analoog 0 / A0

  • Sensor pin + (middle pin) connect to Arduino pin 5+

  • Sensor pin - connect to Arduino pin GND


Subscribe and Download code.

Arduino Test Code

int sensorPin = 0;

void setup() {

Serial.begin(9600);

}

void loop ()

{

while(1)

{

Serial.print(analogRead(sensorPin));

Serial.print('\n');

}

}

After Uploading to arduino Uno, Open Serial plotter and see the result. when placing finger in the sensor module, and you get something like this:

Subscribe and Download code.

Smoothing

Final Code:

#define samp_siz 4

#define rise_threshold 5

// Pulse Monitor Test Script

int sensorPin = 0;

void setup() {

Serial.begin(9600);

}

void loop ()

{

float reads[samp_siz], sum;

long int now, ptr;

float last, reader, start;

float first, second, third, before, print_value;

bool rising;

int rise_count;

int n;

long int last_beat;

for (int i = 0; i < samp_siz; i++)

reads[i] = 0;

sum = 0;

ptr = 0;

while(1)

{

// calculate an average of the sensor

// during a 20 ms period (this will eliminate

// the 50 Hz noise caused by electric light

n = 0;

start = millis();

reader = 0.;

do

{

reader += analogRead (sensorPin);

n++;

now = millis();

}

while (now < start + 20);

reader /= n; // we got an average

// Add the newest measurement to an array

// and subtract the oldest measurement from the array

// to maintain a sum of last measurements

sum -= reads[ptr];

sum += reader;

reads[ptr] = reader;

last = sum / samp_siz;

// now last holds the average of the values in the array

// check for a rising curve (= a heart beat)

if (last > before)

{

rise_count++;

if (!rising && rise_count > rise_threshold)

{

// Ok, we have detected a rising curve, which implies a heartbeat.

// Record the time since last beat, keep track of the two previous

// times (first, second, third) to get a weighed average.

// The rising flag prevents us from detecting the same rise

// more than once.

rising = true;

first = millis() - last_beat;

last_beat = millis();

// Calculate the weighed average of heartbeat rate

// according to the three last beats

print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third);

Serial.print(print_value);

Serial.print('\n');

third = second;

second = first;

}

}

else

{

// Ok, the curve is falling

rising = false;

rise_count = 0;

}

before = last;

ptr++;

ptr %= samp_siz;

}

}


To get a smoother output , take an average of say 20 last readings from the sensor. With an array size of 20 and a baud rate of 9600 in the serial monitor, I might get a plotting like this:



1,301 views0 comments
bottom of page