Go Down

Topic: Pulse sensor Amped (Read 4 times) previous topic - next topic

Grumpy_Mike

Quote
So what do u suggest me to do to make it working as it is

Use the standard software how to use and learn how to use the hardware. Play about with it, try and get it to read your pulse. Relax and be still and you will see it start to work.
Something like this is not as robust as you might like it.

cute-98


Use the standard software how to use


Standard software, do you mean just the basic coding using the Arduino interface without the processing?
if that the case, I have tried using the following code:

Code: [Select]

unsigned char pin = 13;
  unsigned char counter=0;
  unsigned int heart_rate=0;
  unsigned long temp[21];
  unsigned long sub=0;
  volatile unsigned char state = LOW;
  bool data_effect=true;
  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()
  {
      pinMode(pin, OUTPUT);
      Serial.begin(9600);
      Serial.println("Please ready your eat clip.");
      delay(5000);
      array_init();
      Serial.println("Heart rate test begin.");
      attachInterrupt(1, interrupt, RISING);//set interrupt 0,digital port 2
  }
 
  void loop()
  {
      digitalWrite(pin, state);
  }
 
  void sum()//calculate the heart rate
  {
      if(data_effect)
      {
        heart_rate=120000/(temp[20]-temp[0]);//6*20*1000/20_total_time
        Serial.print("Heart_rate_is:\t");
        Serial.println(heart_rate);
      }
      data_effect=1;//sign bit
  }
 
  void interrupt()
  {
    temp[counter]=millis();
    state = !state;
    Serial.println(counter,DEC);
    Serial.println(temp[counter]);
    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;
        Serial.println("Heart rate measure error,test will restart!" );
        array_init();
     }
    if (counter==20&&data_effect)
      {
        counter=0;
        sum();
      }
    else if(counter!=20&&data_effect)
      counter++;
    else
    {
      counter=0;
      data_effect=1;
    }
  }
 
  void array_init()
  {
      for(unsigned char i=0;i!=20;++i)
      {
        temp[i]=0;
      }
      temp[20]=millis();
  }


It's true that I started to panic since my deadline is coming close, and I just get fix with xbee and temperature sensor and now the pulse sensor is just not working though I have follow the tutorial for almost 5 times. I find people posting same problem in the pulsesensor forum itself but no one get a reply for it.

Grumpy_Mike

Do not use print statements in interrupt service routines.

cute-98


Do not use print statements in interrupt service routines.


Can i know why?

JimboZA



Do not use print statements in interrupt service routines.


Can i know why?


The Sparkfun tutorial on interrupts says:

Quote
Be aware though that it is important to keep the interrupt handler as short as possible because it prevents the processor from running its normal code, prevents other interrupts of lower priority, and could be called quite often depending what input you have connected. It's best to just update status variables and then leave, and let your normal program do the rest of the necessary work.


I'd guess that's why....
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Go Up