I'm working on a small project. I have 13 leds which need to be controlled individually (turn on or turn off); Since I don't have 13 pwm pins I used a potentiometer to change the brightness.

This works fine for as long as all of the leds stay in the state they are. But once one led turns on or off it affects the brightness of all other leds.

In the picture below you can see how I did connect them. I have the analog pins A0, A1, A2 and A3 occupied by some buttons.

Does anyone know how I can dim the leds in a way where the leds themselves don't affect the brightness?

(note: I am a programmer and not so much of an electrical engineer. Code-related answers are (usually) easy for me to understand. ones about the hardware are not.);

Current Setup

closed as off-topic by Juraj, sempaiscuba, VE7JRO, Greenonline, MatsK Oct 7 '18 at 12:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Juraj, sempaiscuba, VE7JRO, Greenonline, MatsK
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Maybe an extention board like this one from Adafruit, which gives you 16 individual PWM outputs – chrisl Oct 4 '18 at 11:35
  • 1
    from Tour: "Don't ask about... Any question that doesn't require knowledge about the Arduino platform to answer (try Stack Overflow for general coding questions or Electrical Engineering for general electronics questions)" – Juraj Oct 4 '18 at 12:05
  • @chrisl Thanks for that suggestion! It is a bit expensive, but I'll look into it. Do you by any chance know if I can connect multiple I2C boards to an arduino? – Animiles Oct 4 '18 at 12:56
  • @Juraj I guess you're right. Chrisl's suggestion does require a bit of arduino knowledge though, and because I don't have a complex circuit I personally think this forum would be a better place. I want a solution to this problem, and it doesn't have to be purely an electrical engineering solution :) (I'll keep it in mind for next time though. Thank you for mentioning it) – Animiles Oct 4 '18 at 12:56

Read the pot with analogRead(). Do not connect it to the LEDs at all, just 5v, Gnd and wiper to A5 (any of the analog input pins). LEDs just go from resistor on one leg to Gnd on the other (or 5V, depends on whether anode or cathode is connected to the resistor).

Then use software PWM to control the LEDs.

For example:

byte potPin = A5;
int potValue;
byte ledPin[] = {2,3,4,5,6,7,8,9,10,11,12,13,14};
byte x;

void setup(){
  for (x=0; x<13; x=x+1){
  pinMode (ledPin[x], OUTPUT);
void loop(){
potvalue = analogRead (potPin); // 0 to 1023 value
for (x = 0; x<13; x=x+1){
  digitalWrite (ledPin[x], HIGH);
  // 0 = max brightness, 1023 (1.023mS) will be dimmest
  // manipulate potValue if 1023 is not dim enough - double it, triple it, etc.
  digitalWrite (ledPin[x], LOW);

From here, you can play with other setups for controlling the brightness.

  • 1
    the question is "But once one led turns on or off it affects the brightness of all other leds.". Does this solve it? – Juraj Oct 4 '18 at 13:33
  • @Juraj It works like normal pwm, but this would make it rather tricky to do while the arduino needs to do other things, especially ones where 'delay()' is used. It is the main reason why I don't think his suggestion would be suited for my project. Otherwise I think it should work. – Animiles Oct 4 '18 at 14:26
  • Wouldn't be hard to change this to Blink Without Delay style of code, and getting rid of the delayMicroseconds(). – CrossRoads Oct 4 '18 at 14:32
  • but doesn't the overall brightness problem origin in wiring of the LEDs (serial v. parallel)? – Juraj Oct 4 '18 at 14:44
  • The LEDs as pictured only share a common Gnd or +5. They are not wired in serial or parallel - each has its own driver (an Arduino output pin). – CrossRoads Oct 4 '18 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.