Electronic – arduino – Controlling the brightness of multiple LEDs at once

arduinopwm

I'm building a device for DJ-ing. When practicing at home I prefer the LEDs on the device to be quite bright, but when I'm in a club setting I'd like to dim them to my liking so that I'm not blinded by them. The brightness should be controlled via a potentiometer connected to an analogue input on my Arduino but I'm intending to switch the LEDs individually (no mutliplexing) with digital outputs.

I have a bunch of 2N3904 transistors so I thought maybe I could use them in some configuration, but I'm having a hard time finding a simple way to do this.

EDIT:
I'm happy to provide any additional information.

Regarding the LED's: I'm using 15 regular 5mm LED's.

Controller: Meduino Mega2560 R3 Pro Mini.

Power: The device will be powered by a 9V wallwart but I'm not too sure if it's OK to use the 5v regulator output on the MCU-board.

Best Answer

I've done this as an overall dimmer for panel lights:

schematic

simulate this circuit – Schematic created using CircuitLab

This is a relaxation oscillator (the bottom part) compared to an adjustable reference (the top part). The reference is a front-panel potentiometer that is padded with fixed resistors to match the voltage range of the oscillator. I would recommend 10k resistors all around because they're easy to get, as well as the pot. Choose the capacitor for a low-ish frequency that is still higher than you can see, like maybe 30Hz or above. A 555 calculator may be useful because the voltage range is similar.

The PWM output then feeds one of these, depending on which is easier for you:

schematic

simulate this circuit

As you can see, each LED is individually controlled from a digital output, and the common rail is controlled by the PWM'ed transistor. Thus, OFF is still off, and ON is whatever brightness you set with the PWM generator.

Just make sure that your LED's can withstand the full supply worth of reverse voltage because they'll get that when the PWM is off and you're driving some LED's on and others off. Or to avoid that problem, you could use the opposite type of transistor to control each LED, but I've never needed to.

This has the advantage (for me at least) of the processor not needing to care about the overall brightness. For panel indicators, all the software needs to know is ON/OFF, and this analog circuit defines how bright ON actually is.