1

This bug/stupidity-of-myself/problem is killing me:
I'm have created an RGB strip controller that cycles through the additive-rgb-color spectrum while turning a potentiometer.

I have a pot hooked up to my Arduino Nano v3 (from AZ-Delivery, not official Arduino). Then I have an RGB amplifier hooked up to the Arduino with each phase (R, G, B, V+) and to an external power supply (12V by 2A max).

I shortened my program and removed all the value-to-colour-conversion because that has nothing to do with the problem:

void loop() {
    ColorVal = analogRead(pinPot); //read value of color poti
    ColorByte = map(ColorVal, 0, 1023, 0, 255); //Scales 0-1023 to 0-255

    // potvalue to color conversion
    // ...

    // write via PWM to LED
    analogWrite(pinR, R);
    analogWrite(pinG, G);
    analogWrite(pinB, B);
}

My problem: Theoretically you would expect the system to show white when all variables (R, G and B) are set to 255. However, it behaves the other way around. When all values are set to 255 it's off and vice versa. Another example: When R = 255 and G = 0 and B = 0 Green and Blue are lighting and Red is off.

I thought this has to do with polarity or something but I cannot seem to find it out.

1 Answer 1

2

The RGB LED strip has a common anode (V+). When you put 12 V on R, G or B, the LEDs have 12 V on both sides, so there is no voltage across it and no current.

And if you put 0 V, they have 12 V across it and light up.

To fix it, just invert the PWM value in your code:

analogWrite(255-pinR, R);
analogWrite(255-pinG, G);
analogWrite(255-pinB, B);
1
  • Man, I love you. Thank you so much. The physical explanation makes it even more reasonable.
    – Max
    Jun 5, 2018 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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