Project Thesis
Project Thesis
FACULTY OF ENGINEERING
DEPARTMENT OF
ELECTRICAL
IoT BASED & ELECTRONICS ENGINEERING
PATIENT HEALTH
MONITORING SYSTEM
Graduation Project
Name SURNAME
Name SURNAME
YUNUS BOZKURT-1401050002
Supervisor
May 2019
ACKNOWLEDGEMENTS
We would like to thank our project consultant, Assist.Prof.Dr.Ertugrul SAATCI for
guiding us throughout the process. We also wish to thank all our teachers for their
excellent contributions and support for the finishing this project.
ii
ABSTRACT
Health monitoring systems are widely used devices in clinics and hospitals. Engineering
and medicine are related sciences and with the development of technology, new devices
begin to be used in medicine. Health monitoring systems are one of these devices. They
vary according to the medical values they measure. Some medical values are critical to
human life. Therefore, these values must be continuously monitored. As examples to these
medical values “Heart Rate”, “Body Temperature” and “Blood Oxygen Value” can be
given. The values has an ideal range, when the health values of the patient out of this range
this may cause a disease or critical health situation.
Health monitoring system allows visualizing the health values continuously and controls
the values in ideal range, If they are not in its range it gives notification or an alarm. This
system is useful for early disease detection or checking health status daily. This health
monitoring system should be able to be used by patients in their own homes or outside of
hospital even anywhere you have the internet connection. IoT (Internet of Things) is a
developing technology and its use is becoming widespread with different devices.
In this project, IoT based patient health monitoring system that supports the visualizing
two critical health values was designed. One of these values is heart rate, which is the
number of times the heart beats in a minute, and the other value is the body temperature,
which is critical value for human life. The patient health monitoring system measures these
values from sensors and sends the data to another location on the internet via wi-fi module.
There is also a screen on this device to see the numerical values and checking the health
status of patient and notifications. Thanks to IoT it is easy to access the graphical visuals of
heart rate and body temperature from laptop or smartphone. This project was implemented
by using the Arduino environment. For wi-fi connection ESP8266-01 module was
choosen. IoT part of the project uses ThingSpeak protocol and Thingview application to
send data to smartphone.
iii
TABLE OF CONTENTS
ACKNOWLEDGEMENTS………….……………...……………………………..……...ii
ABSTRACT……………………………………...…………………………...…………...iii
TABLE OF CONTENTS…………………………………………………………………iv
LIST OF FIGURES……...………...……………………...……………………………...vi
LIST OF TABLES………………...……………………………...……………………...vii
LIST OF ACRONYMS……………………………………………...……………………ix
1. INTRODUCTION……………………..…...……………………………………….......1
iv
3.IMPLEMENTATION OF IOT BASED PATIENT HEALTH MONITORING
SYSTEM…………………………...……………………………………………………...18
3.1 Device for Synthesis………………………...………………………………..…….18
4. RESULTS………………………………………………………………...…………….33
5. CONCLUSION…………………...……………………………………………………36
6. APPENDIX…………………………………...………...…………………………..….37
REFERENCES………………………...……………………………….…………...……49
LIST OF FIGURES
Figure 1.4.1 Block Diagram of Monitoring System Block:1……...………………..………4
Figure 3.3.1 Steps for building the Patient Health Monitoring System …………......……32
vi
LIST OF TABLES
Table 2.3.1.1 AT Commands for ESP8266 Configuration………...…...…………………..9
vii
°C : Celsius
viii
LIST OF ACRONYMS
IR : Infrared
ix
1.INTRODUCTION
A patient health monitoring system is a device that provides measuring health values of
patient such as heart rate, body temperature, blood oxygen that have a critical importance
for human life. The patient puts his or her limb to this device and then the measuring points
on body are connected to the health monitoring device by cables. When the connection is
complete the sensors on the device gets the measuring values from patient body and sends
these values to the microcontroller.
The main objective of this project is to create a health monitoring system that can supports
two measurements, namely Heart rate and Body temperature of patients, which can be
followed by doctor, or patient himself. Here in this project, we have designed an IoT based
device, which has a wi-fi connection for sending data over the internet. This system also
shows the measured values graphically and gives information about the status of patient by
controlling these values. This device helps to diagnose abnormal health status and diseases.
A health-monitoring device is a system that measures health values such as heart rate, body
temperature, blood oxygen and there are many important values, which must be in an ideal
range to have a normal health status. This device measures and checks the health values of
patient. It compares the measured values with ideal values. If there is an emergency, it
notifies the doctor or patient.
1
1.2 Evolution and Variations of Health Monitoring System
People have been monitoring the vital signs of others since the dawn of humankind, using
various methods to track heart rate, body temperature, respiratory rate, and arterial blood
pressures.
It was back in 1625 when Santorio of Venice, with help from his good friend Galileo
published methods for measuring body temperature with a spirit thermometer and timing
the pulse rate with a pendulum. However, their findings were largely ignored. It was only
with the publication of “Pulse-Watch” by Sir John Floyer in 1707 that the first scientific
report pertaining to the pulse rate came to light [1].
Ludwig Taube published the first-ever plotted course of fever in a patient circa 1852,
adding respiratory rate to the list of human vital signs trackable at the time. Subsequent
improvements in the thermometer and clock solidified the heart rate, respiratory rate and
body temperature as the standard vital signs monitored by medical professionals of the
time. In 1896 the first ever ‘sphygmomanometer’ (blood-pressure cuff) was introduced to
the medical world, which added a fourth vital sign, arterial blood pressures, to patient
monitoring procedures [1].
During the 1980s, patient monitoring systems evolved to include bedside arrhythmia
analysis and larger, color screens that allowed for more waveforms to be displayed at once
[1].
Today, with advances in display technologies through the 1990s and early 2000s, and the
advent of the touch screen, patient monitor systems have become both easier to use and to
transport. Doctors and nurses alike are now able to monitor and report on patient vitals
effortlessly and with portable patient monitoring systems. With the growing IoT
technology the patient monitoring systems will be able to more advanced easy to use and
portable, wearable technologies supports that systems.
2
1.3 Mechanism of System
The Health Monitoring device has sensors at the connection points on patient body. After
the sensors touch the skin or without touching the skin, sensor gives measured analog
values to the microcontroller.
Measuring the heart rate is realized using pulse sensor. There are two measuring points on
patient body. These points are earlobe and finger.
Measuring the body temperature is realized using temperature sensor. This sensor is
working with infrared (IR) technology. This provides a measurement without touching the
skin.
The microcontroller Arduino UNO gets the values, which come from sensors and compile
them and gives desired output.
ESP8266 is a wi-fi module used for sending the data comes out from microcontroller to the
internet. In this way, it is possible to make a measurement and have continuous values.
Showing the values graphically is possible with this feature. There is an auxiliary website
to plot these graphs taking the sensor values from ESP module using some APIs.
In addition, the numerical values of heart rate and body temperature are displayed on the
LCD.
3
1.4 Block Diagram of Patient Health Monitoring System
A health monitoring system consist of different blocks. IoT based health monitoring
system has two blocks namely, digital circuit part and network part. Digital circuit block is
responsible for measuring the health values using sensors. Displaying the numerical values
on the screen. It has the process of compiling data and convert its values to desired form.
Second block is related with IoT part of the system. In this block, the data, which are
coming from microcontroller, are send to the internet. Transmission of data over internet
requires a special wi-fi module which works with the microcontroller. In this health
monitoring system, the microcontroller is chosen as Arduino UNO. So the ESP8266 wi-fi
module is suitable for data transmission over the internet. There are different versions of
this module for different applications. However this version is common and more
suggested for wi-fi connection.
Visualization of the heart rate and body temperature values of patient can be plotted on a
website which supports APIs. That means the health monitoring system and this website
can work together. That provides a graphical visualization at a given time instant.
4
Measuring part is described in the figure 1.3.1. Then the data should be sent over internet.
This is realized in second block diagram of patient health monitoring system. This makes
the health values easy to access from anywhere you want. IoT based systems is beneficial
for these kind of applications.
The parts of patient health monitoring device and detailed information about working
principle of sensors and all design will be described in next parts with technical
information and diagrams to make the system understandable.
5
2. IoT BASED PATIENT MONITORING SYSTEM
IoT implementations use different technical communications models, each with its own
characteristics. Four common communications models described by the Internet
Architecture Board include [7]:
Device-to-Device
Device-to-Cloud
Device-to-Gateway
Back-End Data Sharing
These models highlight the flexibility in the ways that IoT devices can connect and provide
value to the user.
There are numerous real-world applications of the internet of things, ranging from
consumer IoT and enterprise IoT to manufacturing and industrial IoT (IIoT). IoT
applications span numerous verticals including automotive, telecommunication, medical,
energy and more.
Wearable devices with sensors and software can collect and analyze user data, sending
messages to other technologies about the users with the aim of making user’s lives easier
and more comfortable. In healthcare, IoT offers many benefits, including the ability to
monitor patients more closely to use the data that is generated and analyze it. Hospitals
often use IoT systems to complete tasks such as inventory management, for both
pharmaceuticals and medical instruments.
In this project, these features of IoT were used to monitoring the patient health.
6
Figure 2.2.1 IoT Block Diagram
The ESP8266 is a very user friendly and low cost device to provide internet connectivity to
your projects. This module with full TCP/IP stack and microcontroller capability produced
by Shanghai-based Chinese manufacturer, Espressif Systems. It can work both as an
Access point (can create hotspot) and as a station (can connect to Wi-Fi), hence it can
easily fetch data and upload it to the internet making Internet of Things as easy as possible.
It can also fetch data from internet using API’s hence your project could access any
information that is available in the internet, thus making it smarter. For this reason,
ESP8266 module was used in this project. There are different ESP versions for different
applications such as ESP32, Nodemcu Lolin. Some modules can be programmed without
the use of an external microcontroller.
7
The ESP8266 can be controlled from your local Wi-Fi network or from the internet (after
port forwarding). The ESP-01 module has GPIO pins that can be programmed to turn an
LED or a relay ON/OFF through the internet. The module can be programmed using an
Arduino/USB-to-TTL converter through the serial pins (RX, TX).
There are different pin connections of this module. This module sometimes needs a
firmware update or if something is wrong in ESP8266, it needs a flash to reset itself and
turns back the default. When the GPIO0 is connected to ground, it enters the reset mode.
During data transmission or receiving data from internet just TX, RX, CH_PD, VCC, GND
pins are connected to related pins of microcontroller.
In this project, ESP8266 wi-fi module is used with Arduino UNO. ESP8266 needs a
configuration for wireless network connection. Beside this, the default baund rate settings
are 115200 for serial communication. The configuration of ESP8266 has a special
command list. These are “AT” commands. The library of wi-fi module must be added to
arduino libraries to recognize the codes and AT commands.
Before data transmission over internet via ESP8266, the wi-fi module must be connected to
the network with “SSID”, “password”. For this connection AT commands are used.
First of all, a standard command set created by a company named Hayes is used in UART
communication. It takes its name from the presence of AT letters at the beginning of each
command and is used especially in communication units such as GSM modules, fax,
modem, Bluetooth. For example, when you make a call with your phone, the processor of
your phone sends an AT command to the GSM module and the search starts.
With the help of these AT commands, our ESP module can perform various functions; for
example, it can find and connect to wireless networks in the environment, or set up its own
wireless network.
Then required pin connections are made. Now we need a serial port terminal running on
our computer to send AT commands. In this project, Arduino IDE’s serial port screen was
used. Baund rate cannot be different than 115200. The required AT commands are
explained below.
8
To configure ESP8266, Arduino IDE’s serial port screen opened. Then following
commands are sent.
The required pin connections for wi-fi module configuration is given below. This
connection visual was plotted using fritzing.
9
2.4 What is ThingSpeak ?
ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud. ThingSpeak provides instant visualizations of data
posted by your devices to ThingSpeak. With the ability to execute MATLAB-Arduino
code in ThingSpeak you can perform online analysis and processing of the data as it comes
in. ThingSpeak is often used for prototyping and proof of concept IoT systems that require
analytics [2].
Internet of Things describes an emerging trend where a large number of embedded devices
are connected to the Internet. These connected devices communicate with people and other
things and often provide sensor data to cloud storage and cloud computing resources where
the data is processed and analyzed to gain important insights. Cheap cloud computing
power and increased device connectivity is enabling this trend [2].
IoT solutions are built for many vertical applications such as environmental monitoring
and control, health monitoring, industrial monitoring and control and home automation.
Therefore, ThingSpeak was choosen as IoT platform in this project for health monitoring
application.
10
On the left, we have the smart devices that live at the edge of the network. These devices
collect data and include things like wearable devices, temperatures sensors, heart rate
monitors and other sensors.
In the middle, we have the cloud where data from many sources is aggregated and
analyzed in real time often by an IoT analytics platform designed for this purpose.
The right side of the diagram depicts the algorithm development associated with the IoT
application. Here an engineer tries to collect data by performing historical analysis on the
data. In this case, the data is pulled from the IoT platform into a desktop software
environment to enable the engineer or scientist to prototype algorithms that may eventually
execute in the cloud or on the smart device itself [1].
An IoT system includes all these elements. ThingSpeak fits in the cloud part of the diagram
and provides a platform to quickly collect and analyze data from internet connected
sensors. In this project, ThingSpeak provides visualization of pulse sensor and temperature
sensor IR data in real time.
In this IoT based health monitoring system, pulse sensor and IR temperature sensor values
were visualized on ThingSpeak with a spesific API key and related channels.
11
2.5 Measurement of Heart Rate - Body Temperature
Patient Health Monitoring System includes two measurements of health values that are
crucial for human health. These are heart rate and body temperature. In this project, we
were used a pulse sensor for heart rate and an infrared temperature sensor for body
temperature. These measurements are described below.
The heart rate is one of the 'vital signs' or the important indicators of health in the
human body. It measures the number of times per minute that the heart contracts or
beats. The speed of the heartbeat varies because of physical activity, threats to safety
and emotional responses. While a normal heart rate does not guarantee that a person is
free of health problems, it is a useful benchmark for identifying a range of health issues.
The normal resting heart rate for adults over the age of 10 years, including older adults
is between 60 and 100 beats per minute(BPM). Therefore, it is important an instant
monitoring of heart rate.
There are two ways to measure the heart beat. Namely, one of them manual way (using
two fingers placing at wrist or neck). Other way is using sensors as in this project.
12
When a heartbeat occurs blood is pumped through the human body and gets squeezed into
the capillary tissues. The volume of these capillary tissues increases as a result of the
heartbeat. But in between the heartbeats (the time between two consecutive heartbeats)
this volume inside capillary tissues decreases. This change in volume between the
heartbeats affects the amount of light that will transmit through these tissues [3]. This
change is very small but we can measure it with the help of Arduino.
The pulse sensor module has a light that helps in measuring the pulse rate. When we place
the finger on the pulse sensor, the light reflected will change based on the volume of blood
inside the capillary blood vessels. During a heartbeat, the volume inside the capillary blood
vessels will be high. This affects the reflection of light and the light reflected at the time of
a heartbeat will be less compared to that of the time during which there is no heartbeat
(during the period of time when there is no heartbeat or the time period in between
heartbeats, the volume inside the capillary vessels will be lesser. This will lead higher
reflection of light).
This variation in light transmission and reflection can be obtained as a pulse from the
output of pulse sensor. Then, this pulse can be conditioned to measure heartbeat and then
can be programmed accordingly to read as heartbeat count.
13
Body temperature is a measure of your body's ability to make and to get rid of heat.
The body is very good at keeping its temperature within a safe range, even when
temperatures outside the body change a lot. When you are too hot, the blood vessels in
your skin widen to carry the excess heat to your skin's surface. You may start to sweat.
As the sweat evaporates, it helps cool your body. When you are too cold, your blood
vessels narrow. This reduces blood flow to your skin to save body heat. You may start
to shiver. When the muscles tremble this way, it helps to make more heat.
Most people think a normal body temperature is an oral temperature (by mouth) of
(37°C). This is an average of normal body temperatures. Your normal temperature may
actually be (0.6°C) or more above or below this. Also, your normal temperature changes
by as much as (0.6°C) during the day, depending on how active you are and the time of
day. Temperature changes above this value or the abnormal values can be a danger for
health. In this case, needs a doctor check [4].
14
The MLX90615 is built from 2 chips, the Infra-Red thermopile detector and the signal
conditioning chip MLX90325, specially designed by Melexis to process the output of IR
sensor. Thanks to the low noise amplifier, high resolution 16-bit ADC and powerful DSP
unit of the MLX90325, Melexis is able to deliver a high accuracy and high resolution
infrared thermometer. The calculated object and ambient temperatures are available in the
RAM memory of the MLX90325 with a resolution of 0.02°C. The values are accessible by
2 wire serial SMBus compatible protocol with a resolution of 0.02°C or via a 10-bit PWM
(Pulse Width Modulated) signal from the device [5].
The MLX90615 is factory calibrated in standard temperature ranges from: -40 to 85°C for
the ambient temperature and from -40 to 115°C for the object temperature. In this project,
we aim to measure the body temperature and this sensor is suitable for application.
15
In this project, MLX90615 was used for contactless body temperature measurement. Real
visual of IR sensor given below.
After the body temperature and heart rate measured, the data is being sent over internet by
ESP8266 wi-fi module. Then ThingSpeak gets measured values from system using API
key and plots graphs of each variable.
These are general information about sensors and data transfer over internet. Detailed
information will be given in following parts.
16
2.6 Description of Software Language: Arduino IDE
In this project, Arduino programming language was chosen. Arduino works with sensors
gets the values and compile it using the specific libraries that belongs to developer of the
sensor. Then this microcontroller gives desired output. For internet connection and IoT part
ESP8266 was used. Arduino supports this wi-fi module with adding specific codes and
serial port of Arduino IDE is good for this application. The Arduino programming
language is simpler than most of the programming languages.
17
3.IMPLEMENTATION OF IoT BASED PATIENT HEALTH
MONITORING SYSTEM
Our project is implemented on the Arduino UNO board. The Arduino UNO board is
specifically designed to meet the needs of high volume, cost effective consumer electronic
applications. There are different type of Arduino boards with different number of analog-
digital pins. However, Arduino UNO board is enough for this project. This board is shown
below.
18
3.2 Block Diagram of Health Monitoring System
Block diagram of the design that is implemented with Arduino UNO board is given in theb
figure below. Diagram shows a combined version of all modules used in designing IoT
Based Patient Health Monitoring in our project. Each module is combined together and
generated the all system.
19
3.2.1 Definition of Sub-Parts of System
Pulse Sensor
In this project, heart rate measurement is implemented using a pulse sensor. General
definition of heart rate is the number of times your heart beats in one minute. The
normal range of heart rate is 60-100 beats per minute. This pulse sensor is designed to
measure the pulses from finger and earlobe. The sensor has a special led on it. To
measure the pulses the patient should put the finger or earlobe on this led. This pulse
sensor generates signals when a pulse is happened. Changes of light volume in blood
gives information about heart pulses and timing is important for heart rate measurement.
Shape of this sensor and features are given below.
20
Pin Configuration
Working Principle of Pulse Sensor
The working of the Pulse Sensor is very simple. The sensor has two sides, on one side the
LED is placed along with an ambient light sensor and on the other side we have some
circuitry. This circuitry is responsible for the amplification and noise cancellation work.
The LED on the front side of the sensor is placed over a vein in our human body. This can
either be your fingertip or you ear tips, but it should be placed directly on top of a vein.
Now the LED emits light that will fall on the vein directly. The veins will have blood flow
inside them only when the heart is pumping, so if we monitor the flow of blood we can
monitor the heartbeats as well. If the flow of blood is detected then the ambient light
sensor will pick up more light since the blood will reflect the light, then this minor change
in received light is analyzed over time to determine our heart beats.
Using pulse sensor is straight forward, but positioning it in the right way matters. Since all
the electronics on the sensor are directly exposed, it is also recommended to cover the
sensor with hot glue, vinyl tape or other nonconductive materials. In addition, it is not
recommended to handle these sensors with wet hands. The flat side of the sensor should be
placed on top of the vein and a slight presser should be applied on top of it, normally clips
or Velcro tapes are used to attain this pressure.
To use the sensor simply power it using the Vcc and ground pins, the sensor can operate
both at +5V or 3.3V system. Once powered connect the Signal pin to the ADC pin of the
microcontroller to monitor the change in output voltage. In this project, Arduino UNO
development board is used. After some programming, it is possible to get the bpm values
and see them on serial port screen of Arduino IDE.
21
The infrared thermometer comes factory calibrated with a digital SMBus output giving
full access to the measured temperature in the complete temperature range(s) with a
resolution of 0.02 °C. The sensor achieves an accuracy of ±0.2°C within the relevant
medical temperature range. The user can choose to configure the digital output to be
PWM.
Note: The System Management Bus (SMBus) is more or less a derivative of the I2C
bus. The standard has been developed by Intel and is now maintained by the SBS
Forum. The main application of the SMBus is to monitor critical parameters on PC
motherboards and in embedded systems. For example, there a lot of supply voltage
monitor, temperature monitor and fan monitor/control ICs with a SMBus interface
available.
Features of MLX90615
Pin Configuration
Principle of Operation
The IR sensor consists of series connected thermo-couples with cold junctions placed at
thick chip substrate and hot junctions, placed over thin membrane. The IR radiation
absorbed from the membrane heats (or cools) it.
Where To is the object absolute temperature (Kelvin), Ta is the sensor die absolute
(Kelvin) temperature and A is the overall sensitivity. An additional sensor is needed for the
chip temperature. After measurement of the output of both sensors, corresponding to
ambient and object temperatures can be calculated. These calculations are done by the
internal DSP, which produces digital outputs, linearly proportional to measured
temperatures [5].
23
A DSP embedded in the MLX90615 controls the measurements, calculates object and
ambient temperatures and does the post-processing of the temperatures to output them
through SMBus compatible interface or PWM. The output of the IR sensor is amplified by
a low noise, low offset chopper amplifier with programmable gain, then converted by a
Sigma Delta modulator to a single bit stream and fed to the DSP for further processing.
The signal passes a FIR low pass filter with fixed length of 65536.The output of the FIR
filter is the measurement result and is available in the internal RAM. Based on results of
the above measurements, the corresponding ambient temperature TA and object
temperatures TO are calculated. Both calculated temperatures have a resolution of 0.02 °C
[5].
-Amplifier-
A low noise, low offset amplifier with programmable gain is used for amplifying the IR
sensor voltage.
The Power On Reset (POR) is connected to the Vdd supply. The on-chip POR circuit
provides an active level of the POR signal when the Vdd voltage rises above
approximately 0.5V and holds the entire MLX90615 in reset until the Vdd is higher than
the specified POR threshold VPOR [5].
24
-EEPROM-
EEPROM is a small storage unit that can hold the variable data we need, write and delete
these data electrically. We can save our data to the EEPROM internally in Arduino's
microprocessor and we can use this data again at any time.
The whole EEPROM can be read and written with the SMBus interface. The entire
EEPROM content between addresses 0x04 and 0x0D must be kept unaltered or the factory
calibration of the device will be lost [5].
SMBus Slave Adress:7 LSBs (6...0) contains the SMBus slave address that the
MLX90615 will respond to. Note that all MLX90615 will respond to SA=0x00 and
therefore, this value is useless in a network. Factory default SA is 0x5B, max 127 devices
on one line SA=0x01 …0x7F[5]
PWM Tmin:15 bit for the minimum temperature when PWM is used – right justified
(factory default is 0x355B, which corresponds to +0.03°C) [5]
PWM T range:15 bit range for the PWM signal temperature (TMAX – TMIN) – right
justified (factory default is 0x09C4, which corresponds to a PWM range of 50.01°C).[5]
Config Register :This register consist of control bits to configure the thermometer after
POR
RAM: RAM can be read through SMBus interface. Ta is the MLX90615 package
(ambient) temperature and To is the object temperature. The output scale is 0.02°K/LSB.
To convert a read object temperature into degrees Celsius equation is given below [5].
25
-SMBus Compatible 2-wire Protocol-
The chip supports a 2 wires serial protocol, build with pins SDA and SCL. The SMBus
interface is a 2-wire protocol, allowing communication between the Master Device (MD)
and one or more Slave Devices (SD). In the system only one master can be present at any
given time. The MLX90615 can only be used as a slave device [5].
SCL (digital input), used as the clock for SMBus compatible communication [5].
SDA / PWM – Digital input / NMOS open drain output, used for PWM and input /
output for the SMBus [5].
The SDA pin of the MLX90615 can operate also as a PWM output, depending on the
EEPROM settings. If PWM is enabled, after POR the SDA pin is directly configured as a
PWM output.
The temperature reading can be calculated from the signal timing as:
t2
Tout=2 x x ( Tmax−Tmin ) +Tmin
T
where Tmin and Trange are the corresponding rescale coefficients in EEPROM for the
selected temperature output and T is the PWM period. The calculated ambient and object
temperatures are stored in RAM with a resolution of 0.02°C (15 bit). The PWM operates
with a 10-bit number so the transmitted temperature is rescaled in order to fit in the desired
range. For this goal 2 cells in EEPROM are foreseen to store the desired temperature
range, pwm Tmin and pwm Trange. Equation is given below [5]:
Tram−Tmin(eeprom) Trange(eeprom)
Tpwm= , Kpwm=
Kpwm 1023
Result in 10-bit word which corresponds 0x000 PWM Tmin and 0x3FF Tmax and 1LSB
is
Tmax−Tmin
LSB= [Celsius]
1023
26
ESP8266 Wi-Fi Module
In this project, wi-fi connection and IoT part of project is implemented using ESP8266.
This wi-fi module provides transmitting data to the internet. In Patient Health Monitoring
System the heart rate and body temperature is measured by sensors then compiled by
Arduino UNO board and transmission part is implemented by ESP8266. There is a special
website on internet namely ThingSpeak. In this project, measured values are visualized on
this website graphically. This provides checking the patient’s heart rate and body
temperature values anywhere you have the internet connection. This operation is provided
by ESP8266. Design and configuration of ESP8266 wi-fi module is explained below.
27
-ESP8266 Pin Configuration-
Note: There are different pin connections for different applications such as resetting
ESP8266, configuring with AT-commands, code uploading.
Note: Sometimes this module requires a firmware update to respond the AT-commands.
For this application, there is a special program as ESP8266 Flasher. It is easy to update the
firmware version by applying required steps given below.
28
-ESP8266 Firmware Update and Reset-
There are two different programs here. One of them is used for resetting the ESP8266
when something is wrong in wi-fi module. Other program is used for firmware update to
make the module ready for wi-fi connection.
Note: GPIO-0 pin must be connected to GND to change the module mode as flash. Then to
connect the module to Arduino UNO. It will automatically detects the COM Port. It is
necessary to add the required documents and change the right baudrate as given below.
Click Flash and it gets AP MAC – STA MAC addresses. Then firmware update is
completed.
29
Here is the reset program, if something wrong in ESP8266. Connect the module and start
the program it will automatically reset the module to default.
There are two different connection types. One of them using USB-TTL converter with this
device it is possible to programming ESP8266 Wi-Fi without Arduino UNO. Just plug the
module on USB-TTL converter and connect it to the computer. It is necessary to choose
the board as ESP8266 from Arduino IDE and libraries should be added too.
Another way is programming ESP8266 over Arduino UNO board. TX-RX pins must be
connected. Important thing is here the GPIO-0 pin should not be connected to ground.
Other connections TX-RX , RX-TX , CH_PAD=3v3 , VCC=3v3, GND=GND. Then
connect the usb to the computer. Open the Arduino IDE’s Serial Port screen and change
the baud rate as 115200. Then with AT-commands connecting the module to wi-fi is
possible with related “SSID”, ”Password”. Required AT-Commads are given below. Then
the module is connected to our project.
30
LCD Screen
In the project, the numerical values of heart rate and body temperature is shown using a
LCD screen. It is placed on the project box. This way the measured values can be seen
easily. This screen is chosen 2x16 LCD.
31
3.3 Building the Patient Health Monitoring System
At first step, the required connections are made. Sensors, ESP8266, LCD all are connected
to the Arduino UNO. Before connecting ESP8266 it is important to be sure that the module
is connected wifi. Then program file is uploaded to the Arduino UNO. Finally, the health
monitoring system is ready to measure heart rate and body temperature.
After the program uploading is done this monitoring system can be used anywhere while
system is powered. The patient must connect his or her finger to pulse sensor. This sensor
is covered by a velcro strap to make it easy to wear. For body temperature measurement,
the patient’s hand must be placed closer to the MLX90615 sensor about 5cm. Finally,
measured heart rate and body temperature values can be seen on the LCD screen on the
system box. IoT part of this project provides visualization of the heart rate and body
temperature values via ThingSpeak website. For this part, there is a channel created and it
has a special channel ID. Just search this channel ID number on ThingSpeak website. It is
easy to see the related channel and it is enough to click on it to see the graphical visuals
and gauges of numerical values coming from the sensors. Beside this, there is an
application namely Thingview you can download it. Then search the channel ID number-
channel author name and access the related channel to see the same graphs and gauges.
This provides a mobile connection to the patient health monitoring system.
Figure 3.3.1 Steps for building the Patient Health Monitoring System
32
4. RESULTS
After the Arduino program writing, written program is compiled and uploaded using
Arduino IDE. Then the patient health monitoring system is powered. Sensors are
connected to the patient’s body. Then Serial Monitor of Arduino IDE is opened to check
the wifi connection is completed. At the same time, heart rate (BPM) and body temperature
values were seen. The values are flowing on serial monitor continuously and it is important
to see get update key/API part on serial monitor. That means the values are sending to
ThingSpeak. Serial monitor screen is given below is taken from a measurement in our
project.
Figure 4.1 Serial Monitor Data Flow in Arduino IDE
33
The IoT based patient health monitoring system consist of three steps. At first step, system
design and programming part was completed. At second step, the connection of sensors to
the patient’s body was completed. This connection is made by a wearable glove. This
glove has a velcro band to wrap the patient’s finger for heart rate measurement. For
temperature measurement, the patient should put his or her hand on a rectangular type box
placed on the system box. There is a hole on this box where the infrared temperature
sensor was placed in. After the all connections are made monitoring part starts. At last step,
IoT part comes in. Measured heart rate and body temperature values are sent to
ThingSpeak. The patient or doctor can monitor these values from related channel using
laptop, Ipad or mobile phone. The ThingSpeak channel view is given below.
Figure 4.2 Channel view in ThingSpeak
34
Channel ID for our project is 714946. Searching this channel number or channel author
name emretamturk96 on ThingSpeak website or mobile app it is easy to access to this
channel. This channel has a lamp indicator. This provides a notification. If the values of
heart rate and body temperature is out of the range this lamp turns red color. Another
feature is location of patient can be found via map view.
Figure 4.3 Lamp indicator and channel location in ThingSpeak
Finally, all system is described briefly with given results and features in result part. This
patient health monitoring system provides an easy measurement and monitoring thanks to
it’s design and IoT technology.
35
5. CONCLUSION
Although this monitoring system is good for patients there are a few disadvantages too.
IoT technology is growing continuously. So the shape of medical devices such as health
monitoring systems are getting smaller. But, the designed system is a little bit big to carry.
It could be better to design a smaller wearable device like smart watches or smart bracelets.
Another disadvantage is wifi problem, sometimes the connection is bad and it is hard to
send data to internet. It can be good to use a higher level wifi module for a high quality
internet connection. Cost of this project is not high but it is possible to design a more cost
effective patient health monitoring system.
As conclusion, this IoT based patient health monitoring system works well. Monitoring is
supported with LCD screen and many visuals such as gauges, waveforms on the internet.
Measuring and monitoring of heart rate and body temperature is possible with this system
design.
36
6. APPENDIX
IoT Based Patient Health Monitoring System Codes
#include <LiquidCrystal.h> //Add LCD Library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Defines digital pins of LCD
#include <SoftwareSerial.h> //Add Library for Serial Communication
#include <Wire.h> //Add wire Library
#include <mlx90615.h> //Add Temperature Sensor Library
MLX90615 mlx = MLX90615(); //Defines the sensor name
37
//REGARDS SERIAL OUTPUT—SET THIS UP TO YOUR NEEDS
static boolean serialVisual = true; //Default is false,Re-set is true to see ASCII pulse
volatile int rate[10]; //Array to Hold Last ten Initial Beat Impulse Values
volatile unsigned long sampleCounter = 0; //Used to Determine Pulse Timing
volatile unsigned long lastBeatTime = 0; //Used to Find Initial Beat Impulse
volatile int P = 512; //Used to Find Peak In Pulse Wave
volatile int T = 512; //Used to Find Trough in Pulse Wave
volatile int thresh = 525; //Used to Find Instant Moment of Heart Beat
volatile int amp = 100; //Used to Hold Amplitude of Pulse Waveform
volatile boolean firstBeat = true; //Seed Rate Array Startup with Reasonable BPM
volatile boolean secondBeat = false; //Seed Rate Array Startup with Reasonable BPM
void setup() { //MAIN SETUP FUNCTION OF CODE
lcd.begin(16, 2); //Starts the LCD Screen
pinMode(blinkPin,OUTPUT); //Pin for blink with heartbeat
pinMode(fadePin,OUTPUT); //Pin for fade with heartbeat
Serial.begin(115200); //Sets baundrate for Serial Communication
mlx.begin(); //Starts the Mlx temperature Sensor
interruptSetup(); //Sets up to Read Pulse Sensor Signal at every 2ms
lcd.clear(); //Clears the LCD Screen
lcd.setCursor(0,0); //Sets the Position of Cursor
lcd.print(" Patient Health"); //Writes Text on LCD
lcd.setCursor(0,1); //Sets the Position of Cursor
lcd.print(" Monitoring "); //Writes Text on LCD
delay(4000); //Waits 4 second
lcd.clear(); //Clears the LCD Screen
lcd.setCursor(0,0); //Sets the Position of Cursor
lcd.print("Initializing...."); //Writes Text on LCD
delay(5000); //Waits 5 second
38
lcd.clear(); //Clears the LCD Screen
lcd.setCursor(0,0); //Sets the Position of Cursor
lcd.print("Getting Data...."); //Writes Text on LCD
ser.begin(115200); //Sets baundrate for ESP8266 Serial Communication
ser.println("AT"); //Sends AT and waits for respond OK
delay(1000); //Waits 1 second
ser.println("AT+GMR"); //Shows the version of ESP8266
delay(1000); //Waits 1 second
ser.println("AT+CWMODE=3"); //Sets ESP8266 mode for internet connection
delay(1000); //Waits 1 second
ser.println("AT+RST"); //Resets the ESP8266 Module
delay(5000); //Waits 5 second
ser.println("AT+CIPMUX=1"); //Sets Multiple Connection
delay(1000); // Waits 1 second
39
void loop() //STARTS LOOP FUNCTION
{
serialOutput(); //Defines another Loop in Main Loop
if (QS == true) //A Heartbeat was Found by Arduino then QS is True
{ //BPM and IBI have been Determined
fadeRate = 255; //Makes LED Fade Effect Happen Sets 255 to Fade with Pulse
serialOutputWhenBeatHappens(); //Defines another Loop for Heartbeat to Serial
QS = false; //Reset the Quantified Self Flag for next time
}
ledFadeToBeat(); //Defines another Loop for LED Fade
delay(20); //Waits 20ms
read_temp(); //Defines another Loop for Temperature Read
esp_8266(); //Defines another Loop for ESP8266 Settings
}
void ledFadeToBeat() //Calls Loop for LED Fade Effect
{
fadeRate -= 15; //Sets LED Fade Value
fadeRate = constrain(fadeRate,0,255); //Keeps LED Fade Value in Positive Range
analogWrite(fadePin,fadeRate); //Fade LED
}
void interruptSetup() //Calls Function from Main Setup
{ //Initializes Timer2 to Throw an interrupt at 2ms
TCCR2A = 0x02; //Disable PWM on D3-D11 Pins go to CTC Mode
TCCR2B = 0x06; //256 Prescaler
OCR2A = 0X7C; //Set the Top of the Count to 124 for Sampling at 500Hz
TIMSK2 = 0x02; //Enable Interrupt on Match Between Timer2 and OCR2A
sei(); } //Make Sure Global Interrupts are Enabled
40
void serialOutput() //Calls Loop from Main Loop
{ //Decide How to Output Signal
if (serialVisual == true)
{
arduinoSerialMonitorVisual('-', Signal); //Goes to Function that Makes Serial Monitor
}
else
{
sendDataToSerial('S', Signal); //Goes to sendDataToSerial Function
}
}
void serialOutputWhenBeatHappens() //Calls Loop from Main Loop
{ //A Beat Happened,Output to Serial
if (serialVisual == true) //Code to make Serial Monitor Visualizer Work
{
Serial.print("*** Heart-Beat Happened *** "); //ASCII-Writes on Serial Monitor
Serial.print("BPM: "); //Writes Text on Serial Monitor
Serial.println(BPM); //Writes BPM Value on Serial Monitor
}
else
{
sendDataToSerial('B',BPM); //Send Heart-rate with a ‘B’ prefix
sendDataToSerial('Q',IBI); //Send Time between Beats with ‘Q’ prefix
}
}
41
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 of 12 options
int range = map(sensorReading, sensorMin, sensorMax, 0, 11);
switch (range) { //Defines the different options with range
case 0:
Serial.println(""); /////ASCII
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("--------------|---");
break;
42
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 ) //Calls the Function from Loop
{
Serial.print(symbol); //Writes the symbol
Serial.println(data); //Writes the data value
}
43
ISR(TIMER2_COMPA_vect) //Triggered when Timer2 counts to 124
{
cli(); //Disable Interrupts while doing this
Signal = analogRead(pulsePin); //Read the Pulse Sensor
sampleCounter += 2; //Keep track of Time in ms with this variable
int N = sampleCounter - lastBeatTime; //Monitor Time since to Lastbeat to Avoid Noise
if(Signal < thresh && N > (IBI/5)*3) //Avoid Noise by Wait 3/5 of Last IBI
{ //Finds the Peak and Trough of Pulse Wave
if (Signal < T) //T is Through
{
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 Value
} //Keep Track of Highest Point in Pulse Wave-Look for HeartBeat
if (N > 250) //Avoid High Frequency Noise
{
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
{
Pulse = true; //Set the Pulse Flag when There is a Pulse
digitalWrite(blinkPin,HIGH); //Turn on Pin 13 LED
IBI = sampleCounter - lastBeatTime; //Measure the Time Between Beats in ms
lastBeatTime = sampleCounter; //Keep track of Time for Next Pulse
44
if(secondBeat) { //If this is a Second Beat,If secondBeat==TRUE
secondBeat = false; //Clear secondBeat Flag
for(int i=0; i<=9; i++) //To get a realistic BPM at Startup
{
rate[i] = IBI;
}
}
if(firstBeat) //It is the first time Beat is found if firstBeat==TRUE
{
firstBeat = false; //Clear FirstBeat Flag
secondBeat = true; //Set the SecondBeat Flag
sei(); //Enable Interrupts Again
return; //IBI Values is unreliable so Discard it
} //Keep Running Total of Last 10 IBI Values
word runningTotal = 0; //Clear the Running Total Variable
for(int i=0; i<=8; i++)
{ //Shift Data in the Rate Array
rate[i] = rate[i+1]; //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 Running Total
runningTotal /= 10; //Average the Last 10 IBI Values
BPM = 60000/runningTotal; //How many Beats can Fit into a minute-That is BPM!
QS = true; //Set Quantified Self Flag-This is not cleared in ISR
pulse = BPM; //Assign BPM to pulse
}
}
45
if (Signal < thresh && Pulse == true)
{ //Values are going down,Beat is over
digitalWrite(blinkPin,LOW); //Turn of pin 13 LED
Pulse = false; //Reset the Pulse Flag-Repeats the same thing
amp = P - T; //Gets Amplitude of Pulse Wave
thresh = amp/2 + T; //Set thresh at %50 of Amplitude
P = thresh; //Reset this for next time
T = thresh; //Reset this for next time
}
if (N > 2500)
{ //If 2.5seconds go by without a Beat
thresh = 512; //Set thresh to Default Value
P = 512; //Set P to Default Value
T = 512; //Set T to Default Value
lastBeatTime = sampleCounter; //Bring the lastBeatTime up to Date
firstBeat = true; //Set to Avoid Noise when Heartbeat gets back
secondBeat = false; //Set to Avoid Noise when Heartbeat gets back
}
sei(); //Enable Interrupts when it is done
} //Ends ISR-Interrupt Service Routine
46
void esp_8266() //Calls Loop from Main Loop for ESP8266
{
String cmd = "AT+CIPSTART=4,\"TCP\",\""; //TCP Connection
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80"; //Related settings for Connection
ser.println(cmd);
Serial.println(cmd);
if(ser.find("Error")) //If There is an Error to check the everything is OK
{
Serial.println("AT+CIPSTART error"); //Gives Notification
return;}
String getStr = "GET /update?api_key="; //Gets the API key
getStr += apiKey;
getStr +="&field1=";
getStr +=String(temp); //Sends the Temperature value with API to Field1
getStr +="&field2=";
getStr +=String(pulse); //Sends the Pulse value with API to Field2
getStr += "\r\n\r\n";
//Sends Data Length
cmd = "AT+CIPSEND=4,";
cmd += String(getStr.length()); //Gets the Data Length
ser.println(cmd);
Serial.println(cmd);
delay(1000); //Waits 1 second
ser.print(getStr);
Serial.println(getStr); //Writes Data
delay(3000); //Waits 3 second
}
47
void read_temp() //Calls Loop from Main Loop for Temperature Read
{
float temp_value=(mlx.get_object_temp()); //Gets the Temperature Value
temp=temp_value; //Assign Numerical Value to temp
Serial.print("Temperature:"); //Writes text on Serial Monitor
Serial.println(temp); //Writes Temperature Value on Serial
lcd.clear(); //Clears LCD Screen
lcd.setCursor(0,0); //Set the Position of Cursor
lcd.print("BPM :"); //Writes BPM on LCD
lcd.setCursor(7,0); //Set the Position of Cursor
lcd.print(BPM); //Writes BPM Value to LCD
lcd.setCursor(0,1); //Set the Position of Cursor
lcd.print("Temp.:"); //Writes Temp on LCD
lcd.setCursor(7,1); //Set the Position of Cursor
lcd.print(temp); //Writes Temp Value to LCD
lcd.print((char)223); //Writes C character on LCD
lcd.setCursor(13,1); //Set the Position of Cursor
lcd.print("C"); //Writes C
}
48
REFERENCES
[1] History of Patient Monitoring System
https://www.glenmedsolutions.com/history-patient-monitoring-systems/
https://thingspeak.com/pages/learn_more
[3]Heart Rate
https://www.elprocus.com/heartbeat-sensor-working-application/
[4]Body Temperature
https://www.uofmhealth.org/health-library/hw198785
https://www.melexis.com/en/product/MLX90615
[6]About Arduino
https://www.arduino.cc/en/guide/introduction
https://internetofthingsagenda.techtarget.com/definition/Internet-of-Things-IoT
49