Problem with weak led

Hi y'all!

We've got a problem with some leds that wont light up as theyre supposed to.
We can tell theyre on but the are very weak. We've already tested all the electronics,
theyre fine and the leds are working with other codes.

The idea is to light up one led at a time every time someone has knocked a sertain amount of times at the knock sensor (piezo).
The led at pin 5 starts to light up after 10 knocks. But when the time comes to led pin 6 and 7 they are super weak.

Could someone please have a look at our code?

int knockPin = 3; //pin for incoming knock sensor
int ledPins[]= {5,6,7,8,9,10,11,12,13};
int ledPin = 5;
int ledCount = 14;
int knockVal;
int countKnock=0;
int mappedVal;

void setup()
{
  Serial.begin(9600);
  
  for(int i=5; i< ledCount; i++)
  {
    pinMode(ledPins[i],OUTPUT);
  }
}


void loop()
{
  
  knockVal = analogRead(knockPin);
  mappedVal = map(knockVal,0,1023,1,10);//remap knockVal to a scale of 1-10 instead
  
  
   if(mappedVal <=8) //every knock, increase countKnock with +1
   {
      countKnock +=1;
      Serial.println(countKnock); 
      Serial.print("ledpin: ");
      Serial.println(ledPin);
      delay(80);
   }
   
   //when countKnock reaches 10 light the first led, and so on..
   if(countKnock >= 10 && countKnock <20)
   {    
    digitalWrite(5,HIGH);
   }
   
   if(countKnock >= 20 && countKnock <28)
   {
         
    digitalWrite(6,HIGH);
   }

   if(countKnock >= 28 && countKnock <36)
   {    
    digitalWrite(7,HIGH);
    digitalWrite(5,LOW);
   }
  

}

First thing is to change:

pinMode(ledPins*,OUTPUT);*
to:
pinMode(i,OUTPUT);
You have no need for the array your define here:
int ledPins[]= {5,6,7,8,9,10,11,12,13};
As you are not referencing it in your main loop at all, and you are improperly using it in the mode statement in your setup function.
Lefty

THANK YOU!!!
Such an easy annoying problem. It solved everthing!
Thanks :smiley:

int knockPin = 3;
...
knockVal = analogRead(knockPin);

I also notice that you're taking an analog read from a digital pin.

I also notice that you're taking an analog read from a digital pin.

You can't tell anything like that. The aliases A0, A1, etc. are for when using an analog pin as a digital pin. They are not meant to refer to analog pins AS analog pins. So, the "missing A" does not mean that the pin being referred to is not an analog pin.

As long as the sensor IS actually connected to analog pin 3, that code is perfectly valid.

Oh, that I did not know. So to Arduino,
knockVal = analogRead(3); is the same as knockVal = analogRead(A3); ?

Yes it is the same.