0


I am using PWM (analogWrite) with a common anode LED. My previous experience is using a common cathode. My breadboard is as shown:

schematic

simulate this circuit – Schematic created using CircuitLab

This creates a semi-bright white (ugly red-green-blue mixture) like I expected. I am using only one PWM output (It is currently fading).

Now, what I ask is how can I use multiple PWM outputs to make different colors display without transistors? I was thinking that I could have 3 dedicated pins on the Arduino that switch from ground to floating extremely fast, but is there an easier way? If not, a little explanation on how to do it with transistors (mostly just a small wiring diagram) would be great. Cheers!

2

As long as each LED in the array uses 20mA or less you can do it directly with the Arduino:

schematic

simulate this circuit – Schematic created using CircuitLab

Note that the blue LED will have a higher forward voltage than the red and green ones, hence the lower resistor.

Also note that the PWM will be inverted. Writing 255 to a channel will switch that LED off, while writing 0 will give it full brightness.

  • Why exactly does this work? Also, does the PWM pin mode need to be input? Thanks! – Blake Feb 23 '17 at 0:02
  • A PWM pin cannot be input - that makes no sense. It works because when a pin is an output (as in when you are using PWM, or just simple digitalWrite()) it is either connected to +5V or to GND. When on +5V there isn't enough voltage difference across the LED for it to light. When it's connected to GND there is 5V across the LED and the resistor, making the LED light up. – Majenko Feb 23 '17 at 0:04
  • @Blake I keep meaning to make a video tutorial describing exactly how a GPIO pin on a device like an Arduino actually works. It would show you instantly how this arrangement can work. Maybe I will get round to it over the next day or so. – Majenko Feb 23 '17 at 0:23
  • I get it now! I was doubting to ask if it was an input anyway, like you said, that would make no sense. I just didn't know that is was 5V or to GND, thanks! – Blake Feb 23 '17 at 0:30
1

I am using only one PWM output (It is currently fading).

use three independent pwm channels to drive three leds.

how can I use multiple PWM outputs to make different colors display without transistors?

the answer depends on the leds. for leds that require small current, it is totally doable, just connect the pwm output to them.

for leds that require lots of current, no solution.

  • I agree with this, but why would you say that there is no solution for high-current LEDS? Would it be different if it was a common-cathode LED? I mean, if not, I understand. – Blake Feb 23 '17 at 2:54
  • There is indeed a solution for high-current common-anode RGB LEDs: use a transistor driven by the PWM pins. For example: electronics.stackexchange.com/a/64623, or electronics.stackexchange.com/a/241384 . – Seth P Jan 7 '18 at 21:09

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.