Pulse Sensor and noise interference from LED strip

Hi there

am fairly new to Arduino... I'm using an Arduino Uno R3 and have a pulse sensor connected to an analog pin and a short (5 LED) RGB LED Strip connected to a digital pin.

The aim is to light the Led strip every 5 seconds with a different color depending on the current BPM as calculated from the pulse sensor. I got them working separately just fine but when I combined them into the same sketch/circuit the pulse sensor is affected by noise such that the BPM reading jumps by 30-50 beats.

The pulse sensor is using the Timer 1 ISR on a 1ms interrupt and both the sensor and LED Strip share the same power source. I have thought of using a separate power source for the LED Strip (not tried yet) but was hoping there might be another way to solve this.

Any ideas/advice much appreciated.

thanks, Caleb

It may help to show us the code you was trying and the whole circuit (driving a whole RGB LED strip from one digital pin is quite difficult), else it's too much guessing for me.

Hi pylon

thanks for the reply.

Here’s a link to the code that controls the LED strip: GitHub - pololu/pololu-led-strip-arduino: Arduino library for addressable RGB LED strips from Pololu

and to the sensor code A_PulseSensor_06: http://code.google.com/p/pulse-sensor/downloads/list

The LedStrip is connected to pin 12 on the Arduino and the sensor is connected to Analog pin 5. The interrupt handling
for the sensor is included in setup(), otherwise its all library code. The call to write the Led Strip (I’m only using 5 LEDs)
is done in the subroutine testLedStrip().

Here’s the relevant bits from my code:

void setup(void)
{

  // this next bit will wind up in the library. it initializes Timer1 to throw an interrupt every 1mS.
  TCCR1A = 0x00; // DISABLE OUTPUTS AND BREAK PWM ON DIGITAL PINS 9 & 10
  TCCR1B = 0x11; // GO INTO 'PHASE AND FREQUENCY CORRECT' MODE, NO PRESCALER
  TCCR1C = 0x00; // DON'T FORCE COMPARE
  TIMSK1 = 0x01; // ENABLE OVERFLOW INTERRUPT (TOIE1)
  ICR1 = 8000;   // TRIGGER TIMER INTERRUPT EVERY 1mS  
  sei();         // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

...
...
...

}


void loop(void)
{

...
...
...

  delay(5000);                              
  
  testLedStrip();                      // test strip
}



void testLedStrip()
{
  rgb_color clearLed = {0,0,0};               
  rgb_color greenLed = {0,0,100};             
  rgb_color colors[5];

  for(int x = 0; x < 3; x++)           // drive all Leds 3 times with short delay
  {
    for(int y = 0; y < 5; y++)         // set all Leds to Green
    { 
      colors[y] = greenLed; 
    }
    ledStrip.write(colors, 5);  
    delay(200);
    
    for(int y = 0; y < 5; y++)         // set all Leds to Clear
    {
      colors[y] = clearLed; 
    }
    ledStrip.write(colors, 5);  
    delay(200);
  }
}

I can paste the library code here too if needed.

thanks again, Caleb

The two code parts are not really compatible. The pulse sensor depends on a interrupt handler (a quite heavy one) doing almost the whole work. This must be called once a ms to let it work properly. The LED strip library sends the color values out using some assembler code. To get the timing more or less correct it disables interrupts during the complete transfer.

There is some code and a comment that gives me the impression that you should add the following code to your setup:

ledStrip.interruptFriendly = true;

Maybe that helps, otherwise you have to use either another LED strip or other code for your heart monitor.

Hi pylon

thanks for the quick reply.

I had tried that without success as the Led lighting went out of sync, sometimes leaving LEDs on.

I tried using a different power source for the LEDs and that fixed the problem but as mentioned earlier I'm hoping to get away with just one power source.

thanks again for your help, Caleb