6

I modified the serial code in this way and I don't think the gap is produced by my edit even because it made it even before:

//////////
/////////  All Serial Handling Code, 
/////////  It's Changeable with the 'serialVisual' variable
/////////  Set it to 'true' or 'false' when it's declared at start of code.  
/////////

void serialOutput(){   // Decide How To Output Serial. 
 if (serialVisual == true){  
     arduinoSerialMonitorVisual('-', Signal);   // goes to function that makes Serial Monitor Visualizer
 } else{
      sendDataToSerial('S', Signal);     // goes to sendDataToSerial function
 }        
}


//  Decides How To OutPut BPM and IBI Data
void serialOutputWhenBeatHappens(){    
 if (serialVisual == true){            //  Code to Make the Serial Monitor Visualizer Work
    //ASCII Art Madness
    Serial.print(BPM);
    Serial.println("");

 } else{
        sendDataToSerial('B',BPM);   // send heart rate with a 'B' prefix
        sendDataToSerial('Q',IBI);   // send time between beats with a 'Q' prefix
 }   
}



//  Sends Data to Pulse Sensor Processing App, Native Mac App, or Third-party Serial Readers. 
void sendDataToSerial(char symbol, int data ){
    Serial.print(symbol);

    Serial.println(data);                
  }


//  Code to Make the Serial Monitor Visualizer Work
void arduinoSerialMonitorVisual(char symbol, int data ){    
  const int sensorMin = 0;      // sensor minimum, discovered through experiment
const int sensorMax = 1024;    // sensor maximum, discovered through experiment

  int sensorReading = data;
  // map the sensor range to a range of 12 options:
  int range = map(sensorReading, sensorMin, sensorMax, 0, 11);

  // do something different depending on the 
  // range value:
  switch (range) {
  case 0:     
    Serial.println("");

  } 
}



63

63
63
63
63
62
62
62
62
62
62
62
63
62
63
64
63
63
64
64
65
65



65
68
74
78
86
95
105
112
123
141
167
154
136
128
123
125
123
127
132
104
93
92
92
89
83
77
73
69
65
70
70
71

You can find all the code here: https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino

In the code I posted there is some code I don'f find useful but I can't delete it for reason linked to variables used for other functions I don't know I'm using. You can also see huge changes in the heart rate that surely don't reflect the reality.

10
  • 1
    probably because of the badly formatted switch() case: statement. Have a look at what the Serial.println('"");
    – RSM
    Mar 29 '16 at 10:08
  • that's where I deleted things Mar 29 '16 at 10:36
  • ok I deleted the code there and now no problem. Any idea on how to fix the erroneous heart rates? Mar 29 '16 at 10:37
  • That might be something with the sensor and how it is connected, loose connections possibly.
    – RSM
    Mar 29 '16 at 10:48
  • 1
    Try using another serial terminal program (such as br@y terminal, Hterm, YAT etc.). In these programs you can control the timeout and also view line breaks.
    – sa_leinad
    Oct 27 '16 at 13:55
1

One of the possibilities is when you move your finger, the sensor grip loosened and doesn't count a "beat". So the sensor emits data = 0, and it will cause

Serial.println("");    

in your switch-case.

1
  • 1
    Upvote because this seems most likely. If changing code doesn't matter, and the wiring is intact, then it must be the movement that is causing it. Like the old joke: "Doctor, it hurts when I lift my arm" and the Doctor says, "Then don't lift your arm"
    – SDsolar
    Nov 11 '16 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.