LED pulses when it should stay solid on

Hello! I have project that turns on 15 LED's one at a time. I can adjust a pot to make the LED's light up faster or slower. All of that works fine.

I realized that I forgot to add a static LED that needs to be on all of the time. I added the appropriate lines of code and the LED is indeed on all of the time. However, it pulses in time with the other LED's. How do I make it stay on and not pulse?

const byte LEDpin[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, A0, A1, A2, A3,};
const byte numberOfLED = sizeof ( LEDpin ) / sizeof ( LEDpin[0] );
const byte StaticLight = A4;

unsigned long timeNow = 0;
unsigned long timePrev = 0;
const unsigned long regularInterval = 300;
const unsigned long pause = 1000;
unsigned long interval = regularInterval;

byte counter = 0;

int speed_adj = A5; //Pot
int val = 0; //value that stores the resistance set by the Pot


void setup() 
{
pinMode(StaticLight, OUTPUT); 
for ( byte i = 0; i < numberOfLED; i++ )
  {
    pinMode (LEDpin[i] , OUTPUT);
    digitalWrite ( LEDpin[i], LOW);
  }
  timePrev = millis();
}

void loop()
{
  digitalWrite(StaticLight, HIGH);
  val = analogRead(speed_adj);
  
  timeNow = millis();
  if ( timeNow - timePrev >= val )
  {
    timePrev = timeNow;
    if ( counter < numberOfLED )
    {
      digitalWrite ( LEDpin[counter], HIGH);
    }
    counter++;
    if ( counter == numberOfLED ) val = pause;
    else val = regularInterval;
    if ( counter > numberOfLED )
    {
      counter = 0;
      for ( byte i = 0; i < numberOfLED; i++ )
      {
        digitalWrite ( LEDpin[i], LOW);
      }
    }
  }
}

Thank you for your guidance.

What is supplying power to the LEDs. It may be that the voltage is dropping and that is why the static LED pulses. Do you have a meter to monitor the LED supply voltage? Can you post a schematic that shows all components and power supplies? And a photo (or 2) of your setup may also be useful.

EDIT: I connected a couple of LEDs (pin 3 and A4) to my Uno and ran your code. The static LED (pin A4) does not pulse. That adds some credence to my theory that the power supply to the LEDs may be affected.

I'm going to guess numberOfLED is wrong. Try hard-coding that and/or send the value to serial monitor to verify it.

IIRC LEDpin is a pointer (an address) to the array LEDpin[] so sizeof (LEDpin) may not be what you think.

I have project that turns on 15 LED's one at a time

Your array has 16 elements.

I'm going to guess numberOfLED is wrong. Try hard-coding that and/or send the value to serial monitor to verify it.

No its correct at 16.

I agree with @groundFungus that you should look at the power. When I run your code with just the internal led on pin 13 and an external led on A4 there is no pulsing of the A4 led while 13 blinks on and off.

I failed to mention the LED on pin 13 was blinking, as well as the one on pin 3, during my test.

I will check the supply voltage in the morning. I have been using two Li-Ion 18650 size batteries in series for 8.14V for a long time while I test my project. I figured they were still fresh. Thank you! I will post back if it's not the batteries.

Why even have that LED in the code? Just connect it from 5V to ground.

What size current limit resistors and LED colors?

I am using the Arduino to control the LED because I already have the prototype board ready to go for it and rather then run a new circuit, I thought it would be easier to have the Arduino do it.

My resistors are all 330 ohms.

I checked the batteries with freshly charged 18650's this morning and the LED still pulses.

I have attached a very crude schematic for how it is set up. I have a switch that turns on the power to the Arduino and I let the Arduino control the positive signals to the LED's.

The forward current for the 3mm white LED is 20mA.

Which Arduino board are you using? What is the LED supply voltage?

Have you monitored the supply voltage while the program runs? Slow the speed down so that the meter has time to read between LEDs (1 or 2 seconds between changes).

The actual LED current is (Vsupply - Vf) / R where Vsupply is the supply voltage for the LED, Vf is the forward voltage of the LED (from the LED data sheet) and R is the value of the series current limit resistor.

You might try a smoothing cap across the LED power supply. 100uF to 1000uF (take care to observe polarity with electrolytic caps).

For nice schematics, I use Express Sketch a free download that is pretty easy to learn. Included is PCB design software, but I never use it.

I am using a Nano. The supply voltage is 8.14V.

I'll check out ExpressSketch. Thank you. I didn't want to waste time researching a schematic program so I used Paint. I know it's messy and inadequate.

I have not used a meter to monitor the voltage. That is a very good idea. Thank you!