Heartbeat sensor help

Hello i need a help for my project that uses the arduino uno with pulse sensor to get a heart beat rate for human and display it in LCD or Serial monitor , i used many methods and i tried many codes but no result

How have you connected that thing to the Arduino? What code do you have on the Arduino?

A link is far more useful than a picture.

Ism3lawy:
Hello i need a help for my project that uses the arduino uno with pulse sensor to get a heart beat rate for human and display it in LCD or Serial monitor , i used many methods and i tried many codes but no result

Which model of heartrate sensor?

5V operating voltage and analog output?

Or different?

PaulS:
How have you connected that thing to the Arduino? What code do you have on the Arduino?

A link is far more useful than a picture.

I used the code below and the connection that in the attached picture

volatile int rate[10];                    // used to get running average of HRV values
int pulsePin= A0;
volatile unsigned long lastBeatTime = 0;  // used to find the time between beats
volatile int sampleCounter;               // used to determine pulse timing
volatile int runningTotal;                // used to keep track of pulses
volatile boolean firstBeat = true;        // used to seed rate array so we startup with reasonable BPM
volatile boolean secondBeat = true;       // used to seed rate array so we startup with reasonable BPM


void interruptSetup(){

 // Initializes Timer1 to throw an interrupt every 1mS.
 TCCR1A = 0x00; // DISABLE OUTPUTS AND PWM ON DIGITAL PINS 9 & 10
 TCCR1B = 0x11; // GO INTO 'PHASE AND FREQUENCY CORRECT' MODE, NO PRESCALER
 TCCR1C = 0x00; // DON'T FORCE COMPARE
 TIMSK1 = 0x01; // ENABLE OVERFLOW INTERRUPT (TOIE1)
 ICR1 = 8000;   // TRIGGER TIMER INTERRUPT EVERY 1mS  
 sei();         // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

}


// THIS IS THE TIMER 1 INTERRUPT SERVICE ROUTINE. 
ISR(TIMER1_OVF_vect){ // triggered every time Timer 1 overflows
 // Timer 1 makes sure that we take a reading every milisecond
 Signal = analogRead(pulsePin);  // read the Pulse Sensor 
 sampleCounter++;                // keep track of the time with this variable (ISR triggered every 1mS

 //  NOW IT'S TIME TO LOOK FOR THE HEART BEAT
 int H = sampleCounter-lastBeatTime;      // monitor the time since the last beat to avoid noise
 if ( (Signal > 520) && (Pulse == false) && (H > 500) ){  
   // signal surges up in value every time there is a pulse    
   Pulse = true;                       // set the Pulse flag when we think there is a pulse
   digitalWrite(13,HIGH);              // turn on pin 13 LED
   HRV = sampleCounter - lastBeatTime; // measure time between beats in mS
   lastBeatTime = sampleCounter;       // keep track of time for next pulse
   if(firstBeat){                      // if it's the first time we found a beat
     firstBeat = false;                // clear firstBeat flag
     return;                           // HRV value is unreliable so discard it
   }   
   if(secondBeat){                     // if this is the second beat
     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] = HRV;                      
     }
   }                          
   // keep a running total of the last 10 HRV values
   for(int i=0; i<=8; i++){
     rate[i] = rate[i+1];          // shift data in the rate array and drop the oldest HRV value 
   }
 rate[9] = HRV;                    // add the latest HRV to the rate array
 runningTotal = 0;                 // clear the runningTotal variable
 for(int i=0; i<=9; i++){
   runningTotal += rate[i];        // add up the last 10 HRV values
 }  
 runningTotal /= 10;               // average the last 10 HRV values 
 BPM = 60000/runningTotal;         // how many beats can fit into a minute? that's BPM!
 QS = true;                        // set Quantified Self flag when beat is found and BPM gets updated. 
 // QS FLAG IS NOT CLEARED INSIDE THIS ISR
 }                       


 if (Signal < 500 && Pulse == true){   // when the values are going down, it's the time between beats
   digitalWrite(13,LOW);               // turn off pin 13 LED
Serial.println("beat rate is: ");
Serial.print(BPM);
   Pulse = false;                      // reset the Pulse flag so we can do it again!
 }
 
}

cablehookup.png

jurs:
Which model of heartrate sensor?

5V operating voltage and analog output?

Or different?

yes i used the model which operate at 5V and output is analog i connected the sensor at pin A0 i uploaded the code above

You can't do serial output in an ISR. Get that crap out of there. Print the heart rate in loop(), when the ISR sets the flag that says that there is a heart rate known.

Posting code that actually compiles is a good idea, unless the problem you are having is that the code doesn't compile. If that is the case, complaining that the code doesn't produce useful output is stupid.

Maybe I will leave it to someone else to explain why noobs and interrupts are such a bad combination. :roll_eyes:

Ism3lawy:
yes i used the model which operate at 5V and output is analog i connected the sensor at pin A0 the i code i uploaded it above

Did you check the raw sensor output values?
Can you confirm that the sensor takes up a heartbeat signal?
Is it a good signal, fluctuating up and down in the rhythm of a heartbeat?

Here is a short sketch to provide raw values and latest changes to Serial:

const byte samplePin= A0;
const int sampleInterval=5000; // microseconds
unsigned long lastSampleTime;
int lastSample;
void setup() {
  Serial.begin(115200); // set serial monitor to 115200 baud
}

void loop() {
  if (micros()-lastSampleTime>=sampleInterval)
  {
    lastSampleTime+=sampleInterval;
    int sample= analogRead(samplePin);
    Serial.print(lastSampleTime/1000000.0,3);
    Serial.print('\t');
    Serial.print(sample);
    Serial.print('\t');
    Serial.println(sample-lastSample); // change since last sample was taken
    
    lastSample=sample;
  }
}

Perhaps send some seconds of Serial output without signal (sensor attached to Arduino, no heartbeat signal present).
And also some seconds of Serial output with a valid signal (sensor attached to Arduino, with heatbeat signal present)

Heartbeat detection can only work with a good signal from the sensor.

Hi my name is Steve, I have spent a number of hours with the heartbeat sensor circuit, trying several different circuits and several different sensor combinations.Before even connecting the Arduino I wanted to see if this circuit would show a voltage change that was reflective of a heart peat pulse.What I found after several tries is that the infrared led must be aimed at a 45 degree angle with the lens of the photo-transistor with the finger tip being the vertex, in other words the infrared light must be reflected off of the finger into the lens of the photo-transistor. I found it to be very difficult to get a signal and that your finger has to be positioned just right. Eventually after holding my finger just right I was able to see a semblence of a heart beat on my scope. The scope, by the way should be set at a very slow sweep, in other words dont start out with a flat line on the scope, get the scope to show one point sweep across the screen. Once I got the heart beat to show on my scope I was ready to attach the Arduino. One trick to see if your led is transmitting light is to view the led with your cell phone camera, as it is capable of picking up infrared light,(which appears blue),and the eye cannot see this light. my email is beatlessteve@gmail.com if you have any questions, Ill be more than happy to help!