Sunteți pe pagina 1din 51

Final Year Project Report

B.Sc. Electrical Engineering


Health Monitoring and Management Using
Internet-of-Things (IOT)

Project Supervisor: Dr. Muhammad Salman Khan

GROUP MEMBERS:
Syed Faraz Naeem Bacha Reg. No: 15JZELE00036
Muhammad Asim Khan Reg. No: 15JZELE0006
Aizaz Ali Shah Reg. No: 15JZELE0062

Department of Electrical Engineering


University of Engineering & Technology Peshawar
Jalozai Campus
1
Supervisor Signature: .
Dr. Muhammad Salman Khan

Assistant Professor

Assistant to Dean

Chairman Department of Electrical Engineering

UET Peshawar Jalozai Campus

2
DECLERATION
We, hereby declare that the content of this thesis are
original and the results obtained are our own.

PLAGIARISM REPORT
Following is the plagiarism report generated
through turnitin, which is 13%.

3
TABLE OF CONTENTS

CHAPTER 1 INTRODUCTION

1.1 Abstract
1.2 Introduction
1.3 Project overview
1.4 Aims / Objectives
1.5 Literature review

CHAPTER 2 METHODOLOGY

2.1 Required Hardware

2.2 Methodology

2.2.1 Wearable Sensors

2.2.1.1 ECG Sensor

2.2.1.2 Pulse Sensor

2.2.1.3 Temperature Sensor

CHAPTER 3 COMMUNICATION AND NETWORKING DEVICES

3.1 Node MCU (Node Micro Controller Unit)

3.2 Arduino

CHAPTER 4 SYSTEM ARCHITECTURE

4.1 System Architecture

4.1.1 Data Collection

4.1.2 Data Transmission

4.1.3 Cloud Processing

4
4.2 Flow Diagram for hardware implementation

4.3 Designed Hardware

4.4 Observations and Measurement

4.5 Results

4.6 Conclusion

4.7 Future Work

CHAPTER 5 PROGRAMMINNG

5.1 Arduino Programming

5.2 Node MCU (Node Micro Controller Unit) Programming

References

5
CHAPTER 01
INTRODUCTION

1.1)ABSTRACT
The IOT (internet of things) have large numbers of applications and
implementations. IOT is serving every field of life, but the most important and attractive one in
the present era is in health care. Here implementation of IOT in health care is based on
biomedical sensors, which measures different physiological activities. The activities include
ECG, temperature, blood pressure, pulse rate, blood glucose level, body movements etc. are
monitored through different electronics sensors. The sensors give data to controller in the form
electrical signals that is digitized in order to be processed /transmitted by microcomputer.

The different physiological sensors reflect the overall health of individual. Monitoring these
sensors can be very useful. The presence of information regarding these sensors data, brings
change in current method of diagnoses and prognosis. It helps in personalization, costs
efficiency, and provides good result.

1.2) INTRODUCTION
Due to huge expenses on health caring center and medical staff
for patient caring, Government have to setup health caring center in specific part of the country.
The goal of our project is to lay the foundation of a system which is cost efficient for
Government and people.

To gain such system we have to make use of IOT (internet of thing) where different sensor
connected to patient body, monitor and measure different physiological activities of patient body
like ECG, Pulse rate, Temperature etc.

The outcomes of these sensors cannot give exact diagnosis for given patient but it can predicts
the occurrence of certain diseases like cardiovascular diseases, Parkinson disease, diabetes etc.

Further this project can also be implemented in ICU (intensive care unit) where patient care is
needed intensively.

In addition to that it can also be implemented for recreational purposes.

A time in near future where patient can be treated by monitoring continuously there
physiological activities, and on the basis of that information treatment could be done. Here the

6
Physician is not only given with conventional lab assessments but also with detail aspect of
diseases for particular patient. On the basis of above information a patient can get personalized
treatment which is highly effective.

Such technological development can bring change in the field of medicine by introducing new
ways which are not only cost effective but also helpful in improving the speed and accuracy of
the diagnosis and treatments.

1.3)PROJECT OVERVIEW
The people of all ages will be benefited from our project
especially ICU (intensive care unit) patients or having well known diseases like cardio vascular
diseases, pulmonary obstruction diseases, Parkinson diseases and diabetes. For a person having
one or more diseases from the above can be monitored and treated through use of our project.
Patient can be monitored through use of ECG, pulse rate and temperature sensors. The use of
sensors depends on the patient condition and also on its diseases. The data collected from the
sensor is uploaded to the server (things speak) in text messages form, where the data is
automatically converted into graphical form, where analysis and visualization could be done.

In short our aim is to provide such a system having high accuracy and low cost.

7
PROJECT OVERVIEW IN BLOCK DIAGRAM

PULSE LCD
SENSOR DISPLAY CLOUD

ECG NODE
PATIENT
SENSOR ARDUINO MCU

TEMPERAT SERIAL
URE
SENSOR MONITOR

POWER ADOPTER

Figure: 1.1

8
1.4)AIMS/OBJECTIVES
1.4.1) PORTABLE

The product or device is to be small in size and light in weight and can be
handled easily as it store and show record by just using the internet.

1.4.2) BETTER PATIENT EXPERIENCE


Having well established connection to the
patient health care center with IOT (internet of thing), can enhance the diagnosis and prognosis
accuracy.

1.4.2) PROVIDE AN ACCURATE DETECTION


Due to use of such system we can get
accurate result for given diagnosis based on patient health. Further it will have less error, and
will collect data in short time with more accuracy than any human.

1.4.3) REDUCING COST


When patient get services at home, there is no need for physician or
nurse to visit. So this project eliminates the cost of hospital stay.

1.4.4) ALERT FOR DOCTOR AND RELATIVES


Through use of IOT, doctor and
relative get alert in case of emergency whenever particular parameter goes beyond the limit.

1.4.5) SHOW OUTCOME OF THE TREATMENT


By providing doctor with patient
data base for certain patients can helps the doctor in making decisions, and evolution of ongoing
treatment.

1.4.6) COST EFFECTIVE


Moreover this project is non-expensive and accurate as compared
highly expansive machine used in ICU. Further it is compact and light in weight.

9
1.4.7) LINKING DOCTOR AND PATIENT
In fact most patient feel uncomfortable to go
to hospital and some are very far away from hospital. In these cases our project provides an
active link between doctors and patients

1.5)LITERATURE REVIEW
Due to advancement in technology, health experts now
in great advantageous, due to large number of invention in electronics gadgets that sensors of
different kinds were introduced. Now a day any kind of biomedical sensor can be found in
market which is highly cost effective and accurate. IOT devices are highly used in health sector
due to its immense advantages. In this article we discuss the project which is related to health
monitoring and management system.

Especially cardiac patient, pulmonary obstruction patient, Parkinson patient, diabetic patient,
blood pressure patient, blood sugar patient etc. this project is of immense importance for people
having such kind of diseases especially in the rural area where the number of physician is less
than number of physicians in urban area. In the rural area the medical instruments are not
available everywhere due its costly nature, and probably in some cases if the instruments are
available then it is either expired or damaged, while in certain cases the number of patients are
greater than the number of available instruments. So in short in these circumstances our project is
of great helpful.

Of many chronic diseases, hypertension is the route of all cardio vascular diseases which remain
the cause for large other chronic diseases. In present condition for health in Pakistan and in
general all over the world, no remote HRV machine (Heart Rate Variability) for hypertension
patient available to help the doctors in analysis and to track down the patient's condition. So for
chronic heart diseases we use ECG sensors which can handle effectively the function perform by
HRV machine. An advantage of using ECG sensor is that it is web based, that the result can be
analyzed anywhere in the world by physician as well as by patient relatives.

For a person having mild vascular diseases there heart rate can be monitor using pulse sensor,
which indirectly measure the condition of heart. It measures the heart activity from the blood
flowing in capillaries (the smallest part of the blood vascular system). It can be used by athletes
and sports man to constantly monitor their vascular activity and to help them to plan their
exercise intensity. The advantage of pulse sensor over other equipment is that, it is small and

10
light and can be wear on the tip of finger like watch on wrest. Temperature sensor can be used to
measure and monitor body temperature constantly. An increase or decrease in temperature can be
used by physician for analysis and treatment of patient. Technologies are expanded day by day
by providing an efficient tool for sending data to web (thing speak) from these sensors (pulse
sensor, ECG and temperature sensors). When the patient is in critical condition, and patients
discharged from hospital, he or she needs to check up in regular basis. That is why IOT based
heath monitoring system is best option for rural area Collecting and storing real life data has so
much importance in artificial intelligence and in data sciences, so by implementing our project
around the world can result a collection of huge amount of data which is to accurate and
favorable in analyzing and classifying human behaviors for particular diseases. So in short it
provide backbone for data science

Our project can also be implemented using raspberry pi but in fact using raspberry pi can
increase the cost and the output accuracy remain same as that for Arduino, so we consider
Arduino for our implementation.

11
CHAPTER 02
DESIGN AND METHODOLOGY

2.1)HARDWARE REQUIRED FOR DESIGN


1) ARDUINO MEGA
2) PULSE SENSOR
3) TEMPERATURE SENSOR
4) ECG SENSOR
5) NODE MCU
6) CONNECTING WIRE
7) SOLDERING BOARD
8) LIQUID CRYSTAL DISPLAY
9) POWER SUPPLY
10) LAPTOP FOR PROGRAMMING
11) PUSH BUTTON

2.2)METHODOLOGY
The process of methodology consists of two stages

1) WEARABLE SENSORS
2) NETWORKING AND COMMUNICATION

2.2.1)WEARABLE SENSORS
The wide body network composed up sensor which can
collect data and stored it on cloud. There are a number of sensors depending on patient and on its
condition. Normally the sensors used in our project for patient monitoring are ECG, pulse and
temperature sensor. These sensors are helpful in the very beginning of diseases, as it show the basic
symptoms which are common among all the diseases. Besides that it can also be used for particular
diseases, for example ECG for cardio vascular diseases for patient to be in chronic condition. Similarly
pulse and temperature sensor can also be used. Using sensor in such manner can increase personalization
of products, which is of great interests. Now a day due to partial implementation of such each and every
one can get personalized treatment. Here we will explain working of three sensors in detail

2.2.1.1) ECG sensor

2.2.1.2) Pulse sensor

2.2.1.3) Temperature sensor

12
2.2.1.1) ECG( electrocardiograph)
ECG is the measure of electrical activity of the heart
over a periodic duration of time by placing electrode on body in specialized position. ECG
monitoring and measuring electrodes have passed through the numbers of changes or evaluation.
In 1883, Carlo Matteucci’s first time showed the electrical activity in human body by using
sensor. Later in 1887, Augustus D.Waller’s has invented and published the first human
Electrocardiogram. In 1901 Willem Einthoven made infrastructure of Waller’s technology. He
invented a device called string galvanometer made from fine quartz coated with silver. Einthoven
was awarded with noble prize for electrocardiogram. In present time the electrode of ECG made
from plastic substrate covered with ionic compound that is silver chloride (AgCl). These
electrodes make the use of electrical potential generated in the living cell due to ionic activity

Human heart has two nodes

 AV node (Atrium Ventricular node )


 SA node (Sino Atrial node)

These two are responsible for electrical activity of heart. The heart start pumping at sino-atrical
node which is built to produced heart rate at frequency of 70 cycles per minute. The pumping
activity generated in left and right muscular tissues of the heart. There is short duration of time
called delay which is use to fill the ventricles with blood from atrial contraction in the
ventricular node. This pumping of heart help to pump the blood to the aorta and to remaining
parts of the body. The cardiac cycle consist of two phases that is contraction and relaxation.
During contraction the heart full the blood against the wall of the blood vessels of the vascular
system with great force and during relaxation the heart receive the blood from the blood vessels
of vascular system. So in this way the blood circulate throughout the body. During each cycle of
heart polarization and de polarization of vascular system happen that is the cell membrane
potential of the vascular system changes during each contraction and relaxation of the heart.

When the cycle take place the trans membrane potential develop that is internal and external part
of the membrane are at different potential, due to which voltage develop across the membrane,
here the electrode are used to measure this generated voltage. The voltages detected by these
electrodes have different peaks. These different peaks are P, Q, R, S, T and U. which are shown
in figure

13
2.2.1.1) Normal ECG Rhythm

Figure: 2.1 Normal ECG Rhythm

2.2.1.1) ECG MODULE (AD8232)

Figure:2.2 for ECG Module

14
2.2.1.1) ECG MODULE PINS CONFIGURATION

2.2.1.1) ECG WORKING BLOCK DIAGRAM

Figure: 2.3 ECG Working block Diagram

2.2.1.2) PULSE SENSOR


Pulse sensor also gives information of the heart like ECG but its
advantage over ECG is that it can be used by mobile person as well as stationary. Mostly used by
athletes or by person who are in the regular working conditions.

15
Front Side (to skin) Back Side

Figure: 5 Pulse sensor front and backside view

Figure: 2.4 Pulse Pins Description

16
2.2.1.2) Pulse sensor pin configuration

2.2.1.2) WORKING BLOCK DIAGRAM OF PULSE SENSOR

Figure: 2.5 Pulse Sensor Working Block Diagram

2.2.1.2) CONSTRUCTION AND WORKING OF PULSE SENSORS


Pulse sensor
has two faces. On one side there is complex circuitry and on other side there is LED (light
emitting diode). The complex circuitry controls the LED. The face having LED is placed on the
thumb or some other part parts of body where the vein are exposed to outside, the light from
LED fall on the vein where it detect the blood, the detection of blood is based on the

17
intensity of reflected light. If the heart is in state of contraction there will be more blood in the
vein and more incense light would be reflected and if the heart is in state of relaxation then
there will be no blood in veins, so reflection of light will be not as much as in the case of
contraction. To use the pulse simply connect the power pin (Vcc) with +5 or +3 volt supply, the
input pin is connected to ADC (analog to digital converter), which convert analog input to digital
output. Finally the ground pin is connected to zero potential.

2.2.1.3) TEMPERATUURE SENSOR(DS18B20)(DIGITAL IN NATURE)


Temperature sensor is used to measure temperature of the body. With the help of this sensor we
can measure temperature in the range of -55 to 125C with accuracy of (+-5C). It has three pin as
shown in figure. Pin configurations are shown in figure. Data pin receive the data and other two
pin provide connection

2.2.1.3) PIN DESCRIPTION AND CONFIGURATION FOR TEMPERATURE SENSOR

Figure: 2.6 Temperature Sensor


18
2.2.1.3) HOW TO USE DS18B20(TEMPERATURE SENSORS)
It work with only one
pin, which is connected with microcontroller with help of pull up resister the other two are power
pin as shown in figure

Figure: 2.7 Internal Structure of Temperature Sensor

The pull up resister is used to maintain the line at high state when the bus is not used. The
temperature value are measured and stored in two bytes register. The data can be then read
through use of line.

19
CHAPTER 03

COMMUNICATION AND NETWORKING

3.1) COMMUNICATION AND NETWORKING DEVICES


Sensors transfer
information to cloud through a gateway. These, information are stored on cloud for analysis and
visualization. Different networking or communicating devices are used but here we will use
NodeMCU and Arduino’s.

3.1.2)Node MCU (Node Micro Controller Unit).


Node MCU provide an interface
between the sensors connected to body and cloud server where data is stored. Node MCU take
the data from these sensor and transfer it to thing speak. Thing speak receive the data with little
delay which is about 15sec.

Figure: 3.1 Node MCU

20
Node MCU is microcontroller which has built in Wi-Fi offering a bridge from existing microcontroller to
Wi-Fi, and is capable of running self-contained applications. Node MCU is rich in pin configurations and
also has USB cable that provides connection to laptop just like Arduino.

21
NODE MCU PIN DESCRIPTION

Figure: 3.2 Node MCU Pins Description

3.2)ARDUINO
Arduino is an open source electronics prototype providing a flexible
hardware and software interface. It is basically well develop microcontroller based on ATmega
328 MCU. The Arduino mega is shown in figure

22
Figure: 3.3 Arduino MEGA Pins Layout

23
WORKING FLOW DIAGRAM

POWER ON

ECG SENOSOR PULSE SENSOR


CONNECTED CONNECTED
WITH PATIENT WITH PATIENT
BODY BODY

TEMPERATURE
SENSOR
CONNECTED
ARDUINO WITH BODY ARDUINO
COLLECT ECG COLLECT PULSE
DATA AND SEND SENSOR DATA
TO NODEMCU AND SEND TO
NODEMCU

ARDUINO
COLLECT
DATA SEND TO DATA TRANSFER
TEMPERATURE
CLOUD TO CLOUD
DATA AND SEND
THROUGH THROUGH
TO CLOUD
NODEMCU NODEMCU
THROUGH
NODEMCU

CONVERTED TO CONVERTED TO CONVERTED TO


GRAPH BY GRAPH BY GRAPH BY
CLOUD FOR CLOUD FOR CLOUD FOR
ANALYSIS AND ANALYSIS AND ANALYSIS AND
VISUALIZATION VISUALIZATION VISUALIZATION

POWER OFF AND CYCLE COMPLETE

Figure: 3.4 CYCLBlock Diagram


Working
24
CHAPTER 04

SYSTEM ARCHITECTURE

4.1) SYSTEM ARCHITECTURE


System architecture consists of three mains parts

4.1.1) Data collection:

4.1.2) Data sending

4.1.3) Data Clouding

4.1.1) DATA COLLECTION


The collection of information is carried out by multiple
sensors i.e. temperature, blood pressure and respiratory sensor which aggregate information and
send it to server through certain interfaces like Wi-Fi, Bluetooth etc.

4.1.2) DATA SENDING


In data transfer from sensor is to Arduino where data is
temporarily stored. Data is displayed on LCD and serial monitor. Furthermore data is send to
NODE MCU.

4.1.3) DATA CLOUDING


In data clouding, data is transmitted to cloud from NODE MCU. Data
clouding have three parts.

4.1.3.1) Storage

4.1.3.2) Analytics

4.1.3.3) Visualization

25
4.1.3.1) STORAGE
Information stored on the web server in their respective field allocated
by the user.

4.1.3.2) ANALYTICS
Analysis is carried out on recorded data considering patient health.

4.1.3.3) VISUALIZATION
Visualization is important element for most system which are
based on data because it is not easier for physician to considered such high volumetric data.
Visualization process converts data into interpretable and understandable form which is
necessary for diagnosis.

4.2) FLOW DIAGRAM FOR HARDWARE IMPLEMENTATION

EXTERNAL EXTERNAL ARDUINO MEGA


7-12V POWER
5V POWER SUPPLY
SUPPLY
5V 3.3V 3.3V
3.3V

TEMPERATURE PULSE
NODE MCU ECG SENSOR
SENSOE SENSOR

Figure: 4.1 Block Flow Diagram

26
4.3) DESIGNED HARDWARE

Figure: 4.2 Designed Hardware

4.4)OBSERVATION AND MEASUREMENTS


Observation and measurement are
carried out on the received data in cloud. This data is helpful in observation and measurement.
Accuracy of diagnosis and monitoring is highly dependent on recorded data. Modern electronics
changes the traditional healthcare system, where sensor not only aggregate data but also shares
with one other and send it to cloud.

4.5)RESULTS
After programming and connecting different components together, we carried
out experiment. According to proposed model we have designed a system prototype that is IOT
based patient monitoring system.

27
Following are the results.

4.5.1)Result for ECG sensor connected with body

Figure: 4.3 Snip of Serial Monitor For ECG


The snip of serial monitor shows ECG at different instants of time. When the lead is not
connected or pad is not in proper contact with body with body it gives zero value or simply
displays “lead not Connected”.

When the lead is connected and pad is in proper contact with body it display the value of ECG at
that instant of time. Similar observation can be made from the graph of things speak which is
shown below.

Figure 4.4 Snip of Thing Speak (cloud) For ECG


28
In figure 4.4 the graph shows ECG Vs date and time plot captured from things speak

4.5.2)Result for temperature sensor connected with body

Figure: 4.5 Snip of Serial Monitor For Temperature


The snip of the serial monitor shows the value of temperature sensors in Celsius as well as in
Farenheit scale. When the temperature sensor is not in contact with body it shows room

29
temperature and when it comes in contact with body it shows body temperature at that instant of
time.

Similar observations can be made from things speak graph which is shown below

Figure 4.6 Snip of Things Speak For Temperature

Figure 4.6 shows the graph of temperature Vs date and time. Here the temperature is in celsius
scale.

30
4.5.3)Result for pulse sensor connected with body

Figure: 4.7 Snip of Serial Monitor for Pulse Sensor


The snip of serial monitor shows the values of pulse sensor in BPM. When the pulse sensor is
not in contact with finger it show zero BPM, and when it comes in contact with finger it show
pulse rate at that instant of time.

Similar observation can be made from the graph of things speak which is shown below

31
Figure 4.8 Snip of thing speak for Pulse Sensor
Figure 4.8 shows the graph of pulse rate Vs date and time

4.6)CONCLUSION
IOT provide a smart platform to connect sensors with patient body
for regular checkup. Our project is giving special opportunities to old age people and people
living rural area, being far away from health care center. Our project helps in saving time and
cost at same time.

4.7)FUTURE WORK
1) Our project provides base for those which are purely based on data
that is on data collections. Here the data recorded are pure and free from human error

2) `The recorded data is available for cloud processing which will lead to machine atomization.

3) By connecting different sensors which is of good quality patient in serious condition can also
be treated.

4) Our project can be used to replace bulky hardware in ICU, where same function can be done
by using these small components.

32
CHAPTER 05
PROGRAMMING

ARDUINO PROGRAMMING
Following are the code for the Arduino to collect data from
sensors and send to Node MCU

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line
display

#include <Adafruit_Sensor.h>

#include <SoftwareSerial.h>

#include <ArduinoJson.h>

SoftwareSerial s(5,6);

// for Temperature

#include <OneWire.h>

#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float tempC = 0;

int ecg = 0;

// for BMP

33
// Variables

int pulsePin = A2; // Pulse Sensor purple wire connected to analog pin 0

int startPin = A1;

// Volatile Variables, used in the interrupt service routine!

int BPM =0; // BPM=0;// int that holds raw Analog in 0. updated every 2mS

volatile int Signal; // holds the incoming raw data

volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!

volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when
not a "live beat".

volatile boolean QS = false; // becomes true when Arduoino finds a beat.

// Regards Serial OutPut -- Set This Up to your needs

static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino
Serial Monitor ASCII Visual Pulse

volatile int rate[10]; // array to hold last ten IBI values

volatile unsigned long sampleCounter = 0; // used to determine pulse timing

volatile unsigned long lastBeatTime = 0; // used to find IBI

volatile int P = 512; // used to find peak in pulse wave, seeded

volatile int T = 512; // used to find trough in pulse wave, seeded

volatile int thresh = 525; // used to find instant moment of heart beat, seeded

volatile int amp = 100; // used to hold amplitude of pulse waveform, seeded

volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable
BPM

34
volatile boolean secondBeat = false; // used to seed rate array so we startup with reasonable
BPM

void setup()

lcd.init(); // initialize the lcd

lcd.init();

// Print a message to the LCD.

lcd.backlight();

s.begin(9600);

//pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!

Serial.begin(9600); // we agree to talk fast!

interruptSetup(); // sets up to read Pulse Sensor signal every 2mS

pinMode(startPin, INPUT);

digitalWrite(startPin, HIGH); // IF YOU ARE POWERING The Pulse


Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,

// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE


TO THE A-REF PIN

// analogReference(EXTERNAL);

sensors.begin();

pinMode(10, INPUT); // Setup for leads off detection LO +

pinMode(11, INPUT); // Setup for leads off detection LO -

StaticJsonBuffer<1000> jsonBuffer;

35
JsonObject& root = jsonBuffer.createObject();

// Where the Magic Happens

void loop()

sensors.requestTemperatures();

tempC = sensors.getTempCByIndex(0);

Serial.print(tempC);

Serial.println(" C: ");

lcd.setCursor(0,0);

lcd.print("T ");

lcd.print(tempC);

if((digitalRead(10) == 1)||(digitalRead(11) == 1)){

Serial.println("Lead Not Connect");

else{

// send the value of analog input 0:

Serial.println(analogRead(A0));

ecg=analogRead(A0);

lcd.setCursor(7,0);

lcd.print("ECG ");

36
lcd.print(ecg);

root["ECG"]=ecg;

root["temp"]=tempC;

root.printTo(s);

serialOutput();

if (QS == true) // A Heartbeat Was Found

// BPM and IBI have been Determined

// Quantified Self "QS" true when Arduino finds a heartbeat

serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.

QS = false; // reset the Quantified Self flag for next time

delay(100); // take a break

void interruptSetup()

// Initializes Timer2 to throw an interrupt every 2mS.

TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC
MODE

TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER

37
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE

TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND


OCR2A

sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

void serialOutput()

{ // Decide How To Output Serial.

if (serialVisual == true)

arduinoSerialMonitorVisual('-', Signal); // goes to function that makes Serial Monitor


Visualizer

else

sendDataToSerial('S', Signal); // goes to sendDataToSerial function

void serialOutputWhenBeatHappens()

if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work

if(!(digitalRead(startPin)))

38
{

Serial.print("*** Heart-Beat Happened *** "); //ASCII Art Madness

Serial.print("BPM: ");

Serial.println(BPM);

lcd.setCursor(2,1);

lcd.print(" ");

lcd.setCursor(0,1);

lcd.print("HB ");

lcd.print( BPM );

root["pulse"]=BPM;

root.printTo(s);

if(digitalRead(startPin))

BPM=0;

lcd.setCursor(2,1);

lcd.print(" ");

lcd.setCursor(0,1);

39
lcd.print("HB ");

lcd.print( BPM );

root["BPM"]=BPM;

root.printTo(s);

else

sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix

sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix

void arduinoSerialMonitorVisual(char symbol, int data )

const int sensorMin = 0; // sensor minimum, discovered through experiment

const int sensorMax = 1024; // sensor maximum, discovered through experiment

int sensorReading = data; // map the sensor range to a range of 12 options:

int range = map(sensorReading, sensorMin, sensorMax, 0, 11);

// do something different depending on the

// range value:

40
switch (range)

case 0:

// Serial.println(""); /////ASCII Art Madness

break;

case 1:

// Serial.println("---");

break;

case 2:

// Serial.println("------");

break;

case 3:

// Serial.println("---------");

break;

case 4:

// Serial.println("------------");

break;

case 5:

// Serial.println("--------------|-");

break;

case 6:

// Serial.println("--------------|---");

41
break;

case 7:

// Serial.println("--------------|-------");

break;

case 8:

// Serial.println("--------------|----------");

break;

case 9:

// Serial.println("--------------|----------------");

break;

case 10:

// Serial.println("--------------|-------------------");

break;

case 11:

// Serial.println("--------------|-----------------------");

break;

void sendDataToSerial(char symbol, int data )

42
Serial.print(symbol);

Serial.println(data);

ISR(TIMER2_COMPA_vect) //triggered when Timer2 counts to 124

cli(); // disable interrupts while we do this

Signal = analogRead(pulsePin); // read the Pulse Sensor

sampleCounter += 2; // keep track of the time in mS with this variable

int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid noise

// find the peak and trough of the pulse wave

if(Signal < thresh && N > (IBI/5)*3) // avoid dichrotic noise by waiting 3/5 of last IBI

if (Signal < T) // T is the trough

T = Signal; // keep track of lowest point in pulse wave

if(Signal > thresh && Signal > P)

{ // thresh condition helps avoid noise

P = Signal; // P is the peak

43
} // keep track of highest point in pulse wave

// NOW IT'S TIME TO LOOK FOR THE HEART BEAT

// signal surges up in value every time there is a pulse

if (N > 250)

{ // avoid high frequency noise

if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )

Pulse = true; // set the Pulse flag when we think there is a pulse

IBI = sampleCounter - lastBeatTime; // measure time between beats in mS

lastBeatTime = sampleCounter; // keep track of time for next pulse

if(secondBeat)

{ // if this is the second beat, if secondBeat == TRUE

secondBeat = false; // clear secondBeat flag

for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup

rate[i] = IBI;

if(firstBeat) // if it's the first time we found a beat, if firstBeat == TRUE

44
{

firstBeat = false; // clear firstBeat flag

secondBeat = true; // set the second beat flag

sei(); // enable interrupts again

return; // IBI value is unreliable so discard it

// keep a running total of the last 10 IBI values

word runningTotal = 0; // clear the runningTotal variable

for(int i=0; i<=8; i++)

{ // shift data in the rate array

rate[i] = rate[i+1]; // and drop the oldest IBI value

runningTotal += rate[i]; // add up the 9 oldest IBI values

rate[9] = IBI; // add the latest IBI to the rate array

runningTotal += rate[9]; // add the latest IBI to runningTotal

runningTotal /= 10; // average the last 10 IBI values

BPM = 60000/runningTotal; // how many beats can fit into a minute? that's BPM!

QS = true; // set Quantified Self flag

// QS FLAG IS NOT CLEARED INSIDE THIS ISR

45
}

if (Signal < thresh && Pulse == true)

{ // when the values are going down, the beat is over

Pulse = false; // reset the Pulse flag so we can do it again

amp = P - T; // get amplitude of the pulse wave

thresh = amp/2 + T; // set thresh at 50% of the amplitude

P = thresh; // reset these for next time

T = thresh;

if (N > 2500)

{ // if 2.5 seconds go by without a beat

thresh = 512; // set thresh default

P = 512; // set P default

T = 512; // set T default

lastBeatTime = sampleCounter; // bring the lastBeatTime up to date

firstBeat = true; // set these to avoid noise

secondBeat = false; // when we get the heartbeat back

sei(); // enable interrupts when youre done!

}// end isr

. .

46
NODE MCU (Node Micro Microcontroller Unit)
Following are the code for Node
MCU which is used to get data from Arduino and send it to cloud (things speak)

#include <ESP8266WiFi.h>

#include <Adafruit_Sensor.h>

#include <SoftwareSerial.h>

SoftwareSerial s(D6,D5);

#include <ArduinoJson.h>

#include "ThingSpeak.h"

//#include <ESP8266WiFi.h>

// repace your wifi username and password

const char* ssid = "Aaa";

const char* password = "faraz123";

unsigned long myChannelNumber = 811480;

const char * myWriteAPIKey = "8MXDHNSAU6CTRC55";

WiFiClient client;

void setup() {

// Initialize Serial port

Serial.begin(9600);

s.begin(9600);

Serial.print("Connecting to ");

Serial.println(ssid);

47
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

Serial.println("IP address: ");

Serial.println(WiFi.localIP());

Serial.print("Netmask: ");

Serial.println(WiFi.subnetMask());

Serial.print("Gateway: ");

Serial.println(WiFi.gatewayIP());

ThingSpeak.begin(client);

// while (!Serial) continue;

void loop() {

StaticJsonBuffer<1000> jsonBuffer;

JsonObject& root = jsonBuffer.parseObject(s);

if (root == JsonObject::invalid())

Serial.println("Object Invalid");

return;

48
}

//Print the data in the serial monitor

Serial.println("JSON received and parsed");

root.prettyPrintTo(Serial);

Serial.println("");

Serial.print("Temperature ");

int data1=root["temp"];

Serial.println(data1);

Serial.print("ECG ");

int data2=root["ECG"];

Serial.println(data2);

Serial.print("Heart Pulse ");

int data3=root["pulse"];

Serial.println(data3);

Serial.println("");

ThingSpeak.setField(1, data1);

ThingSpeak.setField(2, data2);

ThingSpeak.setField(3, data3);

ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

//delay(20000);

delay(10000);

Serial.println("---------------------xxxxx--------------------");

Serial.println("");

49
References
[1] A. Benharref and M. Serhani, “Novel cloud and SOA-based framework for
E-Health monitoring using wireless biosensors,” IEEE Journal of Biomed. and Health Inf., vol.
18, no. 1, pp. 46–55, Jan 2014.
[2] S. Babu, M. Chandini, P. Lavanya, K. Ganapathy, and V. Vaidehi,“Cloud-enabled remote
health monitoring system,” in Int. Conf. on
Recent Trends in Inform. Tech. (ICRTIT), July 2013, pp. 702–707.
[3] C. Rolim, F. Koch, C. Westphall, J. Werner, A. Fracalossi, and G. Salvador, “A cloud
computing solution for patient’s data collection in health care institutions,” in Second Int. Conf.
on eHealth, Telemedicine, and Social Medicine, ETELEMED ’10., Feb 2010, pp. 95–99.
[4] M. Lan, L. Samy, N. Alshurafa, M.-K. Suh, H. Ghasemzadeh, A. Macabasco-O’Connell, and
M. Sarrafzadeh, “Wanda: An end-to-end remote health monitoring and analytics system for heart
failure patients,” in Proc. of the Conf. on Wireless Health, ser. WH ’12. New York, NY,
USA: ACM, 2012, pp. 9:1–9:8.
[5] L. Wei, N. Kumar, V. Lolla, E. Keogh, S. Lonardi, C. Ratanamahatana, and H. Van Herle,
“A practical tool for visualizing and data mining medical time series,” in Proc. 18th IEEE
Symposium on Computer-Based Med. Sys., June 2005, pp. 341–346.
[6] Y. Mao, Y. Chen, G. Hackmann, M. Chen, C. Lu, M. Kollef, and T. Bailey, “Medical data
mining for early deterioration warning in general hospital wards,” in IEEE 11th Int. Conf. on
Data Mining Workshops (ICDMW), Dec 2011, pp. 1042–1049..

[7] Iman Azimi, Arman Anzanpour, Amir M. Rahmani, Pasi Liljeberg, Tapio Salakoski,
“Medical Warning System Based on Internet of Things Using Fog Computing”.
[8] Vivek Pardeshi, Saurabh Sagar, Swapnil Murmurwar, Pankaj Hage, “Health
Monitoring Systems using IoT and Raspberry Pi – A Review”.
[9] S.Lavanya, G.Lavanya, J.Divyabharathi, “REMOTE PRESCRIPTION AND IHOME
HEALTHCARE BASED ON IoT”.
[10] https://ac.els-cdn.com/S18770506301260/1-s2.0-S1877050916301260-
main.pdf?_tid=dcbc873b-3c7a-4fea-8d41-
f4c25d549727&acdnat=1521015990_964ce32f5ddee49a5b9eb8f73c99179f
[11] R.N. Kirtana, Y.V. Lokeswari, “An IoT Based Remote HRV Monitoring System
For Hypertensive Patients”.
[12] Ruhani Ab. Rahman, Nur Shima Abdul Aziz, Murizah Kassim, Mat Ikram Yusof,
“IoTbased Personal Health Care Monitoring Device for Diabetic Patients”.
[13] https://www.mdtmag.com/article/2011/08/brief-look-ecg-sensor-technology
[14] Dhvani Parekh, “Designing Heart Rate, Blood Pressure and Body Temperature Sensors
for Mobile On-Call System”.
[15] https://www.livescience.com/42081-normal-heart-rate.html

50
[16] Yuhua Hu, Wirelessly Connected Sensor Acquisition System for Remote
Nursing Applications. [11] Ovidiu Apostu, Bogdan Hagiu, Sever Paşca, Wireless ECG
Monitoring and Alarm System
Using ZigBee”2011 The International Symposium on ADVANCED TOPIC INELECTRICAL
ENGINEERING2068-7966/ATEE 2011.
[17] Goutam Motika, Abinash Prusty,” Wireless Fetal Heartbeat Monitoring System Using
ZigBee & IEEE 802.15.4 Standard”, 2011 Second International Conference on Emerging
Applications of Information Technology, 978-0-7695-4329-1/11 $26.00 © 2011 IEEE
DOI 10.1109/EAIT.2011.89

51

S-ar putea să vă placă și