LED brightness control from GND?

I’m working on a HUD for a racing simulator and having a bit of an issue with the brightness of the display. I have 15 LED rev limiter lights and 6 LED indicator lights. Obviously I ran out of PWM pins before I even started. Each of the LED’s use their own pin on the MEGA. And yes, I have looked into the “blink” method of dimming these, but it just won’t work with this project.

My question is, is there a way that a PWM pin could be used to control the amount of resistance on the cathode side of the LED’s? Theoretically, even though all of the LED’s are on their own pin, they all connect to the same ground, and resistance (or anything like that) applied before connection to the ground would dim all of the LED’s evenly.

Any ideas?

If you try that then the ammount of dimming you will get will be dependant on how many LEDs are on at any one time. You need a transistor to sink the current as well as the arduino pins can only sink less than 40mA.

Why not use a shift register, it will give you all the pins you need and you can apply PWM to them using the shiftPWM libary.

Grumpy_Mike: If you try that then the ammount of dimming you will get will be dependant on how many LEDs are on at any one time. You need a transistor to sink the current as well as the arduino pins can only sink less than 40mA.

Why not use a shift register, it will give you all the pins you need and you can apply PWM to them using the shiftPWM libary.

Would a shift register work in conjunction with the 2 I2C devices I'm already using?

Yes, 2 shift registers can drive 16 LEDs on or off, with the output enable driven by a PWM pin for brightness control. I usually use the SPI pins to drive them - SCK to SRCLK, MOSI to serial data in, and SS to RCLK:

int leds0to15;

// data changed? send it out digitalWrite (ssPin, LOW); // use direct port manipulation to speed this up more SPI.transfer (highByte (leds0to15)); SPI.transfer (lowByte (leds0to15)); digitalWrite (ssPin, HIGH); // outputs change on this rising edge

Slight confusion here. (Isn't that always teh way?)

If you want PWM dimming, for all LEDs together, then of course you can use the PWM to switch the common cathode return with a suitable transistor or FET.

It will not vary the brightness significantly depending on how many LEDs are illuminated as it is either on or off at any given moment and you simply provide adequate drive to the switching device for it to saturate. A logic-level FET would be appropriate.

Slight confusion here.

Yes Paul__B you are confused. The OP was asking about putting ANOTHER resistor in the cathode. You know that by his words:-

My question is, is there a way that a PWM pin could be used to control the amount of resistance on the cathode side of the LED's?

To which the answer is no.

You seem to have changed the question to "is there a way".

The bottom line is that:-

Obviously I ran out of PWM pins before I even started.

So actually describing the way he could do this is a bit unhelpful, as you are ofttimes libel to be.

His real problem is lack of PWM pins, which we are addressing.

Mike, do you seriously believe that in some perverse way, it benefits your "reputation" by mendaciously mis-quoting the OP in order to confuse matters? This hardly constitutes "libel" on my part. :grinning:

MordeKyle: My question is, is there a way that a PWM pin could be used to control the amount of resistance on the cathode side of the LED's? Theoretically, even though all of the LED's are on their own pin, they all connect to the same ground, and resistance (or anything like that) applied before connection to the ground would dim all of the LED's evenly.

As I have carefully explained, the answer is clearly "Yes!"

He cites a PWM pin. Now we could consider various esoteric ways of taking the PWM signal, using a low-pass filter to convert this to an analog value and using this to control a linear pass element in the negative side of the indicator LEDs. Clearly the problem here is that merely introducing a resistance or current limit would lead to a variation in brightness according to how many LEDs were illuminated at any one time.

But hey! It is a PWM pin, and you effect dimming using PWM. As I explained, it is entirely effective to simply switch the negative line en masse with the PWM signal.

The answer is then "Yes!" PWM controls the "effective" resistance to each LED (since it is in effect, switching each series resistor on and off simultaneously). That exactly covers "resistance or anything like that".

His real problem is not lack of PWM pins as he said "would dim all of the LED's evenly". He does not want to dim them independently (since for a start, 15 of them form a bar graph), so he does not require separate PWM pins.

The matter of driving a large number of LEDs is separate. Shift registers would indeed be an appropriate solution, and applying PWM to the output enable pin of the registers would certainly effect simultaneous dimming of all.

I trust he has considered the total loading of all the port pins - if many or most indicators are to be illuminated simultaneously, then the current limiting resistors would need to be selected for something in the order of 5 mA per LED (irrespective of the use of PWM) and this would apply similarly using shift registers unless you use power shift registers such as the TPIC6B595 (which is a cathode driver).