Project Report MSI

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

CPE342-Microprocessor Systems and Interfacing

HEARTBEAT MONITORING USING MICROCONTROLLER

Presented to:
Mian Muhammad Hassan Aslam

Presented by:
Muhammad Naimat Ali
Muhammad Aizaz Arshad
Laiba Rehman

Registration IDs:
FA18-BCE-070-A
FA18-BCE-088-A
FA18-BCE-040-A

i
TABLE OF CONTENTS

HEARTBEAT MONITORING USING MICROCONTROLLER ................................................... i

TABLE OF CONTENTS ..................................................................................................................... ii

LIST OF FIGURES ............................................................................................................................. iii

1. INTRODUCTION............................................................................................................................. 1

1.1 Introduction ................................................................................................................................... 1


1.2 Motivation ..................................................................................................................................... 1
1.3 Aims and Objectives ..................................................................................................................... 1
1.4 Report Organization ...................................................................................................................... 1
2. PROJECT IMPLEMENTATION ................................................................................................... 2

2.1 Component Details........................................................................................................................ 2


2.2 Schematic Diagram ....................................................................................................................... 4
2.3 Working of Project ........................................................................................................................ 5
2.4 Project Analysis ............................................................................................................................ 6
2.4.1 Enviornment and Sustainibility (PLO-7) ............................................................................... 6
2.4.2 Ethics (PLO-8) ....................................................................................................................... 7
3. RESULTS .......................................................................................................................................... 8

4. REFERENCES ................................................................................................................................ 11

5. APPENDIX ...................................................................................................................................... 12

ii
LIST OF FIGURES

Figure 2.1.1 Pin Configuration of an Arduino UNO R3 SMD ............................................................... 2


Figure 2.1.2 Pin Configuration of 16x2 LCD HD44780 ........................................................................ 2
Figure 2.1.3 Pin Configuration of a Heartbeat Sensor ............................................................................ 3
Figure 2.1.4 Pin Configuration of an LED.............................................................................................. 4

Figure 2.2.1 Schematic Diagram of Heartbeat Monitoring System ........................................................ 4

Figure 3. 1. Welcome Screen of Heartbeat Monitoring System ............................................................. 8


Figure 3. 2 A patient using the Heartbeat Monitoring System ............................................................... 8
Figure 3. 3.Patient's Low Heartbeat detected.......................................................................................... 9
Figure 3. 4. System's warning to the patient when the heartbeat is out of healthy range........................ 9
Figure 3. 5. Healthy Patient's Heartbeat being displayed...................................................................... 10
Figure 3. 6. When system is not used for >5 seconds ........................................................................... 10
Figure 3. 7. Measured Heartbeat of a patient ........................................................................................ 10

iii
1. INTRODUCTION

1.1 Introduction
A heartbeat sensor is a device that is used to measure the heartbeats in BPM (Beats per minute) in real
time. It is used widely in hospitals and at home. It is also integrated in smartphones and smartwatches
to track and detect the activity of the athlete and common users.

1.2 Motivation
The motivation behind this project is the intension to monitor the heartbeat in order to evaluate the
condition or the activity of the user. HRMS (Heart Rate Monitoring System) are widely used in the
medical industry to monitor the condition of the patient and even in the operation theater where these
vitals are important to save a valuable life. Now, the HRMS are even used in the training sessions of
professional athletes in order to monitor and understand their vitals and weak points and ensure better
performance in the match field.

1.3 Aims and Objectives


The aim of this project is to measure irregularities in the heartbeat at the convenience of the home. Since
remote heart measurement has been very effective for the treatments of heart patients since last two
decades, and growing ever since [1].
As Douglas Gibson, Director of Cardiac Electrophysiology at Scripps clinic says:

“In some cases, it’s now possible to do routine checks on both the heart and the
device remotely without the need for a visit to the hospital or a clinic,” [1]
The objective is providing the arrhythmia diagnosed patients, which is a condition where heart beats at
an irregular rate [2]. The doctors can help manage their health from the convenience of the home without
having the patient to leave the house in the pandemic of COVID-19. Since, HRMs are usually costly
and not affordable by all, we aim at achieving the same goal but with a reduction of the price factor.

1.4 Report Organization


Chapter 1 starts with the introduction of the project, followed by the aims and objectives behind this
particular project.
Chapter 2 contains methodology of the working of project, detailed explanation of the components used
in the project, the schematic diagram, followed by the working of the project as a whole and how
multiple components communicate together in order to yield a meaningful output, ending with the
project analysis with the discussion and relation to environment and sustainability of the project.
Chapter 3, 4, and 5 are the Results obtained, References used, and the Appendix which contains our
source code for the project.

1
2. PROJECT IMPLEMENTATION

2.1 Component Details


Our project is implemented using Arduino UNO R3 SMD, which is our microcontroller of choice due
to the versatility, and cost measures, and cross-platform compatibility. This is slightly different from
Arduino UNO R3 due to the fact that SMD version has the option of being surface mounted which
makes it easier to connect other components to the microcontroller without the need of being soldered.
Arduino UNO SMD uses C language to program just like any other microcontroller of choice, like an
STM microcontroller.

Figure 2.1.1 Pin Configuration of an Arduino UNO R3 SMD

Another component that we used in the displaying of the outputs is the 16x2 LCD. The official name
for the 16x2 LCD is HD44780. This LCD is very common and widely used in the industry and
educational institutes. It is also used in printers, fax machines, as well as laser printers. This LCD was
developed by Hitachi in the 1980s. A single HD44780 can display up to one 8-character line or two 8-
character lines [3].

Figure 2.1.2 Pin Configuration of 16x2 LCD HD44780

2
An LCD is able to display numbers, strings, characters and small graphics. This gives us a vast option
as compared to an LED for the displaying of result. These LCDs are also easy to program using the
Data pins which are connected to any microcontroller.
An LCD has two types of registers which are built-in.

• Command Register
• Data Register
A Command Register is responsible for giving internal commands such as clearing a screen or moving
a cursor to the next line. Meanwhile a Data Register is responsible for inserting data into the LCD.
There are also two working modes of an LCD which are:

• 8-Bit Mode
• 4-Bit Mode
For our project, we opted for 8-Bit mode since it is undemanding in work as compared to the 4-bit
mode, which uses less connections but is more demanding to program.

Next, another crucial component for our project is the Heart Beat Sensor. SEN-11574 is an integrated
Analogue-to-Digital converter (ADC) since it converts analogue signal (Pulse) into a digitalized form.

Figure 2.1.3 Pin Configuration of a Heartbeat Sensor

The functionality is simple. It has a built-in infrared scanner and receiver, which transmits infrared
signals. These signals are absorbed by the finger of the user. The blood flow in the human body is in
pulses, which means that when the blood is pumped, the area (finger in this case) has more blood as
compared to the time when blood is sent back to the heart. So, this mechanism is observed by the IR
scanner and receiver whose signal is generated by the high and low absorption of IR light by our finger.

3
Finally, we will integrate an LED with the Arduino which will illuminate when a certain level of a heart
rate is measured.

Figure 2.1.4 Pin Configuration of an LED

When the heart beat is measured and crosschecked with the benchmark value, the microcontroller will
trigger a signal which will illuminate the LED at the connected port. This type of output will grab the
attention towards the detail he/she might have missed on the LCD and raise a caution in the mind of
user.

2.2 Schematic Diagram

Figure 2.2.1 Schematic Diagram of Heartbeat Monitoring System

4
2.3 Working of Project

This project has multiple functionalities which combined, brings our project to life. There are many
advantages Arduino gave us over other microcontrollers. Such as the cost factor, built-in functionality
of Analogue-to-Digital converter (ADC), ease of use and many more. The Arduino Uno R3 has built-
in ADC converter which eliminated the need of I2C, which also helped us to reduce our cost and
complexity of the program. The Arduino has A0-A5 pins which take analogue inputs and gives out the
digital outputs in pins 0-7.
Another implementation devised in order to keep the power usage down is the 4-bit mode of LCD. Our
16x2 LCD is working in 4-bit mode instead of 8-bit mode. The advantage of 4-bit mode over the 8-bit
mode is that it reduces the amount of power required by the LCD to operate. It can now work in the
same style while keeping the power usage down.
In the coding aspects of the project, we tried to keep the programming part to the minimal so that the
microcontroller can be quick and reliable and can operate whenever required. We included some
libraries like <LiquidCrystal.h> in order to activate our LCD. The heartbeat sensor was a simple plug-
and-play device that operated when we connected the voltage and ground and connected the signal cable
into the analogue pin for the Arduino to process and provide valuable feedback to the patient.
The user puts their finger on the heartbeat sensor, which gives a signal to the Arduino microcontroller
that the system is in use and the analogue signal being sent has to be processed on. The Arduino then
takes analogue signal from the heartbeat sensor and calculates the beats done by the heart per minute
by multiplying the number of beats it has received in a few seconds. For better accuracy, we devised a
way so that microcontroller can take average of 5 values taken from the heartbeat sensor and displays
it using the LCD. This proves to be more accurate and reliable.
The system checks whether the patient’s heartbeat is in a healthy range or not. If the heartbeat drops 60
BPM or exceeds 100 BPM, then the Heartbeat Monitoring system will heed the patient to seek
immediate medical attention. The system is smart and will go to power saving mode while also
informing the user that the system is not in use and it will require an input from the user to be active
again.
For the better accuracy of the system, the reduction of noise from the system was necessary. There are
many factors that can contribute to introduction of noise to the system like a little muscle spasm in the
finger, or a sound of any organ like gurgling of the stomach, which might travel to the fingertip since
sound is better communicated in solids and liquids.
So, we developed a function called IBI, which is In-Beat-Interval. An IBI is the time in-between two
beats produced by the heart. We stopped input when an there is an IBI which eliminates the sound
produced by other organs and muscles, or externally produced sounds that can disturb the accuracy of
the system. The system then detects the heartbeat again and then shuts off when in IBI. The system
detects when the heartbeat is going down and then predicts that now is the time of an IBI.

5
2.4 Project Analysis

Heart beat sensor is a project that we created and it is working properly. The normal
pulse for healthy adults ranges from 60 to 100 beats per minute. For children under 15 normal heart
beat rate is 70 to 100 per minute. So our project senses the heartbeat when a person places fingertip on
the sensor the heart beat rate is displayed on the LCD. We examine the heart beat rate of children’s and
adults and it shows the result properly. Our project is configured such that if the heart beat rate is lower
than 60 and higher than 100 it notifies the person through LCD “need Checkup”. Our project also
notifies the person in case of no beat sense the LCD displays “No BPM found use it”. For better
performance of our project we use an led which turns ON when fingertip is sensed and it turns OFF
when there is no fingertip detected.
As mentioned earlier, we use the 4-bit mode because it consumes less powerIt means your sketch needs
to send each command/character as two separate batches of 4-bits (one after the other). This is handled
automatically by the Liquid Crystal library, so you won't need any extra complexity in your code.
However, it does mean that your sketch requires roughly double the number of processor cycles to send
anything to the LCD.
In the Arduino we use volatile integer because it directly collects data from memory location. In case
of using integer, the value is temporary stored elsewhere and then it is utilized for data collection which
is twice the work of volatile integer. That’s why we use the volatile integer. Also we use the interrupt
in Arduino. An Interrupt is to make sure that the processor responds quickly to important events. When
a certain signal is detected, an Interrupt of 2ms to 3ms shows up. Also in serial begin function in
Arduino the good data transfer range is 115200-230400. So we set the range 230400.
First of all we use STM to create the project but STM microcontroller was not working properly. That’s
why we use Arduino to create the Heartbeat sensor. The whole project we created comprises of
moderate range economically. It costed us a normal range of Rs1200-1500. It is cost effective and cheap.
It is eco-friendly. During the project creation the LCD we buy was broken so we have to re-buy it.

2.4.1 Enviornment and Sustainibility (PLO-7)

The environment of earth is deteriorating at a highly paced speed which has to be controlled in order
ensure a healthy and safe environment for our upcoming generations. According to green.harvard.edu,
we can reduce e-waste by:

• Re-evaluating
• Extending the life of our electronics
• Reusing large electronics
• Buying eco-friendly electronics.
Our project is designed and manufactured while keeping the environment in mind. Unlike money
hungry companies who manufacture expensive, unrepairable and hard to recycle products, we designed
our product in such a way that any faulty component can be replaced at almost little to none cost while
ensuring the integrity and quality of our product. This makes it easier on the pockets of the consumer
and on mother nature since the whole operational working equipment won’t end up in landfills due to
one little faulty IC, which could’ve been replaced. The Landfills accounts to 292.4 million tons in the
US alone.

6
Landfills due to electronics release hazardous materials like mercury, lead, and arsenic, which are all
poisonous to human body when in contact/consumed. Incinerating the e-waste is also a no-go since it
also releases heavy toxins, which in terms will account to acid rain and increase in toxicity of lands. If
not stopped, the crop irrigation will be reduced and the world might hit an agricultural drought. Hence,
our mission is simple, keeping the cost down while saving mother nature.

2.4.2 Ethics (PLO-8)

According to NSPE Code of ethics, our project “Hold(s) paramount the safety, health, and welfare of
the public” [4], by valuing each and every life. This provides a better accessibility for every person
especially the cardiac patients who are to be monitored but can’t afford the extensive costs of the
procedure. Our integration of engineering knowledge, combined with the medical information makes
an impact on the market and will save a valuable life by detecting it on time, so we can seek medical
attention at earliest.
According to Canon 1-A of American Society of Civil Engineers (ASCE) Code of Ethics:

“Engineers shall recognize that the lives, safety, health and welfare of the general
public are dependent upon engineering judgments, decisions and practices
incorporated into structures, machines, products, processes and devices. [5]

Also, according to IEEE code of ethics:

“To maintain and improve our technical competence and to undertake


technological tasks for others only if qualified by training or experience, or after
full disclosure of pertinent limitations;” [6]

Our working is in parallel with all the code of ethics, since it holds paramount the safety, health, and
welfare and wellbeing of the public. We developed this project with the engineering knowledge of our
best and developed in such a way that it proves beneficial to the society in all regards. This also helped
us realize that the reliability of our product is required for the wellbeing if the general public and that
we have to maintain our technical competence through proper training and guidance from the competent
sources.

7
3. RESULTS

The project is now completed and the following images shows the hardware usage along with some
outputs shown below.

Figure 3. 1. Welcome Screen of Heartbeat Monitoring System

Figure 3. 2 A patient using the Heartbeat Monitoring System

8
Figure 3. 3.Patient's Low Heartbeat detected

Figure 3. 4. System's warning to the patient when the heartbeat is out of healthy range

9
Figure 3. 5. Healthy Patient's Heartbeat being displayed

Figure 3. 6. When system is not used for >5 seconds

Figure 3. 7. Measured Heartbeat of a patient

10
4. REFERENCES

[1] "Scripps," Scripps.org, 22 May 2020. [Online]. Available:


https://www.scripps.org/news_items/6973-what-heart-monitor-is-best-at-detecting-irregular-
heartbeats. [Accessed 11 June 2021].

[2] "Medline Plus," 15 Aug 2016. [Online]. Available:


https://medlineplus.gov/arrhythmia.html#:~:text=
An%20arrhythmia%20is%20a%20problem,slowly%2C%20it%20is%20called%20bradycardia..
[Accessed 11 June 2021].

[3] HITACHI LTD, HD44780U (LCD-II) Dot Matrix Liquid Crystal Display Controller/Driver,
Tokyo, Japan: Hitachi, 1980.

[4] NSPE.ORG, "National Society of Professional Engineers," July 1964. [Online]. Available:
https://www.nspe.org/resources/ethics/code-ethics. [Accessed 2021 jUNE 20].

[5] ASCE, ASCE Code of Ethics, Los Angeles, 1914.

[6] The OHIO State University, IEEE Code of Ethics, Philadelphia, Pennsylvania, 1963.

11
5. APPENDIX
B11111,

#include <LiquidCrystal.h> B10101,

B11111,

B11111,

const int rs = 12, en = 11, d4 = 5, B01110,


d5 = 4, d6 = 3, d7 = 2;
B01010,
LiquidCrystal lcd(12, 11, 5, 4, 3,
2); B11011,

B00000

int pulsePin = A0; };

int Pin = 13;


void setup()

volatile int avgBPM; {

volatile int BPM;

volatile int Signal; Serial.begin(230400);

volatile int IBI = 600; interruptSetup();

volatile boolean Pulse = false; lcd.begin(16, 2);

volatile boolean QS = false;


lcd.setCursor(0, 0);

static boolean serialVisual = true; lcd.write(byte(2));

lcd.createChar(2, Alien);

volatile int rate[10]; lcd.setCursor(2,0);

volatile unsigned long lcd.print("WELCOME User");


sampleCounter = 0; delay(2000);
volatile unsigned long lastBeatTime //lcd.clear();
= 0;
}
volatile int P = 500;

volatile int T = 500;

volatile int thresh = 525;

volatile int amp = 100;


void loop()
volatile boolean firstBeat = true;
{
volatile boolean secondBeat =
false;
serialOutput();

byte Alien[] = {

12
if (QS == true) // Heartbeat Found int o=0;

{ double Total=0;

volatile double temp=0;

void serialOutputWhenBeatHappens()
serialOutputWhenBeatHappens(); //
Output that to serial. {

QS = false; if (serialVisual == true)

} {

delay(20); for(int o=0; o<=4; o++){

}
Serial.print("Heart-Beat: ");

Serial.print("BPM: ");

void interruptSetup() Serial.println(BPM);

{ lcd.clear();

lcd.setCursor(3,0);

TCCR2A = 0x02; lcd.print("Heart-Beat");

TCCR2B = 0x06; lcd.setCursor(2,1);

OCR2A = 0X7C; lcd.print("BPM: ");

TIMSK2 = 0x02; lcd.print(BPM);

sei(); delay(1000);

} temp+=BPM;

void serialOutput() Total += temp;

{ avgBPM = Total/5;

if (serialVisual == true) Serial.print("AverageBPM: ");

{ Serial.println(avgBPM);

arduinoSerialMonitorVisual('- lcd.clear();
', Signal); lcd.setCursor(0,0);
} lcd.print("AverageBPM: ");
else lcd.print(avgBPM);
{ delay(1000);
sendDataToSerial('S',
Signal);
}
}
if (avgBPM<60 ||
} avgBPM>100){

2
lcd.clear(); Signal = analogRead(pulsePin);

lcd.setCursor(2,0); sampleCounter += 3;

lcd.print("Need Check-up"); int N = sampleCounter -


lastBeatTime;
}

if(Signal < thresh && N > (IBI/4))


else
{
{
if (Signal < T)
sendDataToSerial('B',BPM);
{
sendDataToSerial('Q',IBI);
T = Signal;

}
}
}
}

if(Signal > thresh && Signal > P)


void
arduinoSerialMonitorVisual(char {
symbol, int data )
P = Signal;
{
}
const int sensorMin = 0;

const int sensorMax = 200;


if (N > 250)
int sensorReading = data;
{
int range = map(sensorReading,
sensorMin, sensorMax, 0, 11); if ( (Signal > thresh) && (Pulse
== false) && (N > (IBI/4)) )

{
}
Pulse = true;

digitalWrite(Pin,HIGH);

IBI = sampleCounter -
void sendDataToSerial(char symbol, lastBeatTime;
int data )
lastBeatTime =
{ sampleCounter;

Serial.print(symbol);

Serial.println(data); if(secondBeat)

} {

secondBeat = false;

ISR(TIMER2_COMPA_vect) for(int i=0; i<=9; i++)

{ {

cli(); rate[i] = IBI;

3
} P = thresh;

} T = thresh;

if(firstBeat) if (N > 5000)

{ {

firstBeat = false; thresh = 500;

secondBeat = true; P = 500;

sei(); T = 500;

return; lastBeatTime = sampleCounter;

} firstBeat = true;

secondBeat = false;

word runningTotal = 0; lcd.clear();

lcd.setCursor(3,0);

for(int i=0; i<=8; i++) lcd.print("NO_BPM_FOUND!");

{ lcd.setCursor(3,1);

rate[i] = rate[i+1]; lcd.print("Use it!!!!");

runningTotal += rate[i]; delay(1000);

} }

sei();

rate[9] = IBI; }

runningTotal += rate[9];

runningTotal /= 10;

BPM = 60000/runningTotal;

QS = true;

if (Signal < thresh && Pulse ==


true)

digitalWrite(Pin,LOW);

Pulse = false;

amp = P - T;

thresh = amp/2 + T;

You might also like