TITTLE :-
HEARTBEAT
SENSOR USING
ARDUINO
▪ INTRODUCTION
The heartbeat sensor is a device that measures the heart rate of an
individual. It has various applications in the field of healthcare,
fitness, and medical research. With the advancement of technology, it
is possible to build a simple heartbeat sensor using an Arduino board.
In this project, we will explore how to build a heartbeat sensor using
an Arduino board and a heartbeat sensor module (KY-039). The
project involves assembling the hardware components, writing, and
uploading the code to the Arduino board, and testing the sensor to
measure the heartbeat. This project is a great opportunity for
beginners to learn about electronics, programming, and how to build
a simple sensor for monitoring the heartbeat.
▪ Component used in Heartbeat Sensor
➢ ARDUIO UNO BOARD
➢ PULSE SENSOR
➢ JUMPER WIRES
➢ BREADBOARD
➢ 16X2 LCD DISPLAY
❖ ARDUINO UNO BOARD
Arduino Uno is a microcontroller board based on the ATmega328P microcontroller chip. It is an open-
source electronics platform that allows us to create interactive electronic projects. The board
contains everything needed to support the microcontroller, including a USB port for serial
communication, an ICSP header for programming, and a power jack for connecting an external
power supply.
Here are some features and specifications of the Arduino Uno board:
- Microcontroller: ATmega328P
- Operating Voltage: 5V
- Input Voltage: 7-12V (recommended)
- Digital I/O Pins: 14 (of which 6 provide PWM output)
- Analog Input Pins: 6
- DC Current per I/O Pin: 20 mA
- Flash Memory: 32 KB (ATmega328P) of which 0.5 KB
used by bootloader
- SRAM: 2 KB (ATmega328P)
- EEPROM: 1 KB (ATmega328P)
- Clock Speed: 16 MHz
The Arduino Uno board can be programmed using the Arduino Integrated Development Environment
(IDE), which is a free, open-source software tool that provides an easy-to-use interface for writing,
compiling, and uploading code to the board.
The board can be powered through the USB connection from a computer or an external power
supply. The ATmega328P microcontroller can be programmed using a serial connection through the
USB port or through an In-Circuit Serial Programming (ICSP) header using an external programmer.
Overall, the Arduino Uno board is a popular choice for beginners and advanced electronics
enthusiasts alike due to its ease of use, versatility, and wide range of applications. It is widely used in
education, prototyping, and hobbyist projects.
❖ PULSE SENSOR
A pulse sensor is a type of sensor that detects a person's heartbeat.
It is a non-invasive sensor that measures changes in blood volume
in the fingertip, earlobe, or other parts of the body. The sensor
works by shining a light through the skin and measuring the
amount of light that is reflected back by the blood vessels. The
amount of light that is reflected is proportional to the blood volume
in the vessels, which varies with each heartbeat.
The pulse sensor used in this project is a simple, low-cost sensor
that clips onto a fingertip. It consists of a light source (usually an
LED) and a photodetector. The LED shines a light through the fingertip, and the photodetector
measures the amount of light that is reflected back. The reflected light is then converted into an
electrical signal that can be read by the microcontroller (in this case, the Arduino Uno board).
The pulse sensor produces an analog output signal, which is proportional to the changes in blood
volume caused by each heartbeat. The output signal is read by the Arduino board's analog input pin,
which converts the signal into a digital value that can be processed by the microcontroller. The code
then processes the data to calculate the heart rate, which is displayed on the LCD display.
Pulse sensors are commonly used in medical applications, such as heart rate monitoring, as well as in
fitness tracking devices, smartwatches, and other wearable technology. They are also used in
research studies to measure physiological responses to different stimuli or interventions. The pulse
sensor used in this project is a simple and low-cost way to measure heart rate and is a great addition
to any project that involves monitoring a person's physiological response.
❖ JUMPER WIRES
Jumper wires are electrical wires that are used to connect electronic components together on a
breadboard or circuit board. They are essential for building prototype circuits and for testing
electronic designs. Jumper wires are typically made of flexible copper wire that is coated with
insulation material, such as PVC or Teflon, to prevent short circuits.
Jumper wires come in a variety of lengths, colours, and types. They can be male-to-male, male-to-
female, or female-to-female, depending on the type of connection needed. Male-to-male jumper
wires have pins on both ends, and are used to connect two components with female headers or
sockets. Female-to-female jumper wires have sockets or connectors on both ends, and are used to
connect two components with male headers or pins. Male-to-female jumper wires have pins on one
end and sockets on the other end, and are used to connect a component with a male header to a
component with a female header.
Jumper wires can also have different wire gauges, which refer to the thickness of the wire. The wire
gauge affects the amount of current that the jumper wire can carry without overheating. Thicker
wires can carry more current than thinner wires, but may be less flexible.
When using jumper wires, it is important to ensure that the wires are properly connected and that
the correct type of wire is used for the specific connection. It is also important to avoid bending the
wires too much or pulling on them too hard, as this can damage the wire or the components it is
connected to.
❖ BREAD BOARD
A breadboard is a device used to build and test electronic circuits. It is a reusable, solderless device
that allows for quick and easy prototyping of circuits.
The breadboard is typically made of plastic and consists of rows and columns of holes that are used
to insert and connect electronic components. The holes in a breadboard are connected in a specific
pattern, usually following a standard layout, and are often color-coded to make it easier to identify
the different sections.
The breadboard is divided into two main sections: the terminal strip and the distribution strip. The
terminal strip is typically located on the sides of the breadboard and is used to connect power
sources, such as batteries or power supplies, to the circuit. The distribution strip is located in the
center of the breadboard and is used to connect components
together.
Breadboards come in different sizes, with the most common sizes
being mini, half-sized, and full-sized. Mini breadboards are small and
portable, and are typically used for small circuits or for testing
individual components. Half-sized and full-sized breadboards are
larger and have more space for components, and are used for more
complex circuits.
When using a breadboard, it is important to follow a few guidelines to
ensure proper function and to prevent damage to the components.
These guidelines include:
1. Use the correct size and type of jumper wires to connect the
components.
2. Insert the components into the correct holes on the breadboard, following the layout diagram.
3. Avoid overcrowding the breadboard by leaving space between components.
4. Ensure that the components are securely inserted into the breadboard.
5. Avoid bending the legs of the components too much, as this can damage the components.
❖ 16x2 LCD DISPLAY
A 16x2 LCD display is a liquid crystal display that can display 16 characters per line and has 2 lines of
characters. It is commonly used in electronic projects and products to display data and information.
The LCD display is made up of a matrix of tiny liquid crystal cells that are arranged in rows and
columns. When an electric current is applied to a cell, it changes its optical properties and allows
light to pass through, creating a visible character or symbol on the display.
A 16x2 LCD display typically has a rectangular shape and a backlight that makes the characters visible
in low light conditions. The display has a standard 14-pin interface that allows it to be connected to a
microcontroller or other electronic device.
To use a 16x2 LCD display, a software library is typically needed to interface with the display and send
data to be displayed. The library provides functions for initializing the display, setting the cursor
position, writing text, and more.
When programming a 16x2 LCD display, the text and symbols to be displayed are sent to the display
one character at a time. The display can also be customized with special characters or symbols that
can be defined in the software.
Overall, a 16x2 LCD display is a versatile and widely used component in electronic projects and
products, providing a simple and effective way to display information and data.
▪ CIRCUIT DIAGRAM
▪ CODE
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pulsePin = A0; // Pulse Sensor purple wire connected to analog pin A0
int blinkPin = 13; // pin to blink led at each beat
// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a
"live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial
Monitor ASCII Visual Pulse
volatile int rate[10]; // array to hold last ten IBI values
volatile unsigned long sampleCounter = 0; // used to determine pulse timing
volatile unsigned long lastBeatTime = 0; // used to find IBI
volatile int P = 512; // used to find peak in pulse wave, seeded
volatile int T = 512; // used to find trough in pulse wave, seeded
volatile int thresh = 525; // used to find instant moment of heart beat, seeded
volatile int amp = 100; // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = false; // used to seed rate array so we startup with reasonable BPM
void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
[Link](115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD
VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
[Link](16, 2);
[Link]();
// Where the Magic Happens
void loop()
serialOutput();
if (QS == true) // A Heartbeat Was Found
// BPM and IBI have been Determined
// Quantified Self "QS" true when arduino finds a heartbeat
serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
delay(20); // take a break
void interruptSetup()
{
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
void serialOutput()
{ // Decide How To Output Serial.
if (serialVisual == true)
arduinoSerialMonitorVisual('-', Signal); // goes to function that makes Serial Monitor Visualizer
else
sendDataToSerial('S', Signal); // goes to sendDataToSerial function
void serialOutputWhenBeatHappens()
if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work
[Link](" Heart-Beat Found "); //ASCII Art Madness
[Link]("BPM: ");
[Link](BPM);
[Link]("Heart-Beat Found ");
[Link](1,1);
[Link]("BPM: ");
[Link](5,1);
[Link](BPM);
delay(300);
[Link]();
else
sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix
sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix
void arduinoSerialMonitorVisual(char symbol, int data )
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1024; // sensor maximum, discovered through experiment
int sensorReading = data; // map the sensor range to a range of 12 options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 11);
// do something different depending on the
// range value:
void sendDataToSerial(char symbol, int data )
[Link](symbol);
[Link](data);
ISR(TIMER2_COMPA_vect) //triggered when Timer2 counts to 124
{
cli(); // disable interrupts while we do this
Signal = analogRead(pulsePin); // read the Pulse Sensor
sampleCounter += 2; // keep track of the time in mS with this variable
int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid noise
// find the peak and trough of the pulse wave
if(Signal < thresh && N > (IBI/5)*3) // avoid dichrotic noise by waiting 3/5 of last IBI
if (Signal < T) // T is the trough
T = Signal; // keep track of lowest point in pulse wave
if(Signal > thresh && Signal > P)
{ // thresh condition helps avoid noise
P = Signal; // P is the peak
} // keep track of highest point in pulse wave
// NOW IT'S TIME TO LOOK FOR THE HEART BEAT
// signal surges up in value every time there is a pulse
if (N > 250)
{ // avoid high frequency noise
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
Pulse = true; // set the Pulse flag when we think there is a pulse
digitalWrite(blinkPin,HIGH); // turn on pin 13 LED
IBI = sampleCounter - lastBeatTime; // measure time between beats in mS
lastBeatTime = sampleCounter; // keep track of time for next pulse
if(secondBeat)
{ // if this is the second beat, if secondBeat == TRUE
secondBeat = false; // clear secondBeat flag
for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup
rate[i] = IBI;
if(firstBeat) // if it's the first time we found a beat, if firstBeat == TRUE
firstBeat = false; // clear firstBeat flag
secondBeat = true; // set the second beat flag
sei(); // enable interrupts again
return; // IBI value is unreliable so discard it
// keep a running total of the last 10 IBI values
word runningTotal = 0; // clear the runningTotal variable
for(int i=0; i<=8; i++)
{ // shift data in the rate array
rate[i] = rate[i+1]; // and drop the oldest IBI value
runningTotal += rate[i]; // add up the 9 oldest IBI values
rate[9] = IBI; // add the latest IBI to the rate array
runningTotal += rate[9]; // add the latest IBI to runningTotal
runningTotal /= 10; // average the last 10 IBI values
BPM = 60000/runningTotal; // how many beats can fit into a minute? that's BPM!
QS = true; // set Quantified Self flag
// QS FLAG IS NOT CLEARED INSIDE THIS ISR
}
if (Signal < thresh && Pulse == true)
{ // when the values are going down, the beat is over
digitalWrite(blinkPin,LOW); // turn off pin 13 LED
Pulse = false; // reset the Pulse flag so we can do it again
amp = P - T; // get amplitude of the pulse wave
thresh = amp/2 + T; // set thresh at 50% of the amplitude
P = thresh; // reset these for next time
T = thresh;
if (N > 2500)
{ // if 2.5 seconds go by without a beat
thresh = 512; // set thresh default
P = 512; // set P default
T = 512; // set T default
lastBeatTime = sampleCounter; // bring the lastBeatTime up to date
firstBeat = true; // set these to avoid noise
secondBeat = false; // when we get the heartbeat back
sei(); // enable interrupts when youre done!
}// end isr
▪ SOFTWARE SPECIFICATION
Arduino is an open-source stage used for building gadgets schemes. It contains of both a physical
programmable circuit board and a programming technology (Integrated Development Environment)
that keeps consecutively running on your PC, used to compose and transfer PC code to the physical
board. The Arduino IDE utilizes a abridged variant of C++, making it less complex to figure out how to
program, it gives a normal shape factor that breaks out the fundamentals of the lesser scale
controller into a more accessible bundle.
▪ WORKING OF HEARTBEAT SENSOR
The heart sensor project using Arduino Uno, here is a step-by-step explanation of its working:
1. First, connect the components to the Arduino Uno board as per the circuit diagram. Connect the
Heart Rate Sensor module to the analog input A0 of the Arduino Uno board, the 16x2 LCD display to
digital pins 12, 11, 5, 4, 3, and 2, and the power source (usually a 9V battery or a USB cable) to the
Arduino Uno board.
2. Write and upload the code to the Arduino Uno board using the Arduino IDE software. The code
should include functions to read the heart rate data from the sensor module, display the heart rate
on the LCD display, and provide any necessary feedback or alerts.
3. Power on the heart sensor project by connecting the power source to the Arduino Uno board. The
LCD display should light up, and the heart rate sensor module should start collecting heart rate data.
4. Place your finger on the sensor module to measure your heart rate. The sensor module should
detect your pulse and send the heart rate data to the Arduino Uno board.
5. The Arduino Uno board should then process the heart rate data and display it on the LCD display.
The heart rate data may be displayed in beats per minute (BPM) and may also include other
information such as the time of the measurement, the date, or any alerts or warnings.
6. Continue to monitor your heart rate using the heart sensor project and make any necessary
adjustments or changes to the code or circuit as needed. For example, you may want to adjust the
sensitivity of the sensor module or change the display format of the heart rate data.
▪ ADVANTAGES OF HEARTBEAT SENSOR
The heartbeat sensor using Arduino has several advantages. Some of them are:
1. Portable: The heartbeat sensor is small in size and portable, which makes it easy to carry around. It
can be used to monitor heart rate while performing physical activities like running, cycling, and other
sports.
2. Cost-effective: The components required to build this device are relatively inexpensive, making it a
cost-effective solution for measuring the heart rate.
3. Easy to use: The heartbeat sensor is easy to use and requires no special training or expertise to
operate. It can be used by anyone who needs to monitor their heart rate.
4. Real-time monitoring: The sensor can provide real-time monitoring of the heart rate, making it
useful in medical emergencies or situations where immediate action is required.
5. Non-invasive: The sensor is non-invasive and does not require any contact with the skin or other
body parts. This makes it a safe and comfortable option for individuals who need to monitor their
heart rate over an extended period.
6. Customizable: The code for the heartbeat sensor is customizable, which means that it can be
modified to suit different applications or user requirements. For example, the sensor can be
programmed to send notifications or alarms when the heart rate exceeds a certain limit.
Overall, the heartbeat sensor using Arduino is a versatile and practical device that can be used in
various applications to monitor heart rate and improve overall health and well-being.
▪ CONCLUSION
Biomedical engineering combines the design and problem-solving
skill of engineering with medical and biological sciences to enhance
patient’s health care. Cardiovascular disease is one of the major
causes of untimely deaths in world, heartbeat readings are by far the
only viable diagnostic apparatus that could help early detection of
cardiac events. By using this we can compute one’s heart rate
through fingertip. This paper emphases on the heart rate monitoring
and alert which can monitor the heartbeat rate condition of patient.
The system regulates the heartbeat rate per minute and then sends
short message service (SMS) alert to the device. It is portable and
cost effective. It is a very effective system and very easy to handle
and thus provides great flexibility and serves as a great improvement
over other conventional monitoring and alert systems.