Why led be is dimmer in pin 2 than in pin 13 ?

I am using Arduino Uno, I am doing my project and it use red led...
it is so bright when I connect it from pin 13
it is so dim when I connect it from pin 2
I meausre pin 13 and pin 2 has same voltage (5V) but pin 13 has much more high current...
Hmm, how to solve this? I want my led be bright at all pin...it really give me boundary,,,, :~
Why it can happen? is it so or there is wrong with my arduino?

A lot of thanks.

Maybe, but maybe something wrong with your code or set-up. Can you share the code and at least a picture?

Yes sure, you are so good reply my question.

void setup();
void loop();
void increment (int line);
void show(int numberToDisplay,int fromLine);
void sendSerialData (byte registerCount,byte *pValueArray,int fromLine);
void sendSerialDatainitial(byte registerCount,byte *pValueArray,int fromLine);
int switchPin = A5;
int no1=1;
int no2=1;
int no3=1;


// Which pins are connected to which LED
const byte redLED0 = 2;
const byte redLED1 = 3;
const byte redLED2 = 4;

// Time periods of blinks in milliseconds (1000 to a second).
const unsigned long redLED0interval = 2000;
const unsigned long redLED1interval = 3000;
const unsigned long redLED2interval = 4000;

// Variable holding the timer value so far. One for each "Timer"
unsigned long redLED0timer;
unsigned long redLED1timer;
unsigned long redLED2timer;

// This pin gets sets low when I want the 595s to listen
const int  pinCommLatch1 = 5;
const int  pinCommLatch2 = 6;
const int  pinCommLatch3 = 7;

// This pin is used to pass the next bit
const int  pinData1    = 8;
const int  pinData2    = 9;
const int  pinData3    = 10;

// This pin is used by ShiftOut to toggle to say there's another bit to shift
const int  pinClock1     = 11;
const int  pinClock2     = 12;
const int  pinClock3     = 13;

// Definitions of the 7-bit values for displaying digits
byte g_digits [10];

//Machine Config in integer array
int MachineConfig[3][3];

// Current number being displayed
int g_numberToDisplay = 0;

// Number of shift registers in use
const int g_registers = 4;

// Array of numbers to pass to shift registers
byte g_registerArray [g_registers];

void setup()
{
  //config for line 1
  MachineConfig[0][0]=5;   //pinCommLatch line   1
  MachineConfig[0][1]=8;   //pinData line        1
  MachineConfig[0][2]=11;  //pinClock line       1
 
  //config for line 2
  MachineConfig[1][0]=6;   //pinCommLatch line   2
  MachineConfig[1][1]=9;   //pinData line        2
  MachineConfig[1][2]=12;  //pinClock line       2
  
  //config for line 3
  MachineConfig[2][0]=7;   //pinCommLatch line   3
  MachineConfig[2][1]=10;  //pinClock line       3
  MachineConfig[2][2]=13;  //pinData line        3
  
  // Setup the digits array
  g_digits [0] = 1 + 2 + 4 + 8 + 16 + 32 + 00;
  g_digits [1] = 0 + 2 + 4 + 0 + 00 + 00 + 00;
  g_digits [2] = 1 + 2 + 0 + 8 + 16 + 00 + 64;
  g_digits [3] = 1 + 2 + 4 + 8 + 00 + 00 + 64;         
  g_digits [4] = 0 + 2 + 4 + 0 + 00 + 32 + 64;              
  g_digits [5] = 1 + 0 + 4 + 8 + 00 + 32 + 64;         
  g_digits [6] = 1 + 0 + 4 + 8 + 16 + 32 + 64;
  g_digits [7] = 1 + 2 + 4 + 0 + 00 + 00 + 00;                   
  g_digits [8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
  g_digits [9] = 1 + 2 + 4 + 8 + 00 + 32 + 64;     
  //for loop 0-2 int
  for(int i=0;i<3;i++){
    sendSerialDatainitial(g_registers, g_registerArray,i);
  }
}

void sendSerialDatainitial(   
  byte registerCount,  // How many shift registers?
  byte *pValueArray,int fromLine)   // Array of bytes with LSByte in array [0]
{ 
    g_registerArray [3] = g_digits [0];
    g_registerArray [2] = g_digits [0];
    g_registerArray [1] = g_digits [0];
    g_registerArray [0] = g_digits [0];
    
    int PINCommLatch=MachineConfig[fromLine][0];
    int PINData=MachineConfig[fromLine][1];
    int PINClock=MachineConfig[fromLine][2];
      
    pinMode (PINCommLatch, OUTPUT);
    pinMode (PINData, OUTPUT);  
    pinMode (PINClock, OUTPUT);
    
  // Signal to the 595s to listen for data
  digitalWrite (PINCommLatch, LOW);
  
  for (byte reg = registerCount; reg > 0; reg--)
  {
    byte value = pValueArray [reg-1];

    for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
    {
      digitalWrite (PINClock, LOW);
    
      digitalWrite (PINData, value & bitMask ? HIGH : LOW);
        
      digitalWrite (PINClock, HIGH);
    }
  }
  // Signal to the 595s that I'm done sending
  digitalWrite (PINCommLatch, HIGH);
}  // sendSerialData


// Simple function to send serial data to one or more shift registers by iterating backwards through an array.
// Although g_registers exists, they may not all be being used, hence the input parameter.
void sendSerialData (
  byte registerCount,  // How many shift registers?
  byte *pValueArray, // Array of bytes with LSByte in array [0]
  int  fromLine)   
{
  int PINCommLatch=MachineConfig[fromLine][0];
  int PINData=MachineConfig[fromLine][1];
  int PINClock=MachineConfig[fromLine][2];
  
  // Signal to the 595s to listen for data
  digitalWrite (PINCommLatch, LOW);
  
  for (byte reg = registerCount; reg > 0; reg--)
  {
    byte value = pValueArray [reg - 1];

    for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
    {
      digitalWrite (PINClock, LOW);
    
      digitalWrite (PINData, value & bitMask ? HIGH : LOW);
        
      digitalWrite (PINClock, HIGH);
    }
  }
  // Signal to the 595s that I'm done sending
  digitalWrite (PINCommLatch, HIGH);
}  // sendSerialData


void loop()
{  
  if (digitalRead(switchPin))
  {
    blinks();
  }
}

void blinks() 
{
  // Handling the blink of one LED.
  if ( (millis () - redLED0timer) >= redLED0interval)
     {
     digitalWrite (redLED0, HIGH);
     delay (1000);
     digitalWrite (redLED0, LOW);
     increment (0);
     redLED0timer = millis ();
     }
   
   if ( (millis () - redLED1timer) >= redLED1interval)
     {
     digitalWrite (redLED1, HIGH);
     digitalWrite (redLED1, LOW);
     increment (1);
     redLED1timer = millis ();
     }
     
   if ( (millis () - redLED2timer) >= redLED2interval)
     {
     digitalWrite (redLED2, HIGH);
     digitalWrite (redLED2, LOW);
     increment (2);
     redLED2timer = millis ();
     }
    
}
 /* int line1 = random (1,3);
  int line2 = random (1,4);
  int line3 = random (1,6);
    
  int k=0;
  if(line1==1)
  {
      digitalWrite(2, HIGH);   // set the LED on
      delay(300);
      digitalWrite(2, LOW);  
      increment(0);    
  }
  
  if(line2==1)
  {
      digitalWrite(3, HIGH);   // set the LED on
      delay(300);
      digitalWrite(3, LOW);  
      increment(1);    
  }
    
  if(line3==1)
  {
      digitalWrite(4, HIGH);   // set the LED on
      delay (200);
      digitalWrite(4, LOW); 
      increment(2);    
  }   
}*/

void increment(int line)
{
  if(line==0)
  {
   g_numberToDisplay = no1;
   no1++;
   show(g_numberToDisplay,line);
  }else if(line==1)
  {
   g_numberToDisplay = no2;
   no2++;
   show(g_numberToDisplay,line);
  }
  else if(line==2)
  {
  g_numberToDisplay = no3;
  no3++; 
  show(g_numberToDisplay,line);
  }
}
   
void show(int numberToDisplay,int fromLine)
{
  if (numberToDisplay < 10)
  {
    //g_registerArray [4] = g_digits [0];
    g_registerArray [3] = g_digits [0];
    g_registerArray [2] = g_digits [0];
    g_registerArray [1] = g_digits [0];
    g_registerArray [0] = g_digits [numberToDisplay];
  }
  else if (numberToDisplay < 100)
  {
    //g_registerArray [4] = g_digits [0];
    g_registerArray [3] = g_digits [0];
    g_registerArray [2] = g_digits [0];
    g_registerArray [1] = g_digits [numberToDisplay / 10];
    g_registerArray [0] = g_digits [numberToDisplay % 10];
  }
  else if (numberToDisplay < 1000)
  {
    //g_registerArray [4] = g_digits [0];
    g_registerArray [3] = g_digits [0];
    g_registerArray [2] = g_digits [numberToDisplay / 100];
    g_registerArray [1] = g_digits [(numberToDisplay % 100) / 10];
    g_registerArray [0] = g_digits [numberToDisplay % 10];
  }
  else
  {
    //g_registerArray [4] = g_digits [0];
    g_registerArray [3] = g_digits [numberToDisplay / 1000];
    g_registerArray [2] = g_digits [(numberToDisplay % 1000) / 100];
    g_registerArray [1] = g_digits [(numberToDisplay % 100) / 10];
    g_registerArray [0] = g_digits [numberToDisplay % 10];
  }
 // else
  //{
    //g_registerArray [4] = g_digits [numberToDisplay / 10000];
    //g_registerArray [3] = g_digits [(numberToDisplay % 10000) / 1000];
    //g_registerArray [2] = g_digits [(numberToDisplay % 1000) / 100];
    //g_registerArray [1] = g_digits [(numberToDisplay % 100) / 10];
    //g_registerArray [0] = g_digits [numberToDisplay % 10];    
  //}
  sendSerialData (g_registers, g_registerArray, fromLine);
}

Pin 13 is not even used as an LED status indicator. You question and your code do not match.

What are you trying to do and what testing did you do to see if 13 and 2 do not light an LED the same?

Do you explicitly define both pins as output? I don't see this in the code supplied.

Not sure why this is a concern given that code, but if you are in doubt, you need to write specific code to answer your question. For example, define Pin 2 as output, then set it to HIGH attach an LED with resistor and see how bright it is. Then, define pin 13 as output, set it to HIGH and move the same resistor and LED over to check if it is the same.

I dont put any code for pin 13, because I just directly connect the legs of the led to the pin 13 and ground, and then it lights so bright....
Then I compare with the led I connect to the pin 2 where I upload my code, and it is dimmer...

Hmm, well I'm sorry I'm doing my own experiment on the hardware without writing the code...

Yes I have tried as you said Bro, and it show brighter using pin 13 thatn pin 2...what's wrong here??? :zipper_mouth_face:

Are you using a resistor? It might have too much current going through it, making it dimmer(I'm not sure if that's possible, but maybe?).

Are you using a resistor? It might have too much current going through it, making it dimmer(I'm not sure if that's possible, but maybe?).

That resistor is a current limiting resistor that simply limits current and thus controls too much current to be at a level which is comfortable to make the LED lit and not burn it, if you use a Led without a resistor then it will burn with outrageous brightness and will first get hot and then its filament with in will burn by becoming hot and will melt.

If you don't define a pin as an output then it will be an input. On some systems pin 13 comes up already defined as an output. You can draw current from an output but not an input. That is why it is so bright.
Stop being an idiot and get a seriese resistor in that LED before you break something.

1 Like
 MachineConfig[0][0]=5;   //pinCommLatch line   1
  MachineConfig[0][1]=8;   //pinData line        1
  MachineConfig[0][2]=11;  //pinClock line       1
 
  //config for line 2
  MachineConfig[1][0]=6;   //pinCommLatch line   2
  MachineConfig[1][1]=9;   //pinData line        2
  MachineConfig[1][2]=12;  //pinClock line       2
  
  //config for line 3
  MachineConfig[2][0]=7;   //pinCommLatch line   3
  MachineConfig[2][1]=10;  //pinClock line       3
  MachineConfig[2][2]=13;  //pinData line        3
  
  // Setup the digits array
  g_digits [0] = 1 + 2 + 4 + 8 + 16 + 32 + 00;
  g_digits [1] = 0 + 2 + 4 + 0 + 00 + 00 + 00;
  g_digits [2] = 1 + 2 + 0 + 8 + 16 + 00 + 64;
  g_digits [3] = 1 + 2 + 4 + 8 + 00 + 00 + 64;         
  g_digits [4] = 0 + 2 + 4 + 0 + 00 + 32 + 64;              
  g_digits [5] = 1 + 0 + 4 + 8 + 00 + 32 + 64;         
  g_digits [6] = 1 + 0 + 4 + 8 + 16 + 32 + 64;
  g_digits [7] = 1 + 2 + 4 + 0 + 00 + 00 + 00;                   
  g_digits [8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
  g_digits [9] = 1 + 2 + 4 + 8 + 00 + 32 + 64;

Unless you really like typing, can I suggest that the compiler will do this stuff for you, in a much more succint manner?

byte MachineConfig[3][3] = {{5, 8, 11},
                           {6, 9, 12},
                           {7, 10, 13}};

(note also the 50% saving in RAM)

Surely I dont use resistor for that two cases...

Here I attach, you see the led even like turned off...
Heuu, I found another problem, that my 7segment is hullaballo, dont work properly...

It is so weird, the 7 segment on when I move my finger near without touching the cable, what a mystic!
I dont have any sensor around there....
I move my finger to the shift register IC 74HC595, and the 7segment lights on randomly...
Can you help with this?

this is what I attach, sorry about the post before...

@AWOL, thank a lot for your input but I need that type of that array in order to use "fromLine" parameters.

int PINCommLatch=MachineConfig[fromLine][0];
    int PINData=MachineConfig[fromLine][1];
    int PINClock=MachineConfig[fromLine][2];

@Grumpy_Mike: wow, you are right 101%! Now my led is so bright, genious, 8)

@AWOL, thank a lot for your input but I need that type of that array in order to use "fromLine" parameters.

I don't understand the presence of the word "but" in that sentence.

AWOL:

@AWOL, thank a lot for your input but I need that type of that array in order to use "fromLine" parameters.

I don't understand the presence of the word "but" in that sentence.

Yeah, probably different type of mother tongue...

But I would like to say your code is much more simpler! :wink:

It is so weird, the 7 segment on when I move my finger near without touching the cable, what a mystic!

This sounds like you have a floating input somewhere. That is an input not connected to anything, it is very common behavior and not at all weird.
To understand what is going on read this link:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

  // Setup the digits array
  g_digits [0] = 1 + 2 + 4 + 8 + 16 + 32 + 00;
  g_digits [1] = 0 + 2 + 4 + 0 + 00 + 00 + 00;
  g_digits [2] = 1 + 2 + 0 + 8 + 16 + 00 + 64;
  g_digits [3] = 1 + 2 + 4 + 8 + 00 + 00 + 64;         
  g_digits [4] = 0 + 2 + 4 + 0 + 00 + 32 + 64;              
  g_digits [5] = 1 + 0 + 4 + 8 + 00 + 32 + 64;         
  g_digits [6] = 1 + 0 + 4 + 8 + 16 + 32 + 64;
  g_digits [7] = 1 + 2 + 4 + 0 + 00 + 00 + 00;                   
  g_digits [8] = 1 + 2 + 4 + 8 + 16 + 32 + 64;
  g_digits [9] = 1 + 2 + 4 + 8 + 00 + 32 + 64;

I see you are setting bits in those variables. It is good you know about bits, but that is the long way to type.

Numbers can be decimal as you have above. They can also be written as binary, all 1 or 0. Binary numbers begin with 0b to tell the compiler it is binary, not decimal. There is also hexadecimal, known as hex, which is base 16. Hex numbers are 0 1 2 3 4 5 6 7 8 9 A B C D E F.
If you have Windows, the calculator can be switched to scientific mode and will let you use and see hex and binary as well as decimal.

Decimal 7, writes as 7 equal binary 111, writes in code as 0b111. But like decimal, large to small is left to right.

  g_digits [9] = 1 + 2 + 4 + 8 + 00 + 32 + 64;

Using binary makes the same code but easier to write and read

  g_digits [9] = 0b1101111;

When you read the binary from left to right the above is 64 + 32 + 8 + 4 + 2 + 1 or 2^6 + 2^5 + 2^3 + 2^2 + 2^1 + 2^0.

Arduino C++ has bit functions to make it even easier/more clear. Check into bitRead(), bitWrite() and the others.

Good luck, I know something of trying to use other language than my own from long ago in school. And you are trying for learning technical matters, which is even harder. You have brains and guts!