RGB LED

A RGB LED is a LED which integrates 3 LEDs of different colors (red, green, and blue) into one. As a conventional LED, it will light up by connecting the anode (+) to a voltage source (for example 3.3V) and the cathode (-) to the ground with a proper resistor. A common-anode LED has a common athode, which is the pin 1 in the schematic diagram:

As a result, connecting the pin 1 to a 3.3V power source and the pin 2, 3, or 4 to the GND (with a proper resistor), you'll see the blue, green, or red LED light up as desired. Moreover, you can connect the pin 2, 3, and/or 4 to PWM pins to make different levels of voltage go through the LED. This can give more combinations of RGB intensities and thus emits different colors. Here is an example:

  • Connect the common anode (the longest pin of the RGB LED) to a 3V3 pin

  • Connect Red, Green, and Blue pins to P17, P16, and P15, respectively, with 1KΩ resistors placed in between

Load the sketch code into the Arduino IDE:

After clicking the Upload button to upload the codes to the board, you'll see the LED keeps changing its color over time.

Last updated