arduino programming for heart rate analysing

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.

If you want the code written for you can I suggest that you ask this in the Gigs and Collaborations section of the forum,26.0.html unless you already have some code that you need help with.

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

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 ?

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);

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
{ increment();
{ counter();

void increment()
{Serial.print("Sensor value is greater than .75V\n");
void counter()
{ count=count*6;
Serial.print("Heart beat is ");
Serial.print(" per min\n");

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

Try something like this (untested)

long measurementStartTime = 0;
int beats = 0;
byte sensorPin = A0;
int currentSensorValue;
boolean counted = false;

void setup() 
  pinMode(sensorPin, INPUT);

void loop() 
  if ((millis() - measurementStartTime > 10000) && (beats > 0))  //time is up
    Serial.print("Beats read in 6 seconds : ");
    measurementStartTime = millis();
    beats = 0;
  currentSensorValue = analogRead(sensorPin);
  if (currentSensorValue > 156 && counted == false)
    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.

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

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 ?

we used a piezoelectric accelerometer to sense the signal from 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.

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 ?

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

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

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