abstract
Heart Beat And Body Temperature Monitoring using Arduino will detect the heart beat using the Pulse Sensor and body temperature using LM-35 sensor.
Sensor and will show the readings in BPM (Beat Per Minute) on the LCD connected to it.The body Temperature will be displayed on serial monitor along with BPM readings.
With the development of technology, in this project we can digitally sensing body temperature and heart rate using arduino. Mainly arduino is used because it can sense the environment by receiving input from variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language. LM35 is used for the sense body temperature. Body temperature is a basic parameter for monitoring and diagnosing human health. Heart beat sensor was used for sensing heart rate. This device will allow one to measure their mean arterial pressure (MAP) in about one minute and the accurate body temperature will be displayed on the Android. The system can be used to measure physiological parameters, such as Heart rate (Systolic and Diastolic), Pulse rate.
Problem Statement
One of the increasing popular public concerns is human health. Anything else becomes meaningless if one gets sick or dead. For this reason, people spend a lot of money to keep sound health. Unfortunately, people always find that it is too late to receive serious medical care when things are non-invertible.
If early actions can be taken in time then lots of patients can be cured. However, access to many medical equipment is inconvenient and expensive. Heart rate and body temperature are the most vital ones among the most notable indexes of the human health, and they have the advantage of easy access. Moreover, unlike the X-ray, the measurement of heart rate and body temperature has no effect on human health itself.
There are some devices in the current market which can provide raw medical measurement data to patients and doctors, but the patients may not interpret the medical measurement into meaningful diagnosis since they have little medical background. On the other hand, if raw medical data is delivered to the doctor, it kills much time and may cause trouble, but in emergencies time can never be wasted. It is tough to share data over a large area within a short period. Most of the products available in the current market have these major drawbacks with limitation in flexibility and portability.
Introduction
Need of Monitoring:
More than 2 million people are at high risk of having heart attack.
It would be helpful if there was a way for these people to monitor their heart .So we have a problem.That is the way our project focuses on how we can overcome this problem and find a solution. Heart rate means the number of heartbeats per unit of time, usually expressed as beats per minute (bpm). Human’s heart pounds to pump oxygen-rich blood to muscles and to carry cell waste products away from tissues .
Heart rate can vary according to the demand of muscles to absorb oxygen and excrete carbon dioxide changes, such as during exercise or sleep . It also varies significantly between individuals based on fitness, age and genetics. That means heart must beat faster to deliver more oxygen-rich blood. During exercise routines, the heart rate gives a strong indication of how effective that routine is improving health. Normal heart rate of a resting person is about 70 bpm for adult males and 75 bpm for adult females. A heart rate monitor is simply a device that takes a sample of heartbeats and computes the beats per minute so that the information can easily track heart condition .
Medical professionals use heart rate for tracking of patient’s physical conditions. Individuals, such as athletes, who are interested in monitoring their heart rate to gain maximum efficiency from their training, also use it. Body temperature means measurement of the body’s ability to generate and get rid of heat. It is one of chief indicators of normal functioning and health. The nature of the human body is to keep its temperature within a narrow, safe range in spite of large variations in temperatures outside the body.
Literature Survey
Extensive research has been dedicated to the exploration of various technologies such as information technologies (IT) in complementing and strengthening existing healthcare services. In particular, the Internet of Things (IoT) has been widely applied to interconnect available medical resources and provide reliable, effective and smart healthcare service to the elderly and patients with a chronic illness. The aim of this project is to summarize the applications of IoT in the healthcare industry and identify the intelligentization trend and directions of future research in this field.
Based on a comprehensive literature review and the discussion of the achievements of the researchers, the advancement of IoT in healthcare systems have been examined from the perspectives of enabling technologies and methodologies, IoT-based smart devices and systems, and diverse applications of IoT in the healthcare industries. Finally, the challenges and prospects of the development of IoT based healthcare systems are discussed in detail.
Block Diagram
Block Diagram of heartbeat and body temperature monitoring
Hardware requirement
- Pulse Sensor
- LM-35 Sensor
- Arduino Uno
- 16 *2 LCD
- Bread Board
- 10k potentiometer
- Connecting wires
Arduino Board
Arduino is an open source platform used for building electronics projects
- Arduino consists of both a physical programmable circuit board (MICROCONTROLLER) and a piece of software (Integrated Development Environment) that runs on our computer, used to upload computer code to the physical board.
Pulse sensor
- Connect the Pulse Sensor with the Arduino. The Pulse sensor has three pins. Connect 5V and the ground pin of the pulse sensor to the 5V and the ground of the Arduino and the signal pin to the A0 of Arduin
LM-35 temperature sensor
The LM35 is one kind of commonly used temperature sensor that can be used to measure temperature with an electrical o/p comparative to the temperature (in °C). It can measure temperature more correctly compare with a thermistor. This sensor generates a high output voltage than thermocouples and may not need that the output voltage is amplified. The LM35 has an output voltage that is proportional to the Celsius temperature. The scale factor is .01V/°C.
LCD display
Liquid crystal display (LCD) screens are by far the most popular screens for electronics today. If you look around you, you’re likely to see at least one or two, possibly on your microwave or landline caller ID box.Your LCD has a total of 16 pins. Here’s what each pin is designed to do:Pins 1 and 16: These are your power and ground. Pin 3: Used to adjust the brightness of the LCD.Pins 4–6: Used to operate the LCD.Pins 7–14: Used as data lines.Pins 15–16: Used to power the LCD’s backlight.
Working
This is a prototype model for IoT based pulse rate monitor. It can be designed as a wearable watch or ear plug. In a wearable design, the character LCD could be removed and the entire circuit can be shifted to small controller board or SOC.
When the circuit is powered by the battery, the Arduino starts reading the pulse rate from the pulse sensor and the ambient temperature from the LM-35 temperature sensor. The pulse sensor has an infrared LED and a photo transistor which help detect pulse at the tip of the finger or earlobe. Whenever it detects pulse, its IR LED flashes. The flash of the IR LED is detected by the phototransistor and its resistance changes when the pulse is changed. The heartbeat of a normal adult ranges from 60 to 100 per minute. For detecting beats per minute (BPM), first an interrupt is set which triggers in every 2 Milliseconds. So, the sampling rate by the Arduino to detect pulse is 500 Hz. This sampling rate is sufficient to detect any pulse rate.
So, at every 2 Milliseconds, the Arduino reads analog voltage output from the pulse sensor. The analog output from the pulse sensor is converted to a digital value using in-built ADC channel. The Arduino has 10-bit long ADC channel, so the digitized value can range from 0 to 1024. The middle value for this range is 512. Initially, the first beat is set to true and the second beat is counted when the condition that analog output from the pulse sensor is greater than the middle point i.e. 512 is satisfied. Then, onwards, every next beat is counted when the analog output from the pulse sensor is greater than the middle point i.e. 512 and 3/5 of the time between the beats recorded in previous cycle has passed. Every time, the beat is detected, a variable representing BPM is updated. This value in this variable is pushed to an array in every minute and is used to represent the actual Beats Per Minute or Heart Rate. The Arduino code also uses a function to provide an LED fading effect on every beat.
The pulse sensor can also detect body temperature. The LM-35 is used to detect the body temperature here. The operating temperature range of LM-35 is from -55 °C to 150 °C. The output voltage varies by 10 mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01 V/ oC. The LM-35 IC does not require any external calibration or trimming to provide typical accuracies of ±0.25 °C at room temperature and ±0.75 °C over temperature range from −55 °C to 150 °C. Under normal conditions, the temperature measured by the sensor won’t exceed or recede the operational range of the sensor. Typically in the temperature range from −55 °C to 150 °C, the voltage output of the sensor increases by 10 mV per degree Celsius.
Code
#include <LiquidCrystal.h>
// Variables
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 8; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
const int sensor=A1; // Assigning analog pin A1 to variable ‘sensor’
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
LiquidCrystal lcd(13,12,6,5,4,3);// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Mustbe 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 = 250; // used to find peak in pulse wave, seeded
volatile int T = 250; // used to find trough in pulse wave, seeded
volatile int thresh = 250; // used to find instant moment of heart beat, seeded
volatile int amp = 50; // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = false; // used to seed rate array so we startup with reasonable BPM
void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
pinMode(sensor,INPUT); // Configuring pin A1 as input
Serial.begin(9600);
}
// Where the Magic Happens
void loop()
{
serialOutput();
if (QS == true) // A Heartbeat Was Found
{
// BPM and IBI have been Determined
// Quantified Self “QS” true when arduino finds a heartbeat
fadeRate = 255; // Makes the LED Fade Effect Happen, Set ‘fadeRate’ Variable to 255 to fade LED with pulse
serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
vout=analogRead(sensor);
vout=(vout*500)/1023;
tempc=vout; // Storing value in Degree Celsius
tempf=(vout*1.8)+32; // Converting to Fahrenheit
Serial.print(“in DegreeC=”);
Serial.print(“\t”);
Serial.print(tempc);
Serial.println();
Serial.print(“in Fahrenheit=”);
Serial.print(“\t”);
Serial.print(tempf);
Serial.println();
lcd.print(“temp in c:”);
lcd.print(tempc);
delay(2000); //Delay of 1 second for ease of viewing
}
ledFadeToBeat(); // Makes the LED Fade Effect Happen
delay(20); // take a break
}
void ledFadeToBeat()
{
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
void interruptSetup()
{
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON’T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}
void serialOutput()
{ // Decide How To Output Serial.
if (serialVisual == true)
{
arduinoSerialMonitorVisual(‘-’, Signal); // goes to function that makes Serial Monitor Visualizer
}
else{
sendDataToSerial(‘S’, Signal); // goes to sendDataToSerial function
}
}
void serialOutputWhenBeatHappens()
{
if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work
{
Serial.print(“*** Heart-Beat Happened *** “); //ASCII Art Madness
Serial.print(“BPM: “);
Serial.println(BPM);
lcd.clear();
lcd.print(“BPM: “);
lcd.print(BPM);}
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:
switch (range)
{case 0:
Serial.println(“”); /////ASCII Art Madnessbreak;
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;
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 )
{
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
} // keep track of highest point in pulse wave
// NOW IT’S TIME TO LOOK FOR THE HEART BEAT
// signal surges up in value every time there is a pulse
if (N > 250)
{ // avoid high frequency noise
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
{
Pulse = true; // set the Pulse flag when we think there is a pulse
digitalWrite(blinkPin,HIGH); // turn on pin 13 LED
IBI = sampleCounter — lastBeatTime; // measure time between beats in mS
lastBeatTime = sampleCounter; // keep track of time for next pulse
if(secondBeat)
{ // if this is the second beat, if secondBeat == TRUE
secondBeat = false; // clear secondBeat flag
for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup
{
rate[i] = IBI;
}
}
if(firstBeat) // if it’s the first time we found a beat, if firstBeat == TRUE
{
firstBeat = false; // clear firstBeat flagsecondBeat = true; // set the second beat flag
sei(); // enable interrupts again
return; // IBI value is unreliable so discard it
}
// keep a running total of the last 10 IBI values
word runningTotal = 0; // clear the runningTotal variable
for(int i=0; i<=8; i++)
{ // shift data in the rate array
rate[i] = rate[i+1]; // and drop the oldest IBI value
runningTotal += rate[i]; // add up the 9 oldest IBI values
}
rate[9] = IBI; // add the latest IBI to the rate array
runningTotal += rate[9]; // add the latest IBI to runningTotal
runningTotal /= 10; // average the last 10 IBI values
BPM = 60000/runningTotal; // how many beats can fit into a minute? that’s BPM!
QS = true; // set Quantified Self flag
// QS FLAG IS NOT CLEARED INSIDE THIS ISR
}
}
if (Signal < thresh && Pulse == true)
{ // when the values are going down, the beat is over
digitalWrite(blinkPin,LOW); // turn off pin 13 LED
Pulse = false; // reset the Pulse flag so we can do it again
amp = P — T; // get amplitude of the pulse wave
thresh = amp/2 + T; // set thresh at 50% of the amplitude
P = thresh; // reset these for next time
T = thresh;
}
if (N > 2500)
{ // if 2.5 seconds go by without a beat
thresh = 250; // set thresh default
P = 250; // set P default
T = 250; // 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
Applications
- Have become a widely used training aid for a variety of sports.
- Hospitals / Dispensaries
- Better and accurate method of measuring heart beat.
- At homes
- A set pointcan help in determining whether a person is healthy or not checking
- his/her heart beat and comparing with set point.
Future Scope
- Monitoring device that could be used to detect the heart beat anomalies of physically challenged Individuals without hands.
- Also a graphical LCD can be used to display a graph of the change of heart rate over time.
- A serial output can be incorporated into the device so that the heart rates can be sent to a Personal Computer (PC) for further online or offline analysis.
- It could be integrated with mobile technology for e-health cloud transmission to health care providers.
Result
Serial Monitor:
Lcd display:
Conclusion
Through this project our knowledge regarding iot and embedded systems and circuit designing. We learned about real world applications of microcontrollers and embedded systems. This system can be used for heartbeat monitoring and body temperature monitoring using arduino.
abstract
Heart Beat And Body Temperature Monitoring using Arduino will detect the heart beat using the Pulse Sensor and body temperature using LM-35 sensor.
Sensor and will show the readings in BPM (Beat Per Minute) on the LCD connected to it.The body Temperature will be displayed on serial monitor along with BPM readings.
With the development of technology, in this project we can digitally sensing body temperature and heart rate using arduino. Mainly arduino is used because it can sense the environment by receiving input from variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language. LM35 is used for the sense body temperature. Body temperature is a basic parameter for monitoring and diagnosing human health. Heart beat sensor was used for sensing heart rate. This device will allow one to measure their mean arterial pressure (MAP) in about one minute and the accurate body temperature will be displayed on the Android. The system can be used to measure physiological parameters, such as Heart rate (Systolic and Diastolic), Pulse rate.
Problem Statement
One of the increasing popular public concerns is human health. Anything else becomes meaningless if one gets sick or dead. For this reason, people spend a lot of money to keep sound health. Unfortunately, people always find that it is too late to receive serious medical care when things are non-invertible.
If early actions can be taken in time then lots of patients can be cured. However, access to many medical equipment is inconvenient and expensive. Heart rate and body temperature are the most vital ones among the most notable indexes of the human health, and they have the advantage of easy access. Moreover, unlike the X-ray, the measurement of heart rate and body temperature has no effect on human health itself.
There are some devices in the current market which can provide raw medical measurement data to patients and doctors, but the patients may not interpret the medical measurement into meaningful diagnosis since they have little medical background. On the other hand, if raw medical data is delivered to the doctor, it kills much time and may cause trouble, but in emergencies time can never be wasted. It is tough to share data over a large area within a short period. Most of the products available in the current market have these major drawbacks with limitation in flexibility and portability.
Introduction
Need of Monitoring:
More than 2 million people are at high risk of having heart attack.
It would be helpful if there was a way for these people to monitor their heart .So we have a problem.That is the way our project focuses on how we can overcome this problem and find a solution. Heart rate means the number of heartbeats per unit of time, usually expressed as beats per minute (bpm). Human’s heart pounds to pump oxygen-rich blood to muscles and to carry cell waste products away from tissues .
Heart rate can vary according to the demand of muscles to absorb oxygen and excrete carbon dioxide changes, such as during exercise or sleep . It also varies significantly between individuals based on fitness, age and genetics. That means heart must beat faster to deliver more oxygen-rich blood. During exercise routines, the heart rate gives a strong indication of how effective that routine is improving health. Normal heart rate of a resting person is about 70 bpm for adult males and 75 bpm for adult females. A heart rate monitor is simply a device that takes a sample of heartbeats and computes the beats per minute so that the information can easily track heart condition .
Medical professionals use heart rate for tracking of patient’s physical conditions. Individuals, such as athletes, who are interested in monitoring their heart rate to gain maximum efficiency from their training, also use it. Body temperature means measurement of the body’s ability to generate and get rid of heat. It is one of chief indicators of normal functioning and health. The nature of the human body is to keep its temperature within a narrow, safe range in spite of large variations in temperatures outside the body.
Literature Survey
Extensive research has been dedicated to the exploration of various technologies such as information technologies (IT) in complementing and strengthening existing healthcare services. In particular, the Internet of Things (IoT) has been widely applied to interconnect available medical resources and provide reliable, effective and smart healthcare service to the elderly and patients with a chronic illness. The aim of this project is to summarize the applications of IoT in the healthcare industry and identify the intelligentization trend and directions of future research in this field.
Based on a comprehensive literature review and the discussion of the achievements of the researchers, the advancement of IoT in healthcare systems have been examined from the perspectives of enabling technologies and methodologies, IoT-based smart devices and systems, and diverse applications of IoT in the healthcare industries. Finally, the challenges and prospects of the development of IoT based healthcare systems are discussed in detail.
Block Diagram
Block Diagram of heartbeat and body temperature monitoring
Hardware requirement
- Pulse Sensor
- LM-35 Sensor
- Arduino Uno
- 16 *2 LCD
- Bread Board
- 10k potentiometer
- Connecting wires
Arduino Board
Arduino is an open source platform used for building electronics projects
- Arduino consists of both a physical programmable circuit board (MICROCONTROLLER) and a piece of software (Integrated Development Environment) that runs on our computer, used to upload computer code to the physical board.
Pulse sensor
- Connect the Pulse Sensor with the Arduino. The Pulse sensor has three pins. Connect 5V and the ground pin of the pulse sensor to the 5V and the ground of the Arduino and the signal pin to the A0 of Arduin
LM-35 temperature sensor
The LM35 is one kind of commonly used temperature sensor that can be used to measure temperature with an electrical o/p comparative to the temperature (in °C). It can measure temperature more correctly compare with a thermistor. This sensor generates a high output voltage than thermocouples and may not need that the output voltage is amplified. The LM35 has an output voltage that is proportional to the Celsius temperature. The scale factor is .01V/°C.
LCD display
Liquid crystal display (LCD) screens are by far the most popular screens for electronics today. If you look around you, you’re likely to see at least one or two, possibly on your microwave or landline caller ID box.Your LCD has a total of 16 pins. Here’s what each pin is designed to do:Pins 1 and 16: These are your power and ground. Pin 3: Used to adjust the brightness of the LCD.Pins 4–6: Used to operate the LCD.Pins 7–14: Used as data lines.Pins 15–16: Used to power the LCD’s backlight.
Working
This is a prototype model for IoT based pulse rate monitor. It can be designed as a wearable watch or ear plug. In a wearable design, the character LCD could be removed and the entire circuit can be shifted to small controller board or SOC.
When the circuit is powered by the battery, the Arduino starts reading the pulse rate from the pulse sensor and the ambient temperature from the LM-35 temperature sensor. The pulse sensor has an infrared LED and a photo transistor which help detect pulse at the tip of the finger or earlobe. Whenever it detects pulse, its IR LED flashes. The flash of the IR LED is detected by the phototransistor and its resistance changes when the pulse is changed. The heartbeat of a normal adult ranges from 60 to 100 per minute. For detecting beats per minute (BPM), first an interrupt is set which triggers in every 2 Milliseconds. So, the sampling rate by the Arduino to detect pulse is 500 Hz. This sampling rate is sufficient to detect any pulse rate.
So, at every 2 Milliseconds, the Arduino reads analog voltage output from the pulse sensor. The analog output from the pulse sensor is converted to a digital value using in-built ADC channel. The Arduino has 10-bit long ADC channel, so the digitized value can range from 0 to 1024. The middle value for this range is 512. Initially, the first beat is set to true and the second beat is counted when the condition that analog output from the pulse sensor is greater than the middle point i.e. 512 is satisfied. Then, onwards, every next beat is counted when the analog output from the pulse sensor is greater than the middle point i.e. 512 and 3/5 of the time between the beats recorded in previous cycle has passed. Every time, the beat is detected, a variable representing BPM is updated. This value in this variable is pushed to an array in every minute and is used to represent the actual Beats Per Minute or Heart Rate. The Arduino code also uses a function to provide an LED fading effect on every beat.
The pulse sensor can also detect body temperature. The LM-35 is used to detect the body temperature here. The operating temperature range of LM-35 is from -55 °C to 150 °C. The output voltage varies by 10 mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01 V/ oC. The LM-35 IC does not require any external calibration or trimming to provide typical accuracies of ±0.25 °C at room temperature and ±0.75 °C over temperature range from −55 °C to 150 °C. Under normal conditions, the temperature measured by the sensor won’t exceed or recede the operational range of the sensor. Typically in the temperature range from −55 °C to 150 °C, the voltage output of the sensor increases by 10 mV per degree Celsius.
Code
#include <LiquidCrystal.h>
// Variables
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 8; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
const int sensor=A1; // Assigning analog pin A1 to variable ‘sensor’
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
LiquidCrystal lcd(13,12,6,5,4,3);// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Mustbe 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 = 250; // used to find peak in pulse wave, seeded
volatile int T = 250; // used to find trough in pulse wave, seeded
volatile int thresh = 250; // used to find instant moment of heart beat, seeded
volatile int amp = 50; // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = false; // used to seed rate array so we startup with reasonable BPM
void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
pinMode(sensor,INPUT); // Configuring pin A1 as input
Serial.begin(9600);
}
// Where the Magic Happens
void loop()
{
serialOutput();
if (QS == true) // A Heartbeat Was Found
{
// BPM and IBI have been Determined
// Quantified Self “QS” true when arduino finds a heartbeat
fadeRate = 255; // Makes the LED Fade Effect Happen, Set ‘fadeRate’ Variable to 255 to fade LED with pulse
serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
vout=analogRead(sensor);
vout=(vout*500)/1023;
tempc=vout; // Storing value in Degree Celsius
tempf=(vout*1.8)+32; // Converting to Fahrenheit
Serial.print(“in DegreeC=”);
Serial.print(“\t”);
Serial.print(tempc);
Serial.println();
Serial.print(“in Fahrenheit=”);
Serial.print(“\t”);
Serial.print(tempf);
Serial.println();
lcd.print(“temp in c:”);
lcd.print(tempc);
delay(2000); //Delay of 1 second for ease of viewing
}
ledFadeToBeat(); // Makes the LED Fade Effect Happen
delay(20); // take a break
}
void ledFadeToBeat()
{
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
void interruptSetup()
{
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON’T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}
void serialOutput()
{ // Decide How To Output Serial.
if (serialVisual == true)
{
arduinoSerialMonitorVisual(‘-’, Signal); // goes to function that makes Serial Monitor Visualizer
}
else{
sendDataToSerial(‘S’, Signal); // goes to sendDataToSerial function
}
}
void serialOutputWhenBeatHappens()
{
if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work
{
Serial.print(“*** Heart-Beat Happened *** “); //ASCII Art Madness
Serial.print(“BPM: “);
Serial.println(BPM);
lcd.clear();
lcd.print(“BPM: “);
lcd.print(BPM);}
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:
switch (range)
{case 0:
Serial.println(“”); /////ASCII Art Madnessbreak;
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;
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 )
{
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
} // keep track of highest point in pulse wave
// NOW IT’S TIME TO LOOK FOR THE HEART BEAT
// signal surges up in value every time there is a pulse
if (N > 250)
{ // avoid high frequency noise
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
{
Pulse = true; // set the Pulse flag when we think there is a pulse
digitalWrite(blinkPin,HIGH); // turn on pin 13 LED
IBI = sampleCounter — lastBeatTime; // measure time between beats in mS
lastBeatTime = sampleCounter; // keep track of time for next pulse
if(secondBeat)
{ // if this is the second beat, if secondBeat == TRUE
secondBeat = false; // clear secondBeat flag
for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup
{
rate[i] = IBI;
}
}
if(firstBeat) // if it’s the first time we found a beat, if firstBeat == TRUE
{
firstBeat = false; // clear firstBeat flagsecondBeat = true; // set the second beat flag
sei(); // enable interrupts again
return; // IBI value is unreliable so discard it
}
// keep a running total of the last 10 IBI values
word runningTotal = 0; // clear the runningTotal variable
for(int i=0; i<=8; i++)
{ // shift data in the rate array
rate[i] = rate[i+1]; // and drop the oldest IBI value
runningTotal += rate[i]; // add up the 9 oldest IBI values
}
rate[9] = IBI; // add the latest IBI to the rate array
runningTotal += rate[9]; // add the latest IBI to runningTotal
runningTotal /= 10; // average the last 10 IBI values
BPM = 60000/runningTotal; // how many beats can fit into a minute? that’s BPM!
QS = true; // set Quantified Self flag
// QS FLAG IS NOT CLEARED INSIDE THIS ISR
}
}
if (Signal < thresh && Pulse == true)
{ // when the values are going down, the beat is over
digitalWrite(blinkPin,LOW); // turn off pin 13 LED
Pulse = false; // reset the Pulse flag so we can do it again
amp = P — T; // get amplitude of the pulse wave
thresh = amp/2 + T; // set thresh at 50% of the amplitude
P = thresh; // reset these for next time
T = thresh;
}
if (N > 2500)
{ // if 2.5 seconds go by without a beat
thresh = 250; // set thresh default
P = 250; // set P default
T = 250; // 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
Applications
- Have become a widely used training aid for a variety of sports.
- Hospitals / Dispensaries
- Better and accurate method of measuring heartbeat.
- At homes
- A set point can help in determining whether a person is healthy or not checking
- his/her heartbeat and comparing with the set point.
Future Scope
- Monitoring device that could be used to detect the heart beat anomalies of physically challenged Individuals without hands.
- Also a graphical LCD can be used to display a graph of the change of heart rate over time.
- A serial output can be incorporated into the device so that the heart rates can be sent to a Personal Computer (PC) for further online or offline analysis.
- It could be integrated with mobile technology for e-health cloud transmission to health care providers.
Result
Serial Monitor:
Conclusion
Through this project our knowledge regarding IoT and embedded systems and circuit designing. We learned about real-world applications of microcontrollers and embedded systems. This system can be used for heartbeat monitoring and body temperature monitoring using Arduino.
i am currently pursuing BME i am planning to do this as a project now
ReplyDeletegood one!!
Deletekindly ask for any help we are ready to assist!
good one!!
ReplyDeletekindly ask for any help we are ready to assist!
very good device i really move to make it as my assessment i just wonder if we can remove the Breadboard and replace it with something smaller
ReplyDeleteI have tried to implement it in my project. But the code is not working, can you please help?
ReplyDeletehello can i get a combined heartbeat and temperature code please
ReplyDelete