Heart Rate Module (Part 1)

modules biometric

Today, we are going to look at a very simple heart rate sensor. Let's discover how it works and how we can measure the heart rate with it.

Heart Rate Sensor

In this tutorial, we are going to look at the KY-039 module. There are different variants of this module, but the basic working principle is always the same. All modules are quite simple and use only an LED and a photo diode or photo transistor for the measurements. The LED emits light into the skin and the photo diode or transistor measure the light intensity. The amount of light absorbed in the skin depends on the blood volume in the tissue. When the heart contracts blood is pumped from the heart through the arteries into the whole body. The blood volume in the tissue increases and more light is absorbed. This measured by the sensor and ultimately allows us to determine the heart rate.

The measurement method is also called photoplethysmology. Related, but different is the so-called pulse oximetry, where the oxygen saturation in the blood is measured. A pulse oximeter looks similar to a heart rate sensor and most devices also display the heart rate, however, for pulseoximetry multiple LEDs of different wavelengths would be required.

There are two different methods to conduct the measurements: by shining light through the skin and measuring the absorption or by measuring the amount of reflected light. Both variants of the KY-039 module exist. In the image below you can see the type which is using reflection on the left. To use this module just lay your finger on top of the green LED. For the module on the right side you have to lay your finger in between the IR-LED and the phototransistor, so that the LED shines through your finger onto the photo transistor. Don't be surprised, since the LED is an infrared LED you cannot see whether it is on or not.

KY-039 module versions

Using the Heart Rate Sensor

Let's see how we can use these modules to measure our heart rate, shall we?

Both variants of the KY-039 can be wired in the same way. Connect + to 5V, - to GND and analog output signal S to one of the Arduino's analog inputs. I chose A0.

Wiring the module to the Arduino Uno

In this first part of this tutorial, we will use a very simple Arduino program that takes one measurement every 10 ms and sends it to the serial monitor. Here is how this program looks like:

void setup() {

void loop() {
  int value = analogRead(A0);

The Result

Once the program is uploaded to the Arduino, the measurement values are sent to the computer. They can be visualized in the serial plotter, which can be found under Tools. For good measurements you should avoid applying pressure on your finger. Lay it down gently and you should be able to see your heartbeats in the serial plotter.

Measurements visualized in the serial plotter

We can already use this graph to calculate the heart rate. The time between the big arterial pulses is roughly 820 ms. If we transform this value into beats per minutes, we get a heart rate of 73 bpm. What is not possible yet, is calculating the heart rate on the Arduino itself. For that we would need to adjust the program to reliably detect and count the heart beats. This sounds easier than it is. We cannot use a simple threshold, as the measured values depend on many factors like skin color, blood circulation, applied pressure or the intensity of the ambient light. How can we solve this issue? This is what we are going to look at in part 2 of this tutorial.

Previous Post Next Post