Electrical – Issues with NPN Transistors and RGB LEDs (Common Anode)

arduinolednpnrgb

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.

Best Answer

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.