Go Down

Topic: Troubleshooting Dim LED (Read 640 times) previous topic - next topic

greg81200

I'm working on this project where I have correctly wire 9 LEDs to the arduino and make certain LEDs flash so that it corresponds to a song.

My problem is that when I edit the code to turn on/off certain LEDs they all work perfectly fine, except for port 10 which instead of blinking bright like the rest of them blinks very very dim.

I have tried everything to fix this

-change LED
-change resistor/wires/arduino/breadboard/computer

Code:


int ledPins[] = {2,3,4,5,6,7,8,9,10};


void setup()
{
  int index;
 
 
  for(index = 0; index <= 7; index++)
  {
    pinMode(ledPins[index],OUTPUT);
   
  }
}


void loop()
{
 digitalWrite(ledPins[8], HIGH); 
  delay(500);
  digitalWrite(ledPins [8], LOW);
  delay(500); 
}


If anyone could help me get my light bright again, please let me know

Thanks in advance

pert

#1
Nov 29, 2017, 02:04 am Last Edit: Nov 29, 2017, 02:04 am by pert
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:

[code]// your code is here[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code. Do not post double spaced code.

OK, so you have 9 pins in the array:
Code: [Select]
int ledPins[] = {2,3,4,5,6,7,8,9,10};
then you only set the first 8 pins to OUTPUT:
for(index = 0; index <= 7; index++)
  {
    pinMode(ledPins[index],OUTPUT);
  
  }
Code: [Select]
digitalWrite(ledPins[8], HIGH);  
  delay(500);
  digitalWrite(ledPins [8], LOW);
  delay(500);  

Since the 9th item in the array wasn't set to ouput, you are turning the internal pull-up resistor on and off with the above code rather than setting the pin HIGH and LOW as you expected, thus the dim LED.

Here's how you can make your for loop automatically handle any number of items in the array:
Code: [Select]
for(index = 0; index < sizeof(ledPins) / sizeof(ledPins[0]); index++)

greg81200

Thanks so much for the help, this worked!

I was also able to finish my project, if anyone wants to see it the link is:

https://www.youtube.com/watch?v=uaNvC9LBlyA

Go Up