Electronic – arduino – RGB LED inverted logic Arduino

arduinodigital-logicledrgb

Arduino sketch for my program

I followed this instruction, but I found that it doesnot work (the RGB LED is off).
So, instead of connecting the long leg of RGB LED to ground (-), I connect it to the 5V source (+). And, it works.
But, it does not work as expected. Then, I figure out that the Logic (HIGH/LOW) is somehow inverted, so I invert the logic in my program and it works as expected.
My question is why does that happen?

Best Answer

In a common cathode LED, the common lead goes to the ground. The three individual colours are taken high to turn them on. That's positive logic.

In a common anode LED, the common lead is the positive, so is taken to +5V. The individual colours must now be taken low to turn them on. That's negative logic. It's not a function of the Arduino, it's a function of the LED and its connection.