1
\$\begingroup\$

I have a question regarding the use of NPN transistors in an RGB LED (common anode) circuit connected to an Arduino Uno. I have spent the past several months developing LED color control software that communicates over serial to an Arduino board, which then produces color in LEDs over three PWM pins (a fairly common setup). I am now ready to install 10 LEDs instead of the single LED I was using during the testing process. I came across this Fritzing diagram in a solution, and have built the circuit with my NPN transistors and two LEDs to start.

Here are my issues:

  1. Typically in common anode setups, writing a value of 255 to a PWM pin indicates OFF and writing 0 is full brightness. These controls seem to be inverted now with 0 being OFF. Is this normal behavior?

  2. The brightness steps are out of control. Writing 1 to a RGB pin creates a fairly bright light, and anything above 3 is maximum brightness. For my color reproduction to be effective, I need at least 100 brightness steps as I had in my previous setup where only 1 LED was used and no NPN transistors were in the circuit.

Have I overlooked some aspect of NPN transistor electronics? I definitely am in need of guidance. I have only gotten into LED electronics recently and have a lot of learning to do.

Fundamentally, I need a circuit that will allow 10 common anode RGB LEDs to be controlled as a group by three Arduino PWM pins.

\$\endgroup\$
  • \$\begingroup\$ Without your component values (transistor types, resistor values), schematic, or even a picture of your setup it's hard to say. I'm guessing you are missing either the base resistor, using a mosfet and not a NPN transistor, or something. But as for the 0 = off, yes, thats normal. You are controlling the transistor, NOT sinking current through the GPIO directly. \$\endgroup\$ – Passerby Jun 16 '16 at 18:54
  • \$\begingroup\$ My schematic is the diagram linked to minus two of the LEDs and their connecting wires. My transistor is MPS2222A TO-92. I have a variety of resistors available and have been changing them out thinking it may have been an issue with them. Is there a specific resistor value you recommend? The LEDs are these guys link \$\endgroup\$ – KentAshfield Jun 16 '16 at 19:03
  • \$\begingroup\$ You can only write a 0 or 1 to a digital output pin. You write the 0 - 255 PWM values to a PWM control register. The PWM logic in the microcontroller will write 0 or 1 to the output pin as required by the PWM timing. \$\endgroup\$ – Peter Bennett Jun 16 '16 at 19:27
  • \$\begingroup\$ correct @PeterBennett, my bad for using unclear language. In the IDE, values of 0 to 255 are physically written but in actuality that just indicates timing for writing 0 or 1. The point I was trying to make was that observed behavior reversed when I changed the circuit, but I now understand that is normal behavior. I now need to figure out if there are better resistors to use. \$\endgroup\$ – KentAshfield Jun 16 '16 at 19:33
  • \$\begingroup\$ On the AdaFruit page you linked in your comment, there is a tutorial on using LEDs. You should probably look through that, as it discusses determining resistor values, among other related topics. \$\endgroup\$ – Peter Bennett Jun 16 '16 at 22:46
1
\$\begingroup\$

Thanks for not posting the Fritzing diagram as they drive some of the regulars here apoplectic. There's a schematic button on the editor toolbar if you want to sketch something out for appraisal.

Typically in common anode setups, writing a value of 255 to a PWM pin indicates OFF and writing 0 is full brightness. These controls seem to be inverted now with 0 being OFF. Is this normal behavior?

0 is normally off. 1 is on. 100% PWM would be "on all the time". You can think of it as the % time power is applied.

The brightness steps are out of control. Writing 1 to a RGB pin creates a fairly bright light, and anything above 3 is maximum brightness. For my color reproduction to be effective, I need at least 100 brightness steps as I had in my previous setup where only 1 LED was used and no NPN transistors were in the circuit.

It sounds as though there's something wrong with your PWM output configuration or code. Post the relevant bits in your question and be sure to use the "code" tag.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. Q1 lights the red channel. Triplicate for green and blue.

\$\endgroup\$
0
\$\begingroup\$
  1. Yes, this is normal. An NPN is "positive logic" i.e. 1 is on, by connected the LED's cathode to ground. If you were directly connecting the LED to your GPIO pin, you would need to provide the ground by writing the pin itself to 0.

  2. I would try increasing your current limiting resistor to increase the brightness steps.

\$\endgroup\$
  • \$\begingroup\$ Do you have a recommended resistor value for RGB LEDs? I have access to several and could purchase others if needed. \$\endgroup\$ – KentAshfield Jun 16 '16 at 19:06
  • \$\begingroup\$ @jim: decreasing the resistor value is more likely to increase the brightness. \$\endgroup\$ – Peter Bennett Jun 16 '16 at 22:38
  • \$\begingroup\$ @KentAshfield: there are many questions on here regarding LED resistor calculations, and some websites that will do the claculation for you - it is a simple application of Ohm's Law. \$\endgroup\$ – Peter Bennett Jun 16 '16 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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