Go Down

Topic: arduino programming for heart rate analysing (Read 3581 times) previous topic - next topic

febihailyharshi

I am doing a project on heart rate analyzer ,in which i use arduino to count the pulses obtained from a comparator, which corresponds to heartbeat.output of the comparator is obtained as a pulses which is obtained in  a frequency range of 1.2 to 1.7 Hz. I need an appropriate program for counting these pulses to obtain heartbeat for a minute.(which is supposed to be in a range of 60 to 80 counts in normal case). can somebody help me with a suitable program.

UKHeliBob

If you want the code written for you can I suggest that you ask this in the Gigs and Collaborations section of the forum http://arduino.cc/forum/index.php/board,26.0.html unless you already have some code that you need help with.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

febihailyharshi

i need a simple code for counting when the output changes state from 1 to 0 or from 0 to 1. i made a program myself,but it is giving me counts above 1000 , 2000 etc.. which implies that there is an error.can u give me a simple code for counting that change of state.i need this counting to stop after 60seconds

UKHeliBob

Post the code that you gave written so we can see what you have tried and offer advice on how to fix it.
How are the pulses being read ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

febihailyharshi

this is my code to count the number of pulses for 10 sec and then multiplying it by 6 to get the beat count

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int count=0;
unsigned long time1=0;  // store the initial time
unsigned long time2;    // store the current time
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(sensorPin, INPUT); 
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  if(count==0)
  {time1=millis();
  }
  time2=millis();
  sensorValue = analogRead(sensorPin);   
  if(sensorValue>156)
  { increment();
  }
  if(time2>=time1+10000)
  { counter();
  }
 
}
void increment()
{count++;
while(sensorValue>156)
{Serial.print("Sensor value is greater than .75V\n");
}
}
void counter()
{ count=count*6;
  Serial.print("Heart beat is ");
  Serial.print(count);
  Serial.print(" per min\n");
  time1=0;
  time2=0;
  count=0;
}

UKHeliBob

Your counts are so high because you continue to add to the counts whilst the sensor value remains high.

Try something like this (untested)
Code: [Select]
long measurementStartTime = 0;
int beats = 0;
byte sensorPin = A0;
int currentSensorValue;
boolean counted = false;

void setup()
{
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
}

void loop()
{
  if ((millis() - measurementStartTime > 10000) && (beats > 0))  //time is up
  {
    Serial.print("Beats read in 6 seconds : ");
    Serial.println(beats);
    measurementStartTime = millis();
    beats = 0;
  }
  currentSensorValue = analogRead(sensorPin);
  if (currentSensorValue > 156 && counted == false)
  {
    beats++;
    counted = true; 
  }
  else if (currentSensorValue < 146)
  {
    counted = false;
  }
}


NOTE - the tests deliberately do not use the same value to allow some tolerance as the signal changes from high to low and vice versa but may need adjusting.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

febihailyharshi

we used your code but still we got the output to the statement "beats read in 6 sec=" in the range of 700 and 800

UKHeliBob

#7
Mar 24, 2013, 03:34 pm Last Edit: Mar 24, 2013, 03:38 pm by UKHeliBob Reason: 1
How did you arrive at the value of 156 used in your original code ?
How is the sensor wired ?
How are the heartbeats turned into a value that the sensor can read ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

febihailyharshi

we used a piezoelectric accelerometer to sense the signal from wrist.it was then amplified and fed to a filter to filter noise, and it was given to a comparator which converted the peak pulse corresponding to beats into square pulses of frequency 1.2 to 1.7 hz.. this slight  variation is because of noise in between i suppose. we get a peak amplitude of nearly 5V. our purpose is to use arduino as a counter and display the number of pulses arriving in 60 secs.

UKHeliBob

Do you get one 5V peak per heartbeat ?

I don't understand your comment about the variation in frequency being due to noise.  You would surely expect the frequency of heartbeats to vary wouldn't you ?  How have you measured the range of frequencies ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

febihailyharshi

its not supposed to vary much for a person.. it may vary from person to person i beliv.. any way the variation is in the range of 1hz to 2hz... i get 4.8v amplitude for the pulses

UKHeliBob

Quote
the variation is in the range of 1hz to 2hz

If this is for one person during a monitoring session then I suggest that they see a doctor immediately or you review how you are deriving the waveform for analysis.  With that much variation in frequency any results are going to be meaningless
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

mistergreen

#12
Mar 25, 2013, 05:54 pm Last Edit: Mar 25, 2013, 06:34 pm by mistergreen Reason: 1
Choose to save data on the highest peaks only. You're probably getting other incidental pulses.

Maybe if you get a better sensor for the job too
https://www.sparkfun.com/products/8661


more
https://www.sparkfun.com/products/11574

Go Up