Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
4 deleted 660 characters in body
source | link

I have found a code, it that can blink an LED on Arduino according to Heart Beat,. I am using AD8232 as a sensor for Heart Rate..

//  Variables
int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board ArduionArduino LED

 
int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore. 


// The SetUp Function:
void setup() {
  pinMode(LED13, OUTPUT);         // pin that will blink to your heartbeat!
   Serial.begin(9600);         // Set'sSets up Serial Communication at certain speed. 

}

// The Main Loop Function
void loop() {
 
  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value. 
                                              // Assign this value to the "Signal" variable.
 
   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.

 
   if(Signal > Threshold){                      {
    // If the signal is above "550", then "turn-on" Arduino's on-Board LED.  
     digitalWrite(LED13, HIGH);          
   } else {
     digitalWrite(LED13, LOW);                //  Else, the sigalsignal must be below "550", so "turn-off" this LED.
   }

 
  delay(10);

 
}

My question is  : How can iI get BPM?

Is this code for BPM is correct.?

int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;
     
#define UpperThreshold 518
#define LowerThreshold 490
     
int LED13 = 44;   //  The on-board ArduionArduino LED

 
int Signal;                // holds the incoming raw data. Signal value can range from 0-1024

 

void setup() {
 
  pinMode(LED13, OUTPUT);
 
  Serial.begin(9600);
}
 

void loop()
  {

 
  int value = analogRead(0);

 
  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
    // display bpm
 
  Serial.print(BPM);
  Serial.println(" BPM");
 
  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.
 
  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                     
    // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigalsignal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}

I have found a code, it can blink an LED on Arduino according to Heart Beat, I am using AD8232 as a sensor for Heart Rate..

//  Variables
int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board Arduion LED

 
int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore. 


// The SetUp Function:
void setup() {
  pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat!
   Serial.begin(9600);         // Set's up Serial Communication at certain speed. 

}

// The Main Loop Function
void loop() {
 
  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value. 
                                              // Assign this value to the "Signal" variable.
 
   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.

 
   if(Signal > Threshold){                          // If the signal is above "550", then "turn-on" Arduino's on-Board LED.  
     digitalWrite(LED13,HIGH);          
   } else {
     digitalWrite(LED13,LOW);                //  Else, the sigal must be below "550", so "turn-off" this LED.
   }

 
delay(10);

 
}

My question is  : How can i get BPM?

Is this code for BPM is correct.?

int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;
 
#define UpperThreshold 518
#define LowerThreshold 490
 
int LED13 = 44;   //  The on-board Arduion LED

 
int Signal;                // holds the incoming raw data. Signal value can range from 0-1024

 

void setup() {
 
  pinMode(LED13, OUTPUT);
 
  Serial.begin(9600);
}
 

void loop()
 {

 
  int value = analogRead(0);

 
  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm
 
  Serial.print(BPM);
  Serial.println(" BPM");
 
  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.
 
  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}

I have found code that can blink an LED on Arduino according to Heart Beat. I am using AD8232 as a sensor for Heart Rate.

//  Variables
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13; // The on-board Arduino LED
int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550; // Determine which Signal to "count as a beat", and which to ingore.

void setup() {
  pinMode(LED13, OUTPUT); // pin that will blink to your heartbeat
  Serial.begin(9600); // Sets up Serial Communication at certain speed.
}

void loop() {
  Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.
  Serial.println(Signal); // Send the Signal value to Serial Plotter.
  if(Signal > Threshold) {
    // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW); //  Else, the signal must be below "550", so "turn-off" this LED.
  }
  delay(10);
}

My question is: How can I get BPM?

Is this code for BPM correct?

int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;    
#define UpperThreshold 518
#define LowerThreshold 490    
int LED13 = 44; // The on-board Arduino LED
int Signal; // holds the incoming raw data. Signal value can range from 0-1024

void setup() {
  pinMode(LED13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int value = analogRead(0);
  if (value > UpperThreshold) {
    if (BeatComplete) {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false) {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
    // display bpm
  Serial.print(BPM);
  Serial.println(" BPM");
  x++;
  Signal = analogRead(0); // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.
  if (Signal > UpperThreshold) { 
    // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW); //  Else, the signal must be below "550", so "turn-off" this LED.
  }
}
3 deleted 71 characters in body
source | link
int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;

#define UpperThreshold 518
#define LowerThreshold 490

int LED13 = 44;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024



void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED13, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(9600);
}


void loop()
{


  int value = analogRead(0);


  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm

  Serial.print(BPM);
  Serial.println(" BPM");

  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.

  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}
int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;

#define UpperThreshold 518
#define LowerThreshold 490

int LED13 = 44;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024



void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED13, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(9600);
}


void loop()
{


  int value = analogRead(0);


  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm

  Serial.print(BPM);
  Serial.println(" BPM");

  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.

  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}
int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;

#define UpperThreshold 518
#define LowerThreshold 490

int LED13 = 44;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024



void setup() {

  pinMode(LED13, OUTPUT);

  Serial.begin(9600);
}


void loop()
{


  int value = analogRead(0);


  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm

  Serial.print(BPM);
  Serial.println(" BPM");

  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.

  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}
2 found other code which counts BPM and merged with the first one
source | link

Edited below :

Is this code for BPM is correct.?

int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;

#define UpperThreshold 518
#define LowerThreshold 490

int LED13 = 44;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024



void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED13, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(9600);
}


void loop()
{


  int value = analogRead(0);


  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm

  Serial.print(BPM);
  Serial.println(" BPM");

  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.

  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}

Edited below :

Is this code for BPM is correct.?

int x = 0;
int LastTime = 0;
bool BPMTiming = false;
bool BeatComplete = false;
int BPM = 0;

#define UpperThreshold 518
#define LowerThreshold 490

int LED13 = 44;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024



void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED13, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.begin(9600);
}


void loop()
{


  int value = analogRead(0);


  if (value > UpperThreshold)
  {
    if (BeatComplete)
    {
      BPM = millis() - LastTime;
      BPM = int(60 / (float(BPM) / 1000));
      BPMTiming = false;
      BeatComplete = false;
    }
    if (BPMTiming == false)
    {
      LastTime = millis();
      BPMTiming = true;
    }
  }
  if ((value < LowerThreshold) & (BPMTiming))
    BeatComplete = true;
  // display bpm

  Serial.print(BPM);
  Serial.println(" BPM");

  x++;
  Signal = analogRead(0);  // Read the PulseSensor's value.
  // Assign this value to the "Signal" variable.

  //Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


  if (Signal > UpperThreshold) {                        // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
    digitalWrite(LED13, HIGH);
  } else {
    digitalWrite(LED13, LOW);               //  Else, the sigal must be below "550", so "turn-off" this LED.
  }


  //delay(10);



}
1
source | link