# Multiple rgb leds controlled by transistors

**URL:** <https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505>\
**Category:** LEDs and Multiplexing\
**Created:** [November 4, 2015, 4:48am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505 "2015-11-04T04:48:39Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![chairr](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@chairr](https://forum.arduino.cc/u/chairr)\
**Post date:** [November 4, 2015, 4:48am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/1 "2015-11-04T04:48:39Z")

</div>

I am making an rgb led colour mixer, which utilises a 10k potentiometer and 4 rgb leds. The rgb leds are common cathode, and thus have r,g,b pins along with a GND pin. I know that the arduino itself cannot power 4 leds as there is not enough amperage (apologies if i sprout garbage out my mouth, I am still very new to this), so I have got my hands on a 4×AA battery pack and some 548 NPN transistors. I have built the project on a breadboard and an Arduino UNO. It works fine but I am worried that I have missed something as this is my first project (ever). Will this burn out the arduino/leds somehow? Thanks.

Breadboard:  
[http://puu.sh/l8INg/e9354ab63b.png](http://puu.sh/l8INg/e9354ab63b.png)

```cpp
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int potPin = A0;
int val = 0;

void setup()
{
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);

 Serial.begin(9600);
}

void loop()
{
 //Pot reader
 val = analogRead(potPin);
 Serial.println(val);
 
 //Red orange yellow green
 if ( val <= 341 )
 {
  //We now know the val is between 0 and 341.
  //Map the val to 0-255 for the LED.
  val = map(val, 0, 341, 0, 255);
  
  //Higher val turns red down.
  //Lower val turns red up (common anode).
  analogWrite(redPin, val);
  
  //Write the complimentary amount to the green pin.
  //The mixed color values add up to 255.
  //This keeps the LED at constant brightness.
  analogWrite(greenPin, 255-val);
  
  //Turn blue pin off.
  analogWrite(bluePin, 255);
 }
 
 //Green-teal-blue spectrum
 else if ( val <= 683 )
 {
  //We now know the val is between 341 and 683.
  //Map the val to 0-255 for the LED.
  val = map(val, 341, 683, 0, 255);
  
  //Higher val turns green down.
  //Lower val turns green up (common anode).
  analogWrite(greenPin, val);
  
  //Write the complimentary amount to the blue pin.
  //The mixed color values add up to 255.
  //This keeps the LED at constant brightness.
  analogWrite(bluePin, 255-val);
  
  //Turn red pin off.
  analogWrite(redPin, 255);
 }
 
 //Blue-indigo-purple-red spectrum.
 else
 {
  //We now know the val is between 683 and 1023.
  //Map the val to 0-255 for the LED.
  val = map(val, 683, 1023, 0, 255);
  
  //Higher val turns blue down.
  //Lower val turns blue up (common anode).
  analogWrite(bluePin, val);

  //Write the complimentary amount to the red pin.
  //The mixed color values add up to 255.
  //This keeps the LED at constant brightness.
  analogWrite(redPin, 255-val);

  //Turn green pin off.
  analogWrite(greenPin, 255);
 }
 
 //Sampling rate.
 delay(20);
}

```

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 4, 2015, 10:16am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/2 "2015-11-04T10:16:31Z")

</div>

> chairr:  
> Will this burn out the arduino/leds somehow? Thanks.

Might do! 🙄

No current limiting resistors in **each** anode of **each** individual LED.

Balanced against that is that you lose almost a volt in the emitter followers, so you are only feeding about 4.3 V to the LEDs.

OK, just add the 12 resistors. Try 150 ohms for the reds, 100 Ohms for the other two colours.

Note that the Arduino may be overloaded if the batteries go flat.

---

<div class="post-metadata">

**Author:** ![chairr](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@chairr](https://forum.arduino.cc/u/chairr)\
**Post date:** [November 4, 2015, 10:24am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/3 "2015-11-04T10:24:58Z")

</div>

Sorry, forgot to mention. The leds already have 100 ohm resistors for each rgb pin. Forgot to mention as they are mounted on a pcb (off ebay!). I'm more worried about the arduino though. The battery pack will be replaced by a proper 5V DC power source asap.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 4, 2015, 10:38am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/4 "2015-11-04T10:38:16Z")

</div>

As long as the power feed to the emitter followers cannot be turned off while the Arduino is powered up, it will be fine.

If the 5V is **regulated** , you can feed it to VCC on the Arduino.

---

<div class="post-metadata">

**Author:** ![chairr](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@chairr](https://forum.arduino.cc/u/chairr)\
**Post date:** [November 4, 2015, 10:41am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/5 "2015-11-04T10:41:04Z")

</div>

So it's fine if I have a constant 5v DC power source replacing the batteries though right? I accidently blew up an led today when I was tired so I'm super paranoid now!

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 4, 2015, 11:02am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/6 "2015-11-04T11:02:26Z")

</div>

I try to avoid repeating myself. 😀

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 4, 2015, 1:32pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/7 "2015-11-04T13:32:05Z")

</div>

You need a 1K resistors in line with each transistor base.

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [November 4, 2015, 2:16pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/8 "2015-11-04T14:16:45Z")

</div>

Mike, i am very reluctant to question what you say, but i have been told that when a npn is used as an emitter-follower like that, there is no reason to have a resistor on the base, the current regulates itself. Can you enlighten us please?

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 4, 2015, 9:18pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/9 "2015-11-04T21:18:45Z")

</div>

> when a npn is used as an emitter-follower like that, there is no reason to have a resistor on the base,

Yes of course that is true, sorry.

The main problem is that Fritzing is so god dammed awful it is impossible to see what is happening.

He should not be using the transistor in this mode anyway.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 4, 2015, 9:20pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/10 "2015-11-04T21:20:44Z")

</div>

I suspect he mistook something. 😀

It is the case that using an emitter follower, you must **not** insert base resistors.

> Grumpy\_Mike:  
> The main problem is that Fritzing is so god dammed awful it is impossible to see what is happening.

Could be worse.

> Grumpy\_Mike:  
> He should not be using the transistor in this mode anyway.

Actually, while there are the problems with sufficient voltage that I mentioned, using any other mode would make things a lot more complex. You cannot use a PNP transistor here because it would be held ON by the difference between the 6V LED supply and the 5V Arduino supply. You would then have to use an NPN transistor - and more base resistors - to drive it.

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 4, 2015, 9:28pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/11 "2015-11-04T21:28:22Z")

</div>

> You cannot use a PNP transistor here because it would be held ON by the difference between the 6V LED supply and the 5V Arduino supply.

No, get the resistors right and you won't.

---

<div class="post-metadata">

**Author:** ![chairr](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@chairr](https://forum.arduino.cc/u/chairr)\
**Post date:** [November 5, 2015, 5:07am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/12 "2015-11-05T05:07:23Z")

</div>

> Grumpy\_Mike:  
> He should not be using the transistor in this mode anyway.

What do you mean I should not be using them this way? Am I suppose to put the leds somewhere else? What are the risks?

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 5, 2015, 11:31am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/13 "2015-11-05T11:31:32Z")

</div>

> Grumpy\_Mike:  
> No, get the resistors right and you won't.

**Really?**

Care to explain?

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 5, 2015, 5:36pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/14 "2015-11-05T17:36:20Z")

</div>

> Paul\_\_B:  
> **Really?**

Yes really.

You have a 5V swing on the Arduino output and 6V on the PNP's emitter. So you have a pull up from the base to the 6V rail. Then a resistor from base to the Arduino, and a clamping diode from output pin to rail. When the Arduino output is high there is 1V between the output and the emitter. If the potential divider between the two resistors results in a voltage of only say 0.3V between emitter and base of the PNP then the transistor will be off. Only when the Arduino output goes low will the PNP turn on.

But you knew that didn't you.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [November 5, 2015, 7:50pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/15 "2015-11-05T19:50:38Z")

</div>

But you **now** mention a clamping diode.

Yes, **I** certainly did know that, but it was missing from your previous description, wasn't it? So now you are adding more components again and "get the resistors right" was _just a little_ misleading, wasn't it? 😀

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 5, 2015, 8:34pm UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/16 "2015-11-05T20:34:56Z")

</div>

OK. Use a pulldown resistor as well and you can remove the clamping diode. So that is just three resistors, which is "getting your resistors right".  
I am sure you can work that one out.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 2:58am UTC](https://forum.arduino.cc/t/multiple-rgb-leds-controlled-by-transistors/344505/17 "2021-05-06T02:58:35Z")

</div>

Closed on May 6, 2021, 2:58am UTC


