heart Sensor rate with Andruino to android Phone not working


please can correct code me, want heart beat bpm android app, below code have tried far.

int threshold = 60;
int oldvalue = 0;
int newvalue = 0;
unsigned long oldmillis = 0;
unsigned long newmillis = 0;
int cnt = 0;
int timings[16];
void setup() {
  serial.begin(57600);

}

void loop() {
  if(serial.available()>0){
    char re = serial.read();
    switch(re){
     case 'e':
    start();
    break;
  }
 
  }
}


void start(){
 while(1){
 oldvalue = newvalue;
  newvalue = 0;
  for(int i=0; i<64; i++){ // average on 16 measurements
  serial.print('s');
  serial.print(floatmap(analogread(a2)));
    newvalue += analogread(a2);//am not sure this
  }

  delay(20);
  }


 
  if(serial.available()>0){
    if (serial.read()=='q') return;
  }
 }

 int floatmap(int newvalue){
    oldvalue = newvalue;
    newvalue = newvalue/64;
  // find triggering edge
  if(oldvalue<threshold && newvalue>=threshold){
    oldmillis = newmillis;
    newmillis = millis();
    // fill in current time difference in ringbuffer
    timings[cnt%16]= (int)(newmillis-oldmillis);
    int totalmillis = 0;
    // calculate average of last 16 time differences
    for(int i=0;i<16;i++){
      totalmillis += timings;
    }
    // calculate heart rate
    int heartrate = 60000/(totalmillis/16);
     cnt++;
}
 return heartrate;
 }[/left]



Arduino Forum > Topics > Home Automation and Networked Objects > heart Sensor rate with Andruino to android Phone not working


arduino

Comments

Popular posts from this blog

Help with codes to add 1 more shift register and add more to matrix LED

tcp client

Is there an HTML component in Flex 2.0?