Sunday 29 January 2017

ATMEGA328P BASED HEART BEAT MONITOR PROJECT

ATMEGA328P BASED HEART BEAT PROJECT 

PROJECT DESCRIPTION:

Heart rate, body temperature and blood pressure monitoring are very important parameters of human body. Doctors use various kind of medical apparatus like thermometer for checking fever or body temperature, BP monitor for blood pressure measurement and heart rate monitor for heart rate measurement. 

 Here we have used a heartbeat sensor module which senses the heartbeat by the pulse in ear, Heart rate ear clip kit contain a ear clip and a receiver module. The heart rate measure kit can be used to monitor heart rate of patient and athlete. The result can be displayed on a screen via the serial port and can be saved for analysis. The entire system has a high sensitivity, low power consumption and is very portable.

This simple project will allow you to visualize your heart rate result  through a  Bluetooth connection with an  android moblie phone using hc-06  Bluetooth module

COMPONENT:

  1. Atmega328p
  2. Heart rate ear clip
  3. LCD 16X 2
  4. Bluetooth module
 
 
Here is the code:

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(5,6,7,8,9,10);

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial Genotronex(12, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

#define LED 4 //indicator, Grove - LED is connected with D4 of Arduino
boolean led_state = LOW;//state of LED, each time an external interrupt
                //will change the state of LED
unsigned char counter;
unsigned long temp[21];
unsigned long sub;
bool data_effect=true;
unsigned int heart_rate;//the measurement result of heart rate

const int max_heartpluse_duty = 2000;//you can change it follow your system's request.
            //2000 meams 2 seconds. System return error
            //if the duty overtrip 2 second.
void setup()
{
    Genotronex.begin(9600);
  Genotronex.println(" HEART RATE MONITORING PROJECT ");
  delay (500);
  Genotronex.println(" BLUETOOTH DEVICE CONNECTED... "); 
  pinMode(ledpin,OUTPUT);
 delay (1000); // delay for lcd to boot up
    // initialize LCD and set up the number of columns and rows:
  lcd.begin(16, 2);
  delay (1000);
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   HEART RATE   ");
  lcd.setCursor(0,1);
  lcd.print("    MONITOR     ");
  delay (2500);
   Genotronex.println(" HEART RATE MONITORING PROJECT ");

  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  arrayInit();
    lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   HEART RATE   ");
  lcd.setCursor(0,1);
  lcd.print(" TEST BEGIN.... ");
 
   Genotronex.println(" SCANNING PULSE BEGIN..... ");

  delay (2500);
  attachInterrupt(0, interrupt, RISING);//set interrupt 0,digital port 2



}
void loop()
{
  digitalWrite(LED, led_state);//Update the state of the indicator
}
/*Function: calculate the heart rate*/
void sum()
{
 if(data_effect)
    {
      heart_rate=1200000/(temp[20]-temp[0]);//60*20*1000/20_total_time
          lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Heartrate_is: ");
    lcd.print(heart_rate);
   Genotronex.println(" YOUR HEART_RATE IS: ");
   Genotronex.println(heart_rate);

   delay (1000);
    }
   data_effect=1;//sign bit
}
/*Function: Interrupt service routine.Get the sigal from the external interrupt*/
void interrupt()
{
    temp[counter]=millis();
  Serial.println(counter,DEC);    Serial.println(temp[counter]);
    digitalWrite(13, HIGH);
        lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" SCANNING ......");
      lcd.setCursor(0,1);
    lcd.print("Heartrate_is: ");
    lcd.print(heart_rate);
  delay (50);
 digitalWrite(13, LOW );
    switch(counter)
  {

   case 0:
      sub=temp[counter]-temp[20];
      Serial.println(sub);
      break;
    default:
      sub=temp[counter]-temp[counter-1];
      Serial.println(sub);
      break;
  }
    if(sub>max_heartpluse_duty)//set 2 seconds as max heart pluse duty
  {
    data_effect=0;//sign bit
    counter=0;
       Genotronex.println(" HEART BEAT SENSOR IS NOT WELL CONNECTED.. ");
    lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("   HEART RATE   ");
  lcd.setCursor(0,1);
  lcd.print("  READS  ERROR  ");
  delay (2500);
arrayInit();
  }
    if (counter==20&&data_effect)
    {
    counter=0;
    sum();
    }
    else if(counter!=20&&data_effect)
    counter++;
    else
    {
    counter=0;
    data_effect=1;
    }
   
}
/*Function: Initialization for the array(temp)*/
void arrayInit()
{
  for(unsigned char i=0;i < 20;i ++)
  {
    temp[i]=0;
  }
  temp[20]=millis();
}
 
You can contact engrable.ea@gmail.com for the circuit diagram and other details about the heart beat monitor system