Go Down

Topic: Arduino Uno analog pins (as digital output) not outputting enough power (Read 524 times) previous topic - next topic

Trevader24135

I am making a binary clock using LEDs. I need 6 LEDs for seconds, 6 for minutes, and 5 for hours. there are JUST enough pins on the arduino uno to run all 17 LEDs when I use the analog pins for digital outputs, which works fine. the issue is that when the digital pins turn on their LEDs, the analog pins seem to cut most of their power to their LEDs, so the LEDs are ALMOST off, but still on, albeit very dimly, and even dimmer with more digital pins on. is this just a limitation of the UNO, or is there something else going on?

TL;DR:
analog pins lose output power when digital pins are on.

larryd

No technical PMs.
The last thing you did is where you should start looking.

Trevader24135

The issue I see with that is it won't fix the fact that the arduino basically just wont output any power at all out of the analog pins if the digital pins are on. there will be no current to switch a transistor.

larryd

Controller outputs only send a small amount of current to the transistors, a few milliamps at most.

See Q1, Q2 or Q3.



Let's see your current schematic.


No technical PMs.
The last thing you did is where you should start looking.

westfw

I have a current project that drives an 8 digit display, with some of the common cathodes being driven by analog pins.  It seems to work fine, so I suspect something wrong with your schematic or sw.  Do you have current limiting resistors?

PaulRB

The usual reason for dim leds is setting a pin HIGH but forgetting to set it to OUTPUT. Then the led is lit via the Arduino's internal pull-up resistor, so very little current flows. Did you check that?

Another cause could be that you are exceeding the total current limit of the atmega328 chip, which is about 200mA. So 10 LEDs at 20mA would be on the limit. In addition, there are 100mA limits for certain combinations of pins.

Trevader24135

#6
Oct 14, 2017, 06:25 pm Last Edit: Oct 14, 2017, 06:48 pm by Trevader24135 Reason: added circuit diagram
Okay, here's my code:
Code: [Select]
int hours = 0;
int minutes = 0;
int seconds = 0;
  
void setup() {
  // put your setup code here, to run once:
  //Serial.begin(115200);
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 3036;
  TCCR1B |= (1<<CS12);
  TIMSK1 |= (1<<TOIE1);

  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  digitalWrite(13,0);
}

ISR(TIMER1_OVF_vect) {
  //unsigned long timee = millis();
  //Serial.print(timee);
  /*
  if (timee % 1000 > 0 && timee % 1000 < 500) {
    TCNT1 = 3068;
  } else if (timee % 1000 > 500 && timee % 1000 != 0) {
    TCNT1 = 3004;
  } else {
    TCNT1 = 3036;
  }
  */
  seconds += 1;
  if (seconds == 60) {
    seconds = 0;
    minutes += 1;
    if (minutes == 60) {
      minutes = 0;
      hours += 1;
      if (hours == 24) {
        hours = 0;
      }
    }
  }
  //Serial.print(" | ");Serial.print(hours);Serial.print(":");Serial.print(minutes);Serial.print(":");Serial.println(seconds);
  digitalWrite(A5, HIGH && (seconds & B00000001));
  digitalWrite(A4, HIGH && (seconds & B00000010));
  digitalWrite(A3, HIGH && (seconds & B00000100));
  digitalWrite(11, HIGH && (seconds & B00001000));
  digitalWrite(10, HIGH && (seconds & B00010000));
  digitalWrite(9, HIGH && (seconds & B00100000));

  digitalWrite(2, HIGH && (minutes & B00000001));
  digitalWrite(3, HIGH && (minutes & B00000010));
  digitalWrite(4, HIGH && (minutes & B00000100));
  digitalWrite(5, HIGH && (minutes & B00001000));
  digitalWrite(6, HIGH && (minutes & B00010000));
  digitalWrite(7, HIGH && (minutes & B00100000));

  digitalWrite(A0, HIGH && (hours & B00000001));
  digitalWrite(A1, HIGH && (hours & B00000010));
  digitalWrite(A2, HIGH && (hours & B00000100));
  digitalWrite(12, HIGH && (hours & B00001000));
  digitalWrite(13, HIGH && (hours & B00010000));
}
void loop() {
  // put your main code here, to run repeatedly:
    
};


and my schematic is simply every pin of the arduino (I'm using a standalone atmega328, but the issue is the same with the board) connected directly to the anode of an LED, and a common cathode within the color groups (I have 3 colors, red, blue, and white) and a resistor (1kohm red, 220ohm for white, and 1k0hm for blue, my LEDs appear to be low quality because the voltages between them seems skewed (red needs lowest, blue needs highest, opposite of normal, right?)) betwen each of those common anodes and ground.

PaulRB



You should have 1 series resistor per led, not one per group. That is unless only one led from each group will ever be lit at the same time, which won't be the case for a binary clock. The result will be that the brightness of the leds will decrease as more leds in the same group are lit, and uneven brightness between them. One resistor per let will prevent the group dimming are more leds are lit, and also help to minimise the differences in brightness between the leds because of the variance in their forward voltages.

Red leds normally have a lower forward voltage, around 1.8-2.0V. Yellow and orange and some green are normally around 2.2-2.4V. Other greens, blue and white leds have the highest forward voltages at around 3.0-3.5V.

220R and 1K sound too far apart. How did you choose those values?

What does this code do?
Code: [Select]
  if (timee % 1000 > 0 && timee % 1000 < 500) {
    TCNT1 = 3068;
  } else if (timee % 1000 > 500 && timee % 1000 != 0) {
    TCNT1 = 3004;
  } else {
    TCNT1 = 3036;
  }

cattledog

Variables(hh/mm/ss) which are changed within an ISR should  be declared as volatile. There's no need for them to be bigger than byte.

Code: [Select]
volatile byte hours = 0;
volatile byte minutes = 0;
volatile byte seconds = 0;


I too am confused by the commented code indicated by PaulRB. If indeed it is commented out, then TCNT1 will not reset to 3036 after the first overflow, and the timing will be wrong?

The boolean && makes a statement True only if both operands are true. HIGH is always TRUE. Therefore these formulations are equivalent, and the compiler may even resolve them as the same. I think the later formulation is more intuitive without the boolean && of a masked value.

 
Code: [Select]
digitalWrite(A5, HIGH && (seconds & B00000001));
 
  digitalWrite(A5, (seconds & B00000001));

Trevader24135

The reason the code is commented out is because it was just a test on making the clock more accurate (it made no difference because I was still comparing to the original, I don't know what I was thinking), so it's not necessary to run because the interrupt is called close enough every time that I don't REALLY need to worry about it, it'll just be off a few seconds a day until I can get a RTC.

Cattledog you're right, I was borrowing some code and roughly adapted it to my needs, so I never gave it much thought, but I see what you mean. thanks.

sterretje

There is a current limit for the 328 micro. 20mA per pin (absolute max (whatever that is) 40mA), 200mA through Vcc and/or GND and there is also one for the max current per port (can't currently find it).
The issue I see with that is it won't fix the fact that the arduino basically just wont output any power at all out of the analog pins if the digital pins are on. there will be no current to switch a transistor.
Remove all leds and try again ;)
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

jendalinda

Use high brightness LEDs and 1k resistors. I was able directly control 18 LEDs this way.

Smajdalf

Do you have GOOD connection between Vcc and AVcc pin? IIRC analog pins are powered from AVcc pins and lower voltage on AVcc may lead to lower voltage on Analog pins and so less bright LEDs powered from them.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

westfw

In the schematic in post 7 (actually showing in post 7 AVCC and the send ground pin are not shown as connected to ANYTHING!   ALL power pin MUST be connected to VCC/GND as appropriate for correct operation.  The exact nature of failures when some power pins are left unconnected is undefined, but one of the suspected behaviors is that the PORTC pins, which are "powered" by AVCC, might not provide full output current.


Go Up