Introduction
In this tutorial, we will learn about the KY-039 module, how it works and we will build a simple project using the KY-039 module and an Arduino.
Heartbeat Sensor KY-039
The KY-039 Module will be our main component for this tutorial. This module has an infrared (IR) LED, and an IR receiver mounted on a breakout board with resistors. Figure 1 shows the module as seen in fritzing.
Pin Out
The KY-039 module has three pins.
Pin | Description |
---|---|
(-) | GND |
Middle Pin | +5V |
S | Signal |
How it works
Our blood vessels in the fingers contracts and expands on every heartbeat. By placing our finger between the infrared (IR) LED and IR receiver, our blood vessel affects how much IR light is received by the receiver. Based on this, the module’s output is an analog signal from 0~1023. A higher value means less light is being “blocked” through our finger and vice-versa.
Project - Arduino Heartbeat Graph
After learning about the KY-039 module and how it works, it is now time to build a project using the module. Our project will get the analog values from the KY-039 module and display it on the serial monitor.
Components
For this project, we need the following components:
- Arduino Uno board (1 pc.)
- KY-039 Heart Beat Sensor (1 pc.)
- Jumper wires
Wiring Diagram
Figure 2 shows the connection between the Arduino Uno and the KY-039 Heart Beat Sensor.
The KY-039 module pins are connected to the Arduino Uno board as follows:
Component Pin | UNO Board Pin |
---|---|
(-) | GND |
Middle Pin | +5V |
S | A0 |
Code
Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-039.ino and upload it to your Arduino board.
// Arduino and KY-039 module
void setup ()
{
Serial.begin(9600); // initialize serial
}
void loop ()
{
// display analog values to serial
Serial.println(analogRead(A0));
}
Project Test
Apply power to your Arduino Uno board and open the Serial Plotter in the Arduino IDE. Arduino will display the analog value received from the heartbeat module as a graph. If you want to see the analog output as a stream of numbers, open the Serial Monitor instead.