SALES INQUIRIES: 1 (888) 767-9864

Using Red-Green-Blue (RGB) LEDs with Arduino (Common Cathode Type)

In this tutorial we describe using RGB LEDs of the Common Cathode Type.  We will describe setting up the circuit, talk about the LED and discuss the code used to adjust the hue.

4 Comments

  1. Avatar patrickd314 on November 24, 2016 at 6:15 pm

    Careful, viewers: The schematic omits the series resistors (which were included on the breadboard.)

  2. Avatar Sravan Mutharasu on March 14, 2017 at 9:11 am

    Weird! I followed everything to the dot. However, connecting the ground pin to the ground lead of the RGB LED doesnt turn on the LED, but not connecting the ground pin to one of the leads of R,G turns the LED On.. I suppose the RGB LED is broken?

  3. Avatar Andi1356 on July 20, 2019 at 9:04 pm

    why did’t you declared the variable in the setup and initialized it with 0. This way the program won’t declare a variable every time in the loop.

    • Avatar Michael James on July 21, 2019 at 8:23 am

      The reason I chose to do that is for variable scope. If a variable is declared in the setup(), it can only be used within setup().

      If a variable is declared outside of setup() and loop(), it can be used (changed and referred to) anywhere in the program, this property is called global scope. In most small Arduino programs, using variables with global scope is not that big of an issue, however, as program size and complexity grows, using variables of global scope can increasingly become hard to debug. By declaring the variable inside loop(), I am limiting its scope to loop(). It is pretty trivial in this example, because the program is so small, but that is how I chose to do it. I hope this helps answer your question.

Leave a Comment