Pages: [1]   Go Down
Author Topic: arduino programming for heart rate analysing  (Read 3049 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
}
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
 
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
« Last Edit: March 24, 2013, 09:38:03 am by UKHeliBob » Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4267
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 25, 2013, 12:34:20 pm by mistergreen » Logged

Pages: [1]   Go Up
Jump to: