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

IoT Based Heart Attack Monitoring and Prediction

System

By
Saif Ali
01-133172-098
Fawad Ali
01-133172-027

Supervised by
Dr. Saleem Aslam

Session 2017-21

A report is submitted to the Department of Electrical Engineering,


Bahria University, Islamabad.
In partial fulfillment of the requirement for the degree of BS(EE)
Certificate

We accept the work contained in this report as a confirmation of the required standard for the
partial fulfilment of the degree of BS(EE).

__________________ __________________
Head of Department Supervisor

__________________ __________________
Internal Examiner External Examiner

i
Dedication

Parents are the ones who dedicate their wealth and time to us, so we would like to dedicate this
project to our parents, our backbone, and our strong pillars. They did everything they could for our
prosperity and growth. They face adversity so that we can achieve our goals. They supported and
encouraged us in every way. Their support made us give everything we needed to complete what
we started. We offer this service to all our teachers throughout our knowledge journey; they have
made us what we are today. We would like to thank each one of them from the bottom of our
hearts. At last, a heartful thanks to all our friends who did not let us lose hope and motivated us to
make our dream come true.

ii
Acknowledgments

Though we have worked hard and made many efforts to make this project happen, Many thanks
to Dr. Saleem Aslam for giving us the opportunity to work on this project under his direction and
guidance throughout the project. It would probably have been impossible to complete the project
without his help and his kind generosity. We also thank Almighty Allah and thank our friends,
brothers, and colleagues for supporting and encouraging us during our project and studies at BUIC.
We also want to thank our colleagues for helping us. And at last, an exceptional thanks to our
colleagues and batchmates, who supported us, encouraged, and made us complete this project with
their kind guidance and help.

iii
Abstract

Heart Attack or stroke is one of the leading causes of death today: the ratio of people who die out
of heart attack vs. all other diseases is very high. In a report from WHO, a total of 17 million people
died from heart disease in 2016 alone. During recent decades, healthcare facilities have improved
much due to the advancement and achievement that science and technology have achieved. Sensor
working with IoT, and development boards made it easy to real-time monitor the patients. Many
wearable devices are available, like smart bands and smartwatches that can measure essential
parameters of one's health. IoT is a revolutionary tech nowadays, and it is going to be growing
fast. Whereas Machine Learning is the actual future for humans for better learning and
understanding. We have made a device that monitors the basic parameters of a person's heart, e.g.,
Heart Rate, ECG, Blood Pressure, and Chest Pain, etc. Using IoT, the device stores the data into
the cloud servers. Using Cloud Computing, the device autonomously applies the Machine
Learning algorithms to the health parameters. It predicts the chances of a Heart Attack.

iv
Table of Contents
Certificate ..................................................................................................................................................... i
Dedication .................................................................................................................................................... ii
Acknowledgments ...................................................................................................................................... iii
Abstract....................................................................................................................................................... iv
List of Tables .............................................................................................................................................. ix
Introduction ................................................................................................................................................. 1
1.1. Project Description........................................................................................................................ 2
1.2. Project Background/Overview ...................................................................................................... 2
1.3. Problem Description ..................................................................................................................... 3
1.4. Project Objectives ......................................................................................................................... 4
1.5. Project Scope ................................................................................................................................ 4
Literature Review ....................................................................................................................................... 6
2.1. Overview ....................................................................................................................................... 7
2.2. Heart ............................................................................................................................................. 7
2.3. Heart Rate ..................................................................................................................................... 8
2.4. ECG (Electrocardiograph) .............................................................................................................. 9
2.5. Blood Pressure ............................................................................................................................ 10
2.6. Chest Pain.................................................................................................................................... 10
2.7. Related Work .............................................................................................................................. 10
2.7.1 Research ................................................................................................................................... 10
Requirement Specifications...................................................................................................................... 13
3.1 Existing Systems ................................................................................................................................ 14
3.1.1 Commercial Products ............................................................................................................... 14
3.1.2 Research Work ......................................................................................................................... 16
3.1.3 Drawbacks/Limitations............................................................................................................. 17
3.2 Proposed System ............................................................................................................................. 18
3.2.1 Proposed System Explained ..................................................................................................... 18
3.2.2 Why this System? ..................................................................................................................... 19
3.3 Requirement Specifications ............................................................................................................ 19
3.3.1 Functional Requirements ......................................................................................................... 20
3.3.2 Nonfunctional Requirements ..................................................................................................... 20
3.4. Use Cases ........................................................................................................................................ 20

v
System Design ............................................................................................................................................ 22
4.1 System Architecture .......................................................................................................................... 23
4.2 Design Constraints ............................................................................................................................ 24
4.3 High-Level Design and Methodology ................................................................................................ 24
4.4 Low-Level Design............................................................................................................................... 26
4.4.1 ESP-32 Dev Module .................................................................................................................... 26
4.4.2 AD8232 ECG Sensor ................................................................................................................... 26
4.4.3 MAX30100 Pulse Oximeter and Heart-Rate Sensor................................................................... 27
4.4.4 Digital Blood Pressure Sensor .................................................................................................... 28
4.4.5 LCD ............................................................................................................................................. 28
4.4.6 Firebase Cloud............................................................................................................................ 29
4.4.7 Machine Learning Model: Support Vector Machine SVM ......................................................... 29
4.4.8 Arduino IDE ................................................................................................................................ 30
System Implementation ............................................................................................................................ 32
5.1 System Architecture (In terms of Implementation) .......................................................................... 33
5.1.1 Hardware ................................................................................................................................... 33
5.1.2 Software ..................................................................................................................................... 35
5.2 Tools and Technology Used .............................................................................................................. 37
5.2.1 Jupyter Notebook....................................................................................................................... 37
5.2.2 Google Firebase ......................................................................................................................... 38
5.3 Development Environment/Languages Used ................................................................................... 38
5.4 Processing Logic/Algorithms ............................................................................................................. 38
System Testing and Evaluation................................................................................................................ 39
6.1 Hardware Testing .............................................................................................................................. 40
6.1.1 Sensors and ESP-32 .................................................................................................................... 40
6.1.2 Data input and Transmission ..................................................................................................... 41
6.2 Software Testing ............................................................................................................................... 43
6.2.1 Firebase Cloud............................................................................................................................ 43
6.2.2 Jupyter Notebook/Machine Learning ........................................................................................ 43
6.2.3 Testing Model with Abnormal Data ........................................................................................... 45
6.3 Accuracy ............................................................................................................................................ 46
Conclusion ................................................................................................................................................. 47
7.1 Challenges and Limitations ............................................................................................................... 48

vi
7.3 Future Work ...................................................................................................................................... 49
References .................................................................................................................................................. 50
APPENDICES ........................................................................................................................................... 52
Appendix A: Code for Hardware ................................................................................................................. 52
Appendix B: Code for Machine Learning .................................................................................................... 60

vii
List of Figures
Figure 1.1: Causes of Death by Percentage [4]............................................................................... 3

Figure 2.1: Structure of the Heart [7].............................................................................................. 7


Figure 2. 2: Physically Measuring HR [9] ...................................................................................... 8
Figure 2.3: Normal ECG [11] ......................................................................................................... 9

Figure 3. 1: Holter Monitor [19] ................................................................................................... 14


Figure 3.2: Apple Watch [20] ....................................................................................................... 15
Figure 3.3: Fitbit Watch [21] ........................................................................................................ 15
Figure 3.4: BodyGuardian Heart [22] ........................................................................................... 16
Figure 3.5: Functional Requirements Block ................................................................................. 20

Figure 4 1: Block Diagram of system ........................................................................................... 23


Figure 4 2: Flowchart .................................................................................................................... 25
Figure 4 3: ESP-32 ........................................................................................................................ 26
Figure 4 4: ECG Sensor ................................................................................................................ 27
Figure 4 5: Pulse Oximeter ........................................................................................................... 27
Figure 4 6: Working of ECG Sensor............................................................................................. 28
Figure 4 7: BP Monitor ................................................................................................................. 28
Figure 4 8: LCD ............................................................................................................................ 29
Figure 4 9: Firebase Logo ............................................................................................................. 29
Figure 4 10: SVM [32] .................................................................................................................. 30
Figure 4 11: Arduino IDE ............................................................................................................. 31

Figure 5. 1: Complete Hardware Design ...................................................................................... 33


Figure 5. 2: ECG Sensor ............................................................................................................... 34
Figure 5. 3: Oximeter .................................................................................................................... 34
Figure 5. 4: Keypad....................................................................................................................... 35
Figure 5. 5: Arduino IDE .............................................................................................................. 36
Figure 5. 6: Firebase ..................................................................................................................... 36
Figure 5. 7: Machine Learning Demo ........................................................................................... 37

Figure 6. 1: ECG Outputs ............................................................................................................. 40


Figure 6. 2: Heart Rate Measurement ........................................................................................... 41
Figure 6. 3: Data Entry.................................................................................................................. 41
Figure 6. 4: Sending Data to Firebase ........................................................................................... 42
Figure 6. 5: Predicted Result ......................................................................................................... 42
Figure 6. 6: Firebase Data Update ................................................................................................ 43
Figure 6. 7: Data update in ML Model ......................................................................................... 44
Figure 6. 8: Predicted Results from the Model ............................................................................. 44
Figure 6. 9: Abnormal Data .......................................................................................................... 45
Figure 6. 10: Prediction with Abnormal Data ............................................................................... 45

viii
List of Tables
Table 2.1: Heart Rate Table [10] .................................................................................................... 9
Table 2.2: Blood Pressure by Age/Gender [13] ............................................................................ 10
Table 2. 3: Table of Literature Review ......................................................................................... 12

Table 3.1: Existing System Drawbacks ........................................................................................ 18

ix
Chapter # 01

Introduction

IoT Based Heart Attack Monitoring and Prediction System 1


1.1. Project Description
IoT and Machine Learning are the two most demanding fields of technology these days. Without
them, we cannot think of an innovative and intelligent future. These technologies help us daily in
our educational system, security systems, healthcare, and industries.
IoT-Based Heart Attack Monitoring and Prediction System is related to the medical and healthcare
field. It is made to improve healthcare facilities in our world and make it easier for everyone to
take care of their health. It is a device that our world needs the most. It consists of a few sensors
working with the microcontroller, which monitors the basic parameters of a person's body; using
the Internet of Things, Cloud Computing, and Machine Learning techniques predicts the upcoming
Heart Attack before it happens.
The whole process of the device is autonomous, which means once a user wears this device, it
starts monitoring heart health right away. The system deals with the knowledge domains like the
Internet of Things, Machine Learning, Embedded Systems, Cloud Computing, and Sensor
interfacing, etc. it is very vital to make these kinds of the healthcare system because it can make
real-time monitoring very easy, and it can reduce the cost of healthcare significantly if used in
hospitals.

1.2. Project Background/Overview


The Heart Attack is taking the lives of people every day. According to WHO, heart diseases are the
leading cause of death in the world, with the estimated deaths of 17 million lives each year [1].
Heart attack or strokes are events that are usually caused by due to the blockage of the blood in
the blood vessels. One of the main reasons for this is the blockage formed due to the fatty acids in
blood vessels that transfer blood to the brain and heart. Heart Attack can also happen due to the
blood clot due to the vessels' bleeding injury. The most main cause of heart attacks is usually the
combination of risks, such as smoking, unhealthy diet, physical activities, and use of alcohol [2].
The table given below shows the death percentages by diseases [3].

IoT Based Heart Attack Monitoring and Prediction System 2


Figure 1.1: Causes of Death by Percentage [4]

Every day we see people dying out of heart attacks and strokes. There was the need for a device
that can predict a heart attack or any other cardiovascular disease before it happens.
This device has been created to fulfill that space in healthcare for the betterment of society. It is
made to minimize the death toll due to CVDs increasing every year dramatically and saving the
lives of millions of people worldwide. It is made to make quick action possible and let authorities
act fast in case of emergencies to save lives. This device can be a lifesaving tech for many people.

1.3. Problem Description


Heart Diseases are widespread among people. According to research done by every 36 seconds, a
person dies in the USA due to heart disease [4].
• Many third-party companies like Apple, Samsung, Huawei and Haylou, and other brands
have made their commercial healthcare products like smartwatches and innovative bands.
Still, there is no such product in the market for ordinary people to monitor their heart health
regarding heart patients and heart attacks.
• The lack of development in this field has led many people to death because it is infeasible
for someone to go to the healthcare center every day, week, or so to take care of themselves.
• There is a massive shortage of intelligent devices. Also, there is no system made that can
predict what is coming next for severe patients.

IoT Based Heart Attack Monitoring and Prediction System 3


• Also, there is a significant shortage of medical staff in healthcare centers for heart patients
and all, making it impossible for someone to monitor someone's health 24/7.

1.4. Project Objectives


About 50% of the people who suffer a stroke die suddenly on the spot, and the remaining 50%
have to get immediate help in 1-2 hours. People lose consciousness. They cannot even control
themselves when they experience a stroke, so what if we make a device that can first tell the user
before a heart attack happens. In case of stroke, it can say to the family and send alerts to the
doctor? This is what our thesis is focusing on.
the main objectives of this thesis are.
• Mainly to make a device that monitors and predicts heart attack by using a few sensors to
monitor health parameters related to heart attack and then apply machine learning
algorithms to predict the final result.
• Another objective of the making is to introduce a wearable device commercially to
everyone to not rely on doctors and hospitals for their heart condition every day. This
means this device will monitor the patient's health in real-time and save the previous history
of that person in the cloud for later use. This way, a patient can show his weekly or monthly
progress to his doctor to analyze the weekly/monthly health patterns.
• One of the primary and very productive objectives or goals was to interlink Electrical
Engineer, Telecommunication, Cloud Computing, and Machine Learning to better
healthcare facilities.
• This thesis explains how to make a low-cost but cost-effective and very productive device
that can change the future of the medical field in the coming days.

1.5. Project Scope


The scope of this project is divided into two parts.
i. Hardware Part
This part consists of an ESP-32 dev board and the wearable sensors network, which is used
to monitor the health parameters like ECG, Blood Pressure, Heart Rate, Chest Pain, etc.

IoT Based Heart Attack Monitoring and Prediction System 4


Wi-Fi will enable the device to connect in between the clouds to continuously receive and
transform the data.
ii. Software Part (Cloud): for collecting data and applying Machine Learning algorithms
This part is mainly consisting of Cloud Computing and Machine Learning algorithms. The
data from the wearable hardware device is being sent to the Firebase Cloud, where this data
is being fetched to the machine learning cloud platform for implementing machine learning
techniques to predict the final result.

This device deals with a loT of Electrical Engineering fields such as,
i. Communication between devices
ii. Internet of Things
iii. Sensors Interfacing
iv. Circuit Analyses
v. Machine Learning
vi. Cloud Computing
vii. Microcontrollers and Processors
viii. Datamining
ix. Servers interfacing etc.

IoT Based Heart Attack Monitoring and Prediction System 5


Chapter # 02

Literature Review

IoT Based Heart Attack Monitoring and Prediction System 6


2.1. Overview
Some vital parameters can be monitored consciously for heart patients to keep a check on their
condition. Any abnormal changes in these signs can indicate that the person's health is not good,
and he/she needs to go for a checkup as soon as possible. Sadly, no such portable device can
monitor and predict the precise results and can be used commercially.
This report has proposed a portable, wearable, and commercial system that monitors these health
signs to predict future heart attacks. These are the topmost vital signs to check the health of the
heart. [5]
1. Pulse Rate/Heart Rate
2. ECG – Electrocardiogram
3. Blood Pressure of body
4. Chest Pain

2.2. Heart
Our heart is the leading and most essential part of the human body. It is responsible for supplying
blood to every corner of our body. A heart can be found at the thorax, off to the left, covered by
the lungs. Our heart comprises two separate pumps, the right one, which pumps the blood through
the lungs, and the left one, which pumps the blood through the peripheral organs. Each of these
hearts is a pulsatile two-chamber pump composed of an atrium and a ventricle.

Figure 2.1: Structure of the Heart [7]

IoT Based Heart Attack Monitoring and Prediction System 7


2.3. Heart Rate
Heart Rate can simply be described as the rate at which the heartbeats. It is measured in BPM,
which is beats per minute. It is related to the physical expansion and contraction of the arterial wall
of the heart. A few areas to check the pulse rate physically are, wrist, around the neck, elbow, and
behind the ear.
Heart rate varies from age to age. It can be different for a different group of ages.
The average heart rate for adult’s ranges from 60-100 BPM [6]. Various factors can influence the
heart rate in other cases, such as

• Person's age
• Fitness of the body
• Being a smoker or not
• Having a previous heart disease record,
• Body position (standing up or lying down, for example)
There is also a general formula to determine the average heart rate of different ages.
220 - Age = Maximum Heart Rate
Although there are various standard and abnormal heart rates, unusually high or low heart rate can
signify a problem. One should immediately consult a doctor.

Figure 2. 2: Physically Measuring HR [9]

IoT Based Heart Attack Monitoring and Prediction System 8


Table 2.1: Heart Rate Table [10]

Age Ideal Heart Maximum Heart


Rate BPM Rate BPM
20 years 100-170 200
30 years 95-162 190
40 years 90-153 180
50 years 85-145 170
55 years 83-140 165
60 years 80-136 160
70 years 75-128 150

2.4. ECG (Electrocardiograph)


ECG or Electrocardiograph detects and records the electrical signals generated due to the pumping
of the heart. A small fraction of electrical current flows through our body when the heart pumps
blood to our whole body.
A normal ECG is shown in figure 2.3.

Figure 2.3: Normal ECG [11]

ECG plays the most critical and crucial role in determining the patient's heart health and history.
ECG is to read by professional doctors because it contains information that ordinary people cannot
translate. Also, HR can be calculated by the ECG patterns [7].
To predict the heart attack, ECG can be beneficial, as it contains the whole data patterns of the
heart.

IoT Based Heart Attack Monitoring and Prediction System 9


2.5. Blood Pressure
One of the most essential parameters to monitor for heart patients is Blood Pressure. During the
heart attack, blood flow gets blocked due to the blockage of the arteries and veins, which force the
heart to pump the blood, which sometimes leads to a decreased or increase in blood pressure.
Regular high blood pressure is one of the leading causes of damage to the veins, leading to a heart
attack. Heart Attack is caused by high blood pressure, which damages arteries that can become
blocked and prevent blood flow to the heart muscle.
Table 2.2: Blood Pressure by Age/Gender [13]

Age (years) Blood Pressure mm Hg


Men
18–39 119/70
40–59 124/77
60 + 133/69
Women
18–39 110/68
40–59 122/74
60+ 139/68

2.6. Chest Pain


Chest Pain is another symptom of the upcoming heart attack. Chest Pain is one of the most obvious
and prominent signs of stroke. If someone notices even the slightest change in the chest, then he
or she should definitely seek the doctor's help. Pressure develops pain in the chest. Pain, numbness,
pinching, prickling, or other uncomfortable sensations in one or both arms, the back, neck, jaw, or
stomach etc.

2.7. Related Work

2.7.1 Research
As mentioned earlier, there are many more people who suffer from heart problems. There is
therefore a need for daily monitoring and testing related to heart problems. Since it is not possible
to go to the hospital every day, people have made many requests and solutions for health care.

IoT Based Heart Attack Monitoring and Prediction System 10


However, each device is different from the other. We need to improve the details of the health
monitoring system available in the consumer market.
In 2018 [13], Dr. Jayant Shekhar researched how he used a temperature sensor and heart rate sensor
with Arduino to monitor heart health. In case of any abnormality, he used IoT to inform the
respective authorities. He used ThingSpeak for storing the data for future and further use. This
device is an innovative and little development in heart attack prediction. Our fundamental research
was started on his research. He tried to look after the temperature and heart rate of the body. If
these parameters behave abnormally, he made an algorithm that sends alerts.

According to a study by Ordonez, heart disease can be predicted by key symptoms taken from a
patient. They have introduced a system that includes individual traits according to 13 key
indicators such as gender, blood pressure, cholesterol, heart rate, ECG, and others to predict the
same. [8].

Another research done by Priyanka Kakria, in 2015 [9] was significant literature this report, they
made a heart monitoring system for remote cardiac patients in which they developed a system
consisting of the wearable sensor along with IoT technologies to send alerts in case of emergency,
their alert system was a significant achievement.
In another research done by Fizar Ahmed in 2017 [10], he made a model consisting of IoT
applications and wearable sensors like heart rate and blood pressure machine learning algorithms
to predict a heart attack. This research help is making us with this project, and we learned a lot
from the research of Fizar Ahmed.

Fares Sayah, in 2020 wrote an article in which using 13 attributes, including heart rate. Chest pain,
ECG, exercise-induced angina, he made an algorithm to predict the heart attack [11]. He used over
300 entries of the data for training the system. He proposed different algorithms for accuracy,
including KNN and random forest.
A brief table on the literature review is given below for a better understanding. Note: this is not all
possible and available data on the selected topic. This is just a chunk out of it, a tip of the iceberg.
For more detail about the Existing system, it guided you to take a look at section 2.3.

IoT Based Heart Attack Monitoring and Prediction System 11


Table 2. 3: Table of Literature Review

Author/Date Topic Goal Methodology

Temperature and Heart To monitor heart


Dr. Jayant Arduino with Temp. sensor and
Attack Detection using rate and
Shekhar, 2018 pulse sensor
IoT temperature

Health Monitoring
To monitor the
Priyanka System for Remote Wearable’s sensor and IoT to
health of cardiac
Kakria, 2015 Cardiac send data to healthcare centers.
patients
Patients

IoT Application for Prediction of the


Nizar Ahmed, Wearable sensors + Machine
Prediction of Future upcoming Heart
2017 Learning
Heart Attack attack

Heart Disease Detection


Shadman To Predict Heart Heart rate sensor + Machine
by Using Machine
Nashif, 2018 Diseases using ML Learning
Learning Algorithms

Predicting heart disease To Predict Heart Machine Learning Algos on


Fares Sayah,
using machine learning Diseases using ML Existing Dataset
2020

Health Diagnosis by to detect underlying


E. Sathish, Wearable sensors + Machine
Using Machine Learning heart conditions in
2019 Learning
Algorithms real-time

IoT Based Heart Attack Monitoring and Prediction System 12


Chapter # 03
Requirement Specifications

IoT Based Heart Attack Monitoring and Prediction System 13


3.1 Existing Systems
There has been so much development regarding healthcare facilities in the world. Some companies
and brands have made their commercial product, and some people are still finding the best way to
protect the health of people around us. For this purpose, we have divided this section into two
parts.
1. Commercial Health Monitoring Products: That are available in the market for use.
2. Research Work: Proposed systems from research, either Prototypes or just Reports.
3.1.1 Commercial Products
Many companies and brands made their commercial product to keep track of their heart health
regarding heart health. There are so many third-party devices available, but we have selected a few
bests that are truly deserving to be mentioned here. [12]
Holter Monitor
A Holter Monitor is a portable heart health device that measures heart activity. It is almost the size
of an old mobile phone. The device is used by attaching it onto the patient's skin, just like an ID
card.

Figure 3. 1: Holter Monitor [19]

The main feature of the device is that it is easy, comfortable, and involves no fatigue. It can also
be worn even at night, and it will not affect sleep. This device can be used to figure out if a person's
pulse is slow, fast, or abnormal. Also, if an individual has a pacemaker, it can determine if it is
working good or not.
This device has the same model that we are going to build, and it resembles a lot of our machines.

IoT Based Heart Attack Monitoring and Prediction System 14


Apple Watch
The Apple Watch monitors the heart regularly 24/7. With Apple Watch, one can check your heart
rate and heart condition no matter where you are. Apple Watch has an alert button that enables a
person to seek help when someone needs it. It is helpful if you are into health and activity tracking.
Being able to switch the watchbands so easy is excellent. Do not buy the official ones, though, if
you are not insane. The Apple Watch actually reignited interest in regular, mechanical watches.
The old one just feels so much better.

Figure 3.2: Apple Watch [20]

Fitbit
Fitbit is a fitness brand made for people who want to track their fitness routine. They also make
smartwatches or smart monitors for heart health. These are fitness trackers and have all basic set
features that a heart patient would need to be notified of with every update.

Figure 3.3: Fitbit Watch [21]

Fitbit has a heart monitor that shows the person's pulse rate and is also the main feature of this
fitness device. It is an innovative yet compact addition to the heart monitors.

IoT Based Heart Attack Monitoring and Prediction System 15


BodyGuardian Heart
BodyGuardian is a wearable heart device with many heart health factors. One can simply attach it
to the skin, and it will measure your heart rate, respiration, and other vital parameters. It comes
with a dedicated app for health history and alert features. People can contact family, their
physician, doctors, and their caretakers have access to it. We can use device whom to send the
alert in case of emergency.

Figure 3.4: BodyGuardian Heart [22]

3.1.2 Research Work

When it comes to the researched work and the systems that are closer to the one, we are making,
there are many honorable mentions. All of the methods that are proposed by the researcher are
mentioned and explained below.
There was a plan proposed by G. Parthiban and S. Srivatsa, where they have developed a device
that helps to bring back good encounters even in non-specific attributes of the category we are
trying to predict. They have been trying to predict the risk of heart disease using symptoms from
diabetes tests in their work. They have shown that it is possible to assess the risk of heart disease
in diabetic patients with the correct accuracy. Classifiers of this type can help detect early exposure
to a diabetic patient. That way, patients can be warned in advance about changing their habits. Use
qualities such as gender, age, Family Heredity, Weight, BP, and cholesterol, etc. [13]

A research paper by A.G.Srinivas reviewed the problem of dealing with different types of data
mining [14]. They focused on using various techniques to predict targeted behavior. This paper
presents the most automated and effective methods of predicting heart attacks using data mining

IoT Based Heart Attack Monitoring and Prediction System 16


techniques. They have provided an effective way to extract basic patterns from the details of heart
disease. Depending on the weight of the calculated weight, standard patterns with a more excellent
value than the limit are chosen to predict a heart attack.
This can go on and on. By predicting a heart attack, at most, 15 traits have been listed in medical
textbooks. Apart from this list, they had to include other factors that would affect the results, such
as financial status, stress, pollution, and past medical history. [14].

In another paper, the researchers tried to add the portability of Holter monitors and the processing
power resting ECG machines to provide diagnosis solutions using smartphones. [15].

Researchers Another project introduces a process of event planning in terms of data support
systems. This approach leads to reduced power consumption and extended battery life. Their
experiments show that their real-time classification system exceeds existing methods. [16].

Another research paper was read when it was developed by two sub-systems connected wirelessly
using Bluetooth technology. A sensory support system records the heart's electrical activity in the
chest area to produce an electrocardiogram (ECG). It refers to this sub-system in the decision-
making process where the symptoms of a heart attack are detected. It was noted that the linear
algorithm was unable to detect heart attacks with disturbed and noisy details. [17]
3.1.3 Drawbacks/Limitations
As we have divided the existing systems into two parts, we will explain the limitation and
drawbacks of both the systems step by step. There are problems and constraints on both of them,
and we are keen to cater to them all in our proposed system.
• When we talk about the commercial devices available from many brands in the market, many
of them are just using the sensor's output and then predict the chances of heart diseases based
on the abnormality of the health parameters. They do not have reliable results that can be
obtained by using machine learning algorithms. Also, they are costly systems that do not justify
the price to value ratio.
• When we talk about the proposed system, one of the major drawbacks is that they never see
the day's light and are just there on paper. Secondly, all the systems are not portable or
wearable, just like the way we are doing. Some plans are using machine learning, AI, and data

IoT Based Heart Attack Monitoring and Prediction System 17


mining techniques but their systems are not autonomous. The training dataset from one place
and testing dataset use the wearable sensor, then applies algorithms separately and predicts the
results one time.
Table 3.1: Existing System Drawbacks

Type Drawbacks
Commercial They do not have reliable prediction algorithms; they just rely on
abnormalities in the parameters, i.e., limiting on the threshold
values
Research Pieces They do not have a completely autonomous system in a wearable
form that is both reliable and portable.

3.2 Proposed System


Our proposed system, "IoT Based Heart Attack Monitoring and Prediction System," is a system
that combines all the pros from the previously existing systems and avoids all the limitations and
drawbacks that those systems had. We made this device so that it fulfills all the necessities that a
heart patient needs.
Our device consists of a wearable sensor network for measuring heart health parameters. The
whole prediction and monitoring process is done on the cloud, making this device small in size
and much more cost-effective.

3.2.1 Proposed System Explained


As described in the project description, this system has two significant parts: hardware and
software modules.
• The hardware part consists of wearable sensors like ECG, Heart Rate, and Blood Pressure
sensor. It also has a Physical keypad for Chest Pain and Age/Gender data entry. The heart
of this device is the ESP-32 Dev module which is doing all the hectic work.
• The hardware part is a complete package that measures all the parameters required to
monitor heart health.
• Now every reliable system should have a reliable predicting mechanism. This is where the
software part of the proposed system comes in. We use machine learning algorithms like

IoT Based Heart Attack Monitoring and Prediction System 18


the random forest, decision tree, KNN, SVM and others for more reliable and accurate
results. SVM produced most accurate results, so we decided to go with it.
• Firebase Cloud and Jupyter Notebook are being used for fast and reliable Cloud
Computing. This is how we made this device small in size, keeping the machine's integrity
high.
• Once a user wears it, it will take all the heavy work all by itself, and no one has to do
anything. The user will just have to see the results casually.

3.2.2 Why this System?


Why this System? Why is this system so valuable for the people and the healthcare system? The
answers to all these questions are below.
• This device is tiny and wearable, which makes it cost-effective and less of a burden.
• This has all the pros from the existing system like real-time monitoring, sending alerts in case
of any abnormality, and making quick action possible.
• This device takes the existing research by making a product for commercial use by integrating
all the ideas in a small device.
• It neglected both the cons of commercial and Researched works, e.g., this device is
autonomous. It predicts the results by using machine learning algorithms that are more reliable
than just sending alerts based on threshold values.
• This device has all the features that a modern health tracer provides.
• This is the only device that predicts heart attack in a more prominent and usable way.

3.3 Requirement Specifications


The requirement specification part is divided into two parts.
• Functional requirements and
• Nonfunctional requirements
Both of the requirements are explained below in a very detailed manner.

IoT Based Heart Attack Monitoring and Prediction System 19


3.3.1 Functional Requirements

Figure 3.5: Functional Requirements Block

• The system takes the basic selected heart parameters for heart health and predicts the chances
of a heart attack.
• The system should allow the user to monitor and remove wrong datasets.
• The system should take the parameters continuously and monitor health 4/4.
• The system should send Alerts in case of emergencies to family members and healthcare
centers.

3.3.2 Nonfunctional Requirements


• The system should provide values used during prediction to the user.
• The system should store the values in cloud platforms or APP for health history.
• The system should be responsive and consistent.
• The system should use IoT, Cloud Computing, and Machine Learning techniques to their fullest
to improve the accuracy of the predictions.
• The system should be a wearable system that can be portable and used in any place.
• They should be autonomous, just like the typical intelligent systems.
• The system should minimize the delay between the data transfer within and outside the
hardware device, e.g., to clouds and servers.
• The system should predict the heart attack before happening to minimize the chances of
casualties.

3.4. Use Cases


This section was all about the use cases of this system and explained how users will use and interact
with the device, what could be the use cases.
Actor: A heart patient
Supporting actor: Sensors and microcontrollers, other simulation systems

IoT Based Heart Attack Monitoring and Prediction System 20


Goals: A heart patient wears the system and wants to monitor his health.
Main Success Scenario:
• A user wears the device and turns it ON.
• The user enters the login credentials.
• The device turns ON the sensors and starts monitoring the health parameters.
• The sensor data goes into cloud storage for further use and storage for history.
• The Cloud Computing part of the device fetches the data from the cloud.
• It also gets the training dataset from the source.
• Machine Learning algorithms are applied.
• The results are being predicted.
• The device gets the predicted results on LCD.
• Users see the result and relax.
• The health history and parameters are being stored in the application and cloud.
Special Requirements
The efficiency of the algorithm for simulation affects performance metrics. The parameters like
Heart Rate, ECG, and Blood Pressure may affect the accuracy when the device is not worn
correctly and the number of computations that the algorithm uses in each step.

IoT Based Heart Attack Monitoring and Prediction System 21


Chapter # 04

System Design

IoT Based Heart Attack Monitoring and Prediction System 22


The project design one of the most critical stages hence this step takes considerable time of the
overall project time. Previously we have summed up the foundation and best in a class of this
theory project, including an outline of the checking and forecast framework. It additionally
investigated the current frameworks which cover wellbeing checking. This section will detail the
proposed plan of the framework for foreseeing the heart attack from gathered information from
sensors. Hence, there is a short portrayal of the framework design and the usefulness every module
has. Both equipment and programming plans are being examined here seriously, depicting their
segments, calculations, and their circuit designs.

4.1 System Architecture


As described earlier, this project is divided into both the hardware and software parts. Each part
and module are essential for the project, and it is explained below in a very detailed manner. The
figure below shows the basic block diagram of the project. It helps the reader to grasp the
essential parts and modules used.

Figure 4 1: Block Diagram of system

The whole architecture is explained in HLD and LLD in detail, starting from the hardware parts.

System hardware includes,


• ESP 32 Dev Module, which has a dual-core processor to perform fast calculations.

IoT Based Heart Attack Monitoring and Prediction System 23


• AD8232 ECG Sensor for measuring the ECG signal.
• A Pulse Oximeter for measuring the heart rate.
• A BP monitor for measuring the Blood Pressure.
• A physical keypad for chest pain alerts.
• An LCD for displaying the results.
The Software architecture includes.
• Firebase Cloud for storing the measured parameters.
• Arduino IDE for sensor interfacing and data collection in ESP-32.
• Google Colab/Jupyter Notebook for machine learning implementation.

4.2 Design Constraints


When looking for the best sensor or monitor for the blood pressure measurement in our project,
we went through a severe problem, there is no blood pressure monitor available in Pakistan, both
online and offline markets, that can be attached with the microcontrollers to get the readings. There
are commercial BP monitors available in the market but, they are not usable with microcontrollers
because they do not have such external serial ports to be used with MCUs.
This was a severe design constraint when finalizing the project. To solve the problem of BP
measurement, a BP monitor was taken, and using the techniques of circuit analyses and circuit
design, we tried to get the PCB open so that a serial connection can be obtained from the I2C IC
on the PCB of the blood pressure monitor so that we can finally make a sensor out of it. I took us
many days to figure out and then after failing two times we decided to go for manual entry.

4.3 High-Level Design and Methodology


The flowchart below is showing how the whole process is being done autonomously. As
described in earlier stages, the hardware part and software part are integrated so that the entire
process runs in a very smooth stream.

IoT Based Heart Attack Monitoring and Prediction System 24


Figure 4 2: Flowchart

• Firstly, there are three sensors used for measuring ECG, Heart Rate, and Blood Pressure.
Also, there is a physical keypad for chest pain alerts. All these sensors are analog. Using
the inbuilt ADC and DAC, the signals from these sensors can be translated to the medium
of choice.
• ESP-32 gets the data from these sensors in one of the 16 ADC pins, and using the inbuilt
Wi-Fi, it sends this data to the firebase cloud for storage, where the whole history is stored.
• For the machine learning part, we have Jupyter Notebook. We have implemented our SVM
model, support vector machine, a highly efficient supervised machine learning model. This
model will be trained with the training dataset of around 1500 samples, and it will also
fetch the data from the firebase cloud.
• The training dataset has parameters like Age, Gender, Heart Rate, ECG, Blood Pressure,
and Chest Pain.
• After training our model, the data measured from the sensor comes in the model where the
final result is being calculated.
These results are shown on the LCD and also on the APP.

IoT Based Heart Attack Monitoring and Prediction System 25


4.4 Low-Level Design
The low-level design of the system is explained in two parts, hardware, and software modules.
Below is the explanation of the blocks and modules that lie in high-level design.
4.4.1 ESP-32 Dev Module
ESP-32 is a high-speed and efficient microcontroller with inbuilt Wi-Fi and Bluetooth modules
for several applications. It is considered one of the best for IoT-based projects that is why we went
with it. ESP32 gives several functions and ways to work with many sensors and circuits. ESP32
can work as a completely standalone device or as a slave device to a host of another
microcontroller, reducing communication stack overhead. [18].

Figure 4 3: ESP-32

There are around 40 ADC Pins, of which 34 can be used as GPIO,


Some of the essential features are.
• External Memory Flash 4MB
• ADC and DAC

• Touch Sensor

• 32-Bit CPU

4.4.2 AD8232 ECG Sensor


The AD8232 is a very effective single lead ECG sensor that uses the op-amp circuitry to amplify
the signals from the heart to produce ECG. The electrical signals can be obtained as an
Electrocardiogram [19]. ECG can be quite full of noise. The AD8232 acts as an op-amp to help
obtain a clear and noise less signal.

IoT Based Heart Attack Monitoring and Prediction System 26


Figure 4 4: ECG Sensor

The AD8232 uses an integrated circuit for the signal conditioning to be used with microcontrollers,
making it the best device to use in electronics and biomedical projects.
The AD8232 Heart Rate Monitor has 9 pins. Also, there are Right Arm, Left Arm, and Right Leg
pins to attach to the body and get the signals from the heart. Furthermore, there is also an LED
indicator that beats with every heartbeat.
One main feature is the Operating Voltage range of 3.3V
4.4.3 MAX30100 Pulse Oximeter and Heart-Rate Sensor
The MAX30100 is an integrated pulse oximeter and heart rate sensor which can measure both the
blood oxygen level and BPM beats per minute of a person's body. It uses the photodetector to
detect the reflected light and measures both parameters using analog signal conditioning.
it usually operates in the voltage range of 1.8V and 3.3V. [20].

Figure 4 5: Pulse Oximeter

Key Features are as follows.


• Monitors Heart Rate and Blood Oxygen Saturation level.
• Has Photo Sensor
• Works with Ultra-Low-Power Operation

IoT Based Heart Attack Monitoring and Prediction System 27


Figure 4 6: Working of ECG Sensor.

4.4.4 Digital Blood Pressure Sensor


Regular Blood Pressure monitors are cumbersome, and it is tough to use them without someone
help. While digital wrist blood pressure monitor is straightforward to use and operate.

Figure 4 7: BP Monitor

The LCD will show your systolic blood pressure, pulse rate results in no time.
4.4.5 LCD
An individual definition comes from a liquid crystal or LCD. It is the synthesis of two types of
matter, solid and liquid. A liquid crystal is used to create a transparent LCD. Liquid crystal displays
are highly technological displays commonly used for desktops, TV, smart telephone, and video
games. LCD technology needs far slimmer displays in comparison to Cathode-Ray tube
architecture.

IoT Based Heart Attack Monitoring and Prediction System 28


Figure 4 8: LCD

4.4.6 Firebase Cloud


For storing the data measured from the sensors, google firebase is being used. Firebase is one of
the best service solutions out there, and it is backed by Google. It has everything that you need.

Figure 4 9: Firebase Logo

Numerous engineers appreciate utilizing Firebase since it lets loose them from a portion of the
difficulties they had before while building up the backend of their product or application. Firebase
gives a large number of the devices and administrations that a designer needs while completing
their work. Instead, engineers can make an extraordinary encounter inside their application for the
clients rather than get disappointed with the entirety of the specialized coding items.
4.4.7 Machine Learning Model: Support Vector Machine SVM
One of the most absurd and complex tasks that come in when working with machine learning is
selecting a proper, efficient model. After going through many research and tests, and trials, we
decided on the SVM machine learning model to perform better and accurately.
Support Vector Machine (SVM) is a supervised binary classification algorithm. Given a set of
points of two types in NN dimensional place, SVM generates an (N−1) (N−1) dimensional
hyperplane to separate those points into two groups [21].

IoT Based Heart Attack Monitoring and Prediction System 29


Figure 4 10: SVM [32]

SVM will use the trick to find the hyperplane. Now you can cut the area near the apex to separate
those red points from blue. We can think of another 2D plane that performs the task of cutting.
That 2D2D plane is our desired hyperplane.

4.4.8 Arduino IDE


Arduino IDE is software that is used to code for the Arduino boards. It enables better code editing
and debugging. Arduino IDE is the Integrated Development Environment developed by the
Arduino Company to give the Arduino board developers an interactive environment. IDE is
available for all major OS. It was written in Java Programming Language and highly similar to
C++. Arduino IDE supports the Languages C and C++to upload into the Arduino boards.
It is also compatible with all the Arduino-compatible development boards like ESP-32, making it
the best choice for using it with ESP-32.

IoT Based Heart Attack Monitoring and Prediction System 30


Figure 4 11: Arduino IDE

IoT Based Heart Attack Monitoring and Prediction System 31


Chapter # 05

System Implementation

IoT Based Heart Attack Monitoring and Prediction System 32


This chapter is related to the design and implementation of our project. There are two significant
portions of the Implementation of the project.
1.Hardware
2.Software

Figure 5. 1: Complete Hardware Design

5.1 System Architecture (In terms of Implementation)


Firstly, we will talk about the hardware part of the system.
5.1.1 Hardware
The central part of the device is the ESP-32, responsible for getting data from the sensor, signal
conditioning, and data transmission from the device to the servers and apps. ESP-32 is powered
by a 5V DC source, and it has several ADC, DAC, and GPO pins for any kind of sensor to work
with. Along with the ESP-32, the AD832 ECG sensor is connected using the ADC pin of the
development module. It works on 5VDC, and it has three connection points. One is the primary
wire transferring the ECG signal to the device. Others are VCC and ground connections.

IoT Based Heart Attack Monitoring and Prediction System 33


Figure 5. 2: ECG Sensor

There is a Pulse oximeter used to get the readings of blood oxygen level and Heart rate. It works
on 3-5 VDC, and it is also connected to the ADC pin of the ESP-32.

Figure 5. 3: Oximeter

Along with these, we have a digital Blood pressure monitor, which is serially providing the
measured readings to the ESPP-32 using the serial ports. The BP monitor has its own battery
system, so it has to be charged with external batteries.
There is a keypad for Chest Pain. It is used when a person feels pain in their chest, and by pressing
the emergency button, an alert will be generated.

IoT Based Heart Attack Monitoring and Prediction System 34


Figure 5. 4: Keypad

ESP-32 has an integrated Wi-Fi Module that enables it to work with different IoT devices. We are
using this module to send the data measured from all the sensors to the firebase cloud for storage
and history.
A keypad is added with the device that enables it to input the data from the user, such as their age,
gender, and other necessary information, which is highly important in machine learning aspects.
Also, there is a 16x2 LCD for showing the typed information and predicted results.
This was the complete hardware architecture explained briefly.
5.1.2 Software
This section will discuss and explain the software architecture of the whole system. We will see
how the hardware part is interacting with the software and vice versa.
Arduino IDE for ESP-32
The environment used for coding the ESP-32 Module is Arduino IDE which is basically the C++
language optimized to work on Arduino or Arduino-like boards. Fortunately, ES-32 is one of them,
and it was fascinating to work on Arduino IDE.
The programming part of all the sensors has been done in the IDE. Also, the Data transfer is
done by coding the Wi-Fi module.

IoT Based Heart Attack Monitoring and Prediction System 35


Figure 5. 5: Arduino IDE

Google Firebase for Data Storage


The data from the device is transferred to the Google Firebase for storage purposes and the
Machine Learning models. Google Firebase is the perfect place where you can simply sign in,
get the auth keys and start getting the data from your electronic devices or any other software-
related products.

Figure 5. 6: Firebase

IoT Based Heart Attack Monitoring and Prediction System 36


Google Colab and Jupyter Notebook for Machine Learning
As machine learning is the core of this device and has to be autonomous and backed up with the
cloud, our best solution is to go with Google Colab for cloud computing and machine learning
deployment. Google Colab is explained in detail in the above section. The figures below show the
platform's interface and how programming is done in the platform. It is similar to work with just
like Jupyter notebooks.

Figure 5. 7: Machine Learning Demo

5.2 Tools and Technology Used


To make the device with that extensive scope, we have to use up to date, faster, and less expensive
tools to ensure a smooth run for a longer time. Just like every other hardware and software hybrid
project, this project also needed some of the latest tools to work. Below all the tools and
technologies used in this project are explained.
5.2.1 Jupyter Notebook
One of the significant parts of this device is machine learning. To implement the machine learning
models, one of the most prominent languages used by professionals is Python. Jupyter Notebook
is just like, Python, but with extra and enhanced features, like real-time visualization of the data,

IoT Based Heart Attack Monitoring and Prediction System 37


cloud computing features, and many more. Using Jupyter Notebooks for the development of this
device has helped to make this dream a reality.
5.2.2 Google Firebase
One of the most hectic problems people face is making web pages or using the web servers for
real-time storage and monitoring for healthcare devices. It is essential to have a place where the
relative or related person could check on the patient's health parameters. For this device, Google
Firebase acts as the data storage and real-time data interpreter. It works really fast and has equal
to no lag or latency.

5.3 Development Environment/Languages Used


For this device, there are two development environments, and both use two different languages.
For the hardware wearable sensor network, we are using the Arduino IDE, which basically uses
the C++ language to code the Arduino or similar boards.
For the software part, mainly machine learning, we use the Jupiter Notebooks, which uses Python.
All the machine learning part is done in the python language using the Jupyter Notebook.

5.4 Processing Logic/Algorithms


This section is related to the algorithms used in the system, as this system has two main modules,
one of hardware and one is machine learning module, so this device works on two main algorithms
and logics.
• Code for Hardware and
• Programming for the Machine learning

IoT Based Heart Attack Monitoring and Prediction System 38


Chapter # 06

System Testing and Evaluation

IoT Based Heart Attack Monitoring and Prediction System 39


System testing is one of the most crucial parts of one's product or device. Keeping in mind that
there is no such thing as perfect in this world, we have made this section very clear for the readers
to fully understand the pros and cons of our device.
This section will guide you through the phases of testing, which are, hardware part testing, firebase
cloud testing, and machine learning model testing.

6.1 Hardware Testing


Hardware testing includes testing of ESP-32, all the sensors, Wi-Fi module, Keypad, and LCD.
We have tested the hardware under all possible conditions, and a brief report is given below
showing the results.
6.1.1 Sensors and ESP-32
One of the device's main features measures all the essential heart health parameters using the
wearable sensor network, which includes heart rate and blood oxygen saturation sensor (oximeter),
blood pressure monitor, and ECG sensor.

Figure 6. 1: ECG Outputs

The figure above shows the ECG outputs measured by the ECG sensor. It shows the ECG curves
that can be used to see whether the heart patterns are normal or abnormal. The data can be sent to
the doctor to be analyzed. The code written for the ECG curve can predict whether the ECG
patterns are normal or abnormal. The device is capable enough to make decisions of its own to
categorize the data into different tags, such as normal or abnormal ECG graphs.

IoT Based Heart Attack Monitoring and Prediction System 40


Figure 6. 2: Heart Rate Measurement

Similarly, the Heart Rate and Blood Oxygen are being measured in the figure above. Pulse
Oximeter is being used for measuring the Heart rate and blood oxygen levels of the body. As
shown in the figure, pulse and oxygen levels are being updated live on the screen. The sensor
works simply by putting the fingertip on the light source of the sensor. Similarly, the data from the
BP monitor is being measured.
6.1.2 Data input and Transmission

Figure 6. 3: Data Entry

IoT Based Heart Attack Monitoring and Prediction System 41


Credentials like age and gender are equally crucial for predicting the chances of heart attack as
heart rate or blood pressure. As there is no such sensor that can figure out the age or gender of the
person, we have used a simple login method to enter these details using the Keypad. As shown in
the figure, the user can enter the data by using the Keypad. Then this data goes straight into the
firebase server.
Below, the figure shows the data being sent to the firebase cloud.

Figure 6. 4: Sending Data to Firebase

When all the parameters are sent into the cloud, then the machine learning part dives in. The whole
prediction stages start. While it takes a few seconds to be calculated, the device gets the results
back on the screen using the internet facility. It shows the predicted results as patient customary
or heart attack expected.

Figure 6. 5: Predicted Result

IoT Based Heart Attack Monitoring and Prediction System 42


6.2 Software Testing
The software aspect of the device is most essential as it is responsible for the transmission of the
data, storage of the data, feeding the data into machine learning platforms, and performing the
machine learning algorithms on the data to predict the heart attack.
Software testing has been divided into two parts: The Firebase Cloud, where ESP-32 sends the
data, and Jupyter Notebook, where the Machine Learning program is deployed.
6.2.1 Firebase Cloud
While all the data is to be stored somewhere online, we have chosen Firebase. The device Wi-Fi
sends the data into the firebase account, as shown in the figure below. The data is updated live in
the cloud platforms whenever a parameter changes.

Figure 6. 6: Firebase Data Update

6.2.2 Jupyter Notebook/Machine Learning


After the data is updated in the Firebase, the machine learning model fetches the data into its
depository. The information is taken live into the model. The machine learning model is already
trained with a dataset of over 1000 samples.

IoT Based Heart Attack Monitoring and Prediction System 43


The figure below shows the code for the machine learning model. As it is written in Jupyter
notebook, we can see the live graphic results. The updated table of parameters is shown, which
was fetched from Firebase.

Figure 6. 7: Data update in ML Model

The model takes only a few minutes to predict the results, and then it shows the predicted results
on the screen.

Figure 6. 8: Predicted Results from the Model

IoT Based Heart Attack Monitoring and Prediction System 44


6.2.3 Testing Model with Abnormal Data
We have also tested the model with abnormal parameters to see whether it predicts the heart attack
or not. Trying the device on humans is nearly impossible and ethically wrong on many levels, so
we have tested the model by changing the values of Heart Rate, ECG, and Blood Pressure to very
abnormal values. Blood Pressure has been increased up to 150, chest pain to level 3, the highest
level, and heart rate to 135, which is usually high.
The model is trained so that it does not generate false alerts so often, which means the models
know that just increased heart rate, high or low blood pressure, or just chest pain cannot solely be
the reason for heart attack. It considers every parameter and then predicts the results. This aspect
of this device nullifies more chances of false alerts and predictions.

Figure 6. 9: Abnormal Data

Figure 6. 10: Prediction with Abnormal Data

After updating the parameters, the device predicts the heart attack.

IoT Based Heart Attack Monitoring and Prediction System 45


6.3 Accuracy
When we deal with the devices that are to be used for medical purposes, we have to be very careful
with the equipment we are making because it can play with people's lives. Keeping this in mind,
we have created this device as accurate and precise as it can get.
The accuracy of the sensors used in this device is around 85-88% which can be considered good
looking at the level of R&D we can get as students in the market.
After training and testing, the accuracy of machine learning has come up to more than 93%, which
is considered very excellent. As the machine learning part has a huge role in predicting the heart
attack, which is the project's goal, it is very pleasing to have more than 90% accuracy.

IoT Based Heart Attack Monitoring and Prediction System 46


Chapter # 07

Conclusion

IoT Based Heart Attack Monitoring and Prediction System 47


Overall, the device is a very new invention. It is a new concept that can be very beneficial in the
healthcare field. It can be a lifesaving tech for many people. Making this device was a fun and
exciting process. It deals with the engineering fields like machine learning, microcontrollers,
sensor interfacing, clouds, and servers.
We have made the device that monitors the basic parameters of a person's heart health like ecg,
blood pressure heart rate and more to predict the chances if heart attack. The device has a wearable
look which makes it easier to be worn outside the house.
We have developed a prototype device to detect and predict the heart attack and generate an alert.
In addition, it is a beneficial device due to its portability which means the patients can carry it with
them; therefore, no need to stay at hospitals because the Heart Rate Monitor is applicable almost-
--everywhere. Along with the Heart Rate Monitor, we made sure the storage of data into the cloud
allows both doctors and patients to interact with each other and records the data received from the
heart monitor.

7.1 Challenges and Limitations


Several challenges were faced throughout the entire life cycle of the project. The first one was
With the pulse sensor. It did not detect accurate readings if it was placed with excessive or loose
Pressure on the body. Another challenge was to learn machine learning with Python to a level
where we can understand, create, or modify the machine learning models already available to fit
them into our own needs. It took very long to develop a perfect environment for deploying the
machine learning models.
Although the ECG sensor has done a pretty good job but still there is need to done work for the
ECG sensor for example designing a filter for filtering noise and more. This noise can be slightly
reduced by grounded all the connections correctly. To have accurate data to some extent, several
repeated measurements are required. Hence both challenges were overcome.

7.2. Accomplishments
This project has achieved many of its proposed goals. These accomplishments are.
- Measuring the essential parameters of heart health.
- Processing of these parameters.
- Storing the data into the cloud
- Machine learning to predict the heart attack.

IoT Based Heart Attack Monitoring and Prediction System 48


7.3 Future Work
While achieving the goals is a good sign, there is always more to it. Although the device is a new
concept, and many aspects are never explored before, we have made that possible. A few things
can be done in the future to make this device more appealing, accurate, and feature complete.
Here is the list of things that can be achieved in the future.
• Design a complete state of the art system to improve efficiency and accuracy.
• Addition of temperature sensor, respiratory device, and blood sugar sensor.
• GPS for tracking the patient's location so that in case of need, help can be provided.
• More compact PCB design to reduce the size of the device.
• More infographic LCD screen to show the results live on the device.
• A dedicated online server with hosting to run machine learning code 24/7.
• An android App for both patients and doctors to interact and monitor the developments in
health.

IoT Based Heart Attack Monitoring and Prediction System 49


References

[1] A. Brunier, "World Health Organization," 2019. [Online]. Available:


https://www.who.int/news/item/09-12-2020-who-reveals-leading-causes-of-death-and-
disability-worldwide-2000-2019.
[2] WHO, "World Health Organization," 2017. [Online]. Available:
https://www.who.int/news-room/fact-sheets/detail/cardiovascular-diseases-(cvds).
[3] "Business Insider," 2020. [Online]. Available: https://www.businessinsider.com/two-
leading-causes-of-death-2016-1.
[4] L. F. Friedman, "Business Insider," 2015. [Online]. Available:
https://www.businessinsider.com/two-leading-causes-of-death-2015-6.
[5] "Centres for desease control and prevention," 2020. [Online]. Available:
https://cutt.ly/yh3ddWc.
[6] "Webmd," 2020. [Online]. Available: https://www.webmd.com/heart-disease/diagnosing-
doctors-exam#1.
[7] K. S. Nageswari, Handouts on Cardiovascular System.
[8] "https://www.mayoclinic.org," 2020. [Online]. Available: https://cutt.ly/wh8aATB.
[9] M. Corley, "jiujitsumag," 2020. [Online]. Available:
https://jiujitsumag.com/2020/01/26/how-do-you-rate-understanding-your-heartrate/.
[10] J. Fletcher, "medicalnewstoday," 2019. [Online]. Available:
https://www.medicalnewstoday.com/articles/326002.
[11] "dvm360," 2020. [Online]. Available: https://www.dvm360.com/view/reading-ecgs-in-
veterinary-patients-an-introduction.
[12] R. Biswarup, "Analysis of PPG and ECG,," LAP Lambert Academic Publishing, 2015.
[13] 2020. [Online]. Available: https://mahashouse.com/2018/07/14/7-reasons-why-you-have-
high-blood-pressure-how-to-lower-it-naturally/.
[14] C. Ordonez, "“Improving Heart Disease Prediction using," Technical Seminar, University
of Tokyo, 2004.
[15] P. Kakria, "Health Monitoring System for Remote Cardiac," 2015.
[16] F. Ahmed, "IoT Application for Prediction of Future Heart Attack," International Journal
of Computer Applications , 2017.
[17] F. Sayah, "Kaggle," 2020. [Online]. Available:
https://www.kaggle.com/faressayah/predicting-heart-disease-using-machine-learning.
[18] M. Watson, "caring senior service," [Online]. Available:
https://www.caringseniorservice.com/blog/heart-health-devices.
[19] M. C. Staff. [Online]. Available: https://www.mayoclinic.org/tests-procedures/holter-
monitor/about/pac-20385039.
[20] Stuart Miles, 2020. [Online]. Available: https://www.pocket-
lint.com/smartwatches/reviews/apple/153850-apple-watch-series-6-review.

IoT Based Heart Attack Monitoring and Prediction System 50


[21] 2020. [Online]. Available: https://www.google.com/imgres? Ffitbit-versa-review.
[22] 2018. [Online]. Available: https://steemhunt.com/tag/heart/@xabi/bodyguardian-heart-
system-a-heart-health-monitoring-system.
[23] S. K. Srivatsa., "Applying machine learning methods in diagnosing heart disease for
diabetic patients," International Journal of Applied Information Systems (IJAIS) 3, vol. 7,
p. 30, 2012.
[24] A. Govardhan., "Analysis of coronary heart disease and prediction of heart attack in coal
mining regions using data mining techniques," International Conference on Computer
Science & Education, 2010.
[25] J. J. Oresko, "A wearable smartphone-based platform for real-time cardiovascular disease
detection via electrocardiogram processing.," EEE Transactions on Information
Technology in Biomedicine, 2010.
[26] D. Sopic, "Real-time classification technique for early detection and prevention of
myocardial infarction on wearable devices.," IEEE Biomedical Circuits and Systems
Conference, 2017.
[27] M. EH, "Wearable Real-Time Heart Attack Detection and Warning System to Reduce
Road Accidents," Sensors 19, 2019.
[28] espressif. [Online]. Available: https://www.espressif.com/en/products/socs/esp32.
[29] sparkfun. [Online]. Available: https://www.sparkfun.com/products/12650.
[30] maximintegrated. [Online]. Available:
https://www.maximintegrated.com/en/products/sensors/MAX30100.html/product-
details/tabs-3.
[31] R. Loganathan, "Machine learning with SVM and other kernel methods," PHI Learning
Pvt. Ltd., 2009.

IoT Based Heart Attack Monitoring and Prediction System 51


APPENDICES
Appendix A: Code for Hardware

IoT Based Heart Attack Monitoring and Prediction System 52


IoT Based Heart Attack Monitoring and Prediction System 53
IoT Based Heart Attack Monitoring and Prediction System 54
IoT Based Heart Attack Monitoring and Prediction System 55
IoT Based Heart Attack Monitoring and Prediction System 56
IoT Based Heart Attack Monitoring and Prediction System 57
IoT Based Heart Attack Monitoring and Prediction System 58
IoT Based Heart Attack Monitoring and Prediction System 59
Appendix B: Code for Machine Learning
For Model Training:

IoT Based Heart Attack Monitoring and Prediction System 60


IoT Based Heart Attack Monitoring and Prediction System 61
IoT Based Heart Attack Monitoring and Prediction System 62
For Detection:

IoT Based Heart Attack Monitoring and Prediction System 63


IoT Based Heart Attack Monitoring and Prediction System 64

You might also like