user34459: I am working on a Heart Rate Monitoring project, using this Sensor from sparkFun, plugged to Arduino pro mini and reading proper BPM, I have an LED connected to pin 13 of my Arduino that blinks when the pulse happen.
The code given on SparkFun page works on Timer2
I have two more LEDs connected to pin12 and pin11, which indicates battery percentage - because i am powering my Arduino using a 2 cell lithium ion battery with Voltage regulator.. I also have a voltage divider circuit at the voltage regulator with 1K resistors and connected to analog pin A0 for monitoring battery voltage.
I have assigned LED connected on pin 13 as LED1, on 12 as LED2 and 11 as LED3
LED1 for low charge
LED2 for half charge
LED3 for full charge
Here is the problem : 
When i connect charger ,Arduino reads data from voltage divider and outputs levels to LEDS
Here - LED1 is conflicting between the pulse sensor (which is working on Timer2) and also for indicating the low level charging, and LED1 is flickering.
how to overcome with this issue.? disabling Timer2 helps.? if'Yes' then how to do that.?
Note : I don't want to sample Heart Rate Pulse when charger is connected!
Thank you very much.
Best
void charging() {
TCCR2A = 0;
usbState = digitalRead(usb_detect);
while (usbState == HIGH) {
usbState = digitalRead(usb_detect);
// read the input on analog pin 0:
int sensorValue = analogRead(A1);
// Convert the analog reading (which goes from 0 - 512) to a voltage (0 
- 3.3V):
float voltage = sensorValue * (3.3 / 512.0);
// print out the value you read:
if (voltage >= 2.5 && voltage <= 3.3)
{

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(gps_led, ledState);
    digitalWrite(blinkPin, LOW);
    digitalWrite(save_led, LOW);
  }
}

if (voltage >= 3.4 && voltage <= 3.7)
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }


    // set the LED with the ledState of the variable:
    digitalWrite(blinkPin, ledState);
    digitalWrite(gps_led, HIGH);
    digitalWrite(save_led, LOW);
  }
}

if (voltage >= 3.8 && voltage <= 4.1)
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(save_led, ledState);
    digitalWrite(blinkPin, HIGH);
    digitalWrite(gps_led, HIGH);
  }

}

Serial.println(voltage);

delay(1);        // delay in between reads for stability

}
}


user4143: Timer 2 is fundamental to that code. It is used to sample the heart rate sensor at a regular period. If you disable that timer you will never sample the sensor.
You cannot have two functions on one LED - it makes no sense. You should decide on one and only one function to use that LED for. If you want to use it for the battery status then remove the code from the timer interrupt that controls the LED. If you want to use it to display the hear beat then you will have to make do with just two LEDs for your battery status. 
If the two operations are mutually exclusive then yes you can disable the timer. Just turn it off, then turn it on again when you want sampling to start again.
Off:
TCCR2B = 0;

On (assuming you are using this
code):
TCCR2B = 0x06;


user359: in the linked repo in the product page you linked there is a explanation page how to use the device without using timers buried at the bottom of a file:
https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/PulseSensorAmped_Arduino_1.5.0/Timer_Interrupt_Notes.ino#L217
In essence instead of using the timer interrupt you put the sampling code in the loop() body triggered by a software timer and make sure that there are no delay() or busy loops happening in it.

34459: <p>I am working on a Heart Rate Monitoring project, using this <a href="https://www.sparkfun.com/products/11574" rel="nofollow noreferrer">Sensor</a> from sparkFun, plugged to Arduino pro mini and reading proper BPM, I have an LED connected to pin 13 of my Arduino that blinks when the pulse happen.
The code given on SparkFun page works on Timer2</p>

<p>I have two more LEDs connected to pin12 and pin11, which indicates battery percentage - because i am powering my Arduino using a 2 cell lithium ion battery with Voltage regulator.. I also have a voltage divider circuit at the voltage regulator with 1K resistors and connected to analog pin A0 for monitoring battery voltage.</p>

<p>I have assigned LED connected on pin 13 as LED1, on 12 as LED2 and 11 as LED3</p>

<p>LED1 for low charge
LED2 for half charge
LED3 for full charge</p>

<p>Here is the problem : </p>

<p>When i connect charger ,Arduino reads data from voltage divider and outputs levels to LEDS</p>

<p>Here - LED1 is conflicting between the pulse sensor (which is working on Timer2) and also for indicating the low level charging, and LED1 is flickering.</p>

<p>how to overcome with this issue.? disabling Timer2 helps.? if'Yes' then how to do that.?</p>

<p>Note : I don't want to sample Heart Rate Pulse when charger is connected!</p>

<p>Thank you very much.</p>

<p>Best</p>

<pre><code>void charging() {
TCCR2A = 0;
usbState = digitalRead(usb_detect);
while (usbState == HIGH) {
usbState = digitalRead(usb_detect);
// read the input on analog pin 0:
int sensorValue = analogRead(A1);
// Convert the analog reading (which goes from 0 - 512) to a voltage (0 
- 3.3V):
float voltage = sensorValue * (3.3 / 512.0);
// print out the value you read:
if (voltage &gt;= 2.5 &amp;&amp; voltage &lt;= 3.3)
{

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis &gt;= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
    digitalWrite(gps_led, ledState);
    digitalWrite(blinkPin, LOW);
    digitalWrite(save_led, LOW);
  }
}

if (voltage &gt;= 3.4 &amp;&amp; voltage &lt;= 3.7)
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis &gt;= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }


    // set the LED with the ledState of the variable:
    digitalWrite(blinkPin, ledState);
    digitalWrite(gps_led, HIGH);
    digitalWrite(save_led, LOW);
  }
}

if (voltage &gt;= 3.8 &amp;&amp; voltage &lt;= 4.1)
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis &gt;= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(save_led, ledState);
    digitalWrite(blinkPin, HIGH);
    digitalWrite(gps_led, HIGH);
  }

}

Serial.println(voltage);

delay(1);        // delay in between reads for stability

}
}
</code></pre>
 4143: <p>Timer 2 is fundamental to that code. It is used to sample the heart rate sensor at a regular period. If you disable that timer you will never sample the sensor.</p>

<p>You cannot have two functions on one LED - it makes no sense. You should decide on one and only one function to use that LED for. If you want to use it for the battery status then remove the code from the timer interrupt that controls the LED. If you want to use it to display the hear beat then you will have to make do with just two LEDs for your battery status. </p>

<p>If the two operations are mutually exclusive then yes you can disable the timer. Just turn it off, then turn it on again when you want sampling to start again.</p>

<p>Off:</p>

<pre><code>TCCR2B = 0;
</code></pre>

<p>On (assuming you are using <a href="https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/PulseSensorAmped_Arduino_1.5.0/Interrupt.ino" rel="nofollow noreferrer">this
code</a>):</p>

<pre><code>TCCR2B = 0x06;
</code></pre>
 359: <p>in the linked repo in the product page you linked there is a explanation page how to use the device without using timers buried at the bottom of a file:</p>

<p><a href="https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/PulseSensorAmped_Arduino_1.5.0/Timer_Interrupt_Notes.ino#L217" rel="nofollow noreferrer">https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino/blob/master/PulseSensorAmped_Arduino_1.5.0/Timer_Interrupt_Notes.ino#L217</a></p>

<p>In essence instead of using the timer interrupt you put the sampling code in the <code>loop()</code> body triggered by a software timer and make sure that there are no <code>delay()</code> or busy loops happening in it.</p>
