Possible to wire common anode RGB LED or reverse polarity?

Today I stopped down at the hardware store, and picked up a RGB LED which appeared to be unlabled, but turned out to be a common anode after an hour of trial and error figuring out and learning from my mistakes.
I’ve googled around a bit, but haven’t found much of any use of the results.

Is it possible to wire this particular LED to the Photon and use analogWrite() to change the colors, or even if possible to reverse the polarity of the specified PWM pins on the board?


Yes you can use common anode LEDs with the Photon’s PWM pins, you just need to invert your PWM duty cycle (0…LED full brightness, 255…LED off).
Or you add an inverting transistor (grounded emitter circuit) or similar external circuitry.

For direct control you’d wire the LED like this

PWM pin -> current limiting resistor -> LED -> 3V3 pin.

1 Like

Thanks for the explanation, I’ll test it out and be sure to get back to you on how it works or if I have any more issues.

Here is my current wiring configuration:

I have adjusted my code to the following to represent inverted values:

void ledExecute() {
    analogWrite(PIN_R, 255 - pwm_red);
    analogWrite(PIN_G, 255 - pwm_green);
    analogWrite(PIN_B, 255 - pwm_blue);
    RGB.color(pwm_red, pwm_green, pwm_blue); //Change the color of the on-board LED.

However, the LED still will not light up. Am I performing something wrong?

Have you read this

Sorry, forgot all about that! will fix.

Works flawless!
Thank you very much!

1 Like