Get your parts ready:
Breadboard
(1) RGB common-anode LED
This part has 3 LEDs (red, green, and blue) in the same package.
(3) 330 Ω resistors (Ω = "ohm" - a unit of resistance)
(6) wires (assorted colors)
Grove Beginner Kit for Arduino
These resistors are connected between the Red, Green, Blue legs of the RGB LED and the Arduino microcontroller output pins.
Insert them into the breadboard ➡
Connect a jumper wire between the 2nd leg of the RGB LED and the "-" (GND) bus on the breadboard.
Use 2 jumper wires to connect the "-" and "+" breadboard connections to the "GND" and "5V" pins on the Arduino microcontroller board ➡
Use 2 jumper wires to connect the resistors to pins 9, 10, and 11 on the Arduino microcontroller.
You can view this circuit diagram design with TinkerCAD. [RGB common-anode LED Arduino]
Next, create a sketch for your RGB LED circuit using either Codecraft or the Arduino IDE, as described in the next sections.
Note that the RGB LED we are using is "common anode," so we set the output to OFF to light the LED!
Create a Codecraft sketch to turn the red/green/blue LED on/off individually and together to make different colors.
Use the "LED state ON/OFF" block as we have used in previous lessons, including Blink the LED
Note that "state OFF" turns ON the LED and
"state ON" turns OFF the LED!
Create a Codecraft sketch that mixes the red, green, blue colors together in some interesting way.
Use "LED set to brightness" block as we have used in the LED Dimmer using PWM lesson.
If you're stuck, here's a sketch you can download and open in Codecraft:
RGB_LED_breadboard.cdc
We use the red, green, blue LEDs together to make different colors, this is "additive color mixing."
Check out this tool to experiment with additive mixing.
Complete: RGB LEDs
You have "common anode" RGB LEDs in your kit, so be sure to follow the
Common Anode instructions.
Instead of using pins 3, 5, 6 for the LEDS, use pins 9,10,11.
(because the Grove Beginner Kit is using pins 3, 5, 6 for other modules.)
Copy the sketch from the bottom of the RGB LEDs page.
Change the pin assignments to match the pins you are using:
const int RGB_RED_LED_PIN = 6; // indicated by orange wire
const int RGB_GREEN_LED_PIN = 5; // indicated by green wire
const int RGB_BLUE_LED_PIN = 3; // indicated by blue wire
const int RGB_GREEN_LED_PIN = 11; // indicated by green wire
const int RGB_BLUE_LED_PIN = 10; // indicated by blue wire
const int RGB_RED_LED_PIN = 9; // indicated by orange wire
In the Coding for both Common Cathode and Anode section, be sure to change this line
const boolean IS_COMMON_ANODE = false;
const boolean IS_COMMON_ANODE = true;
Run the example sketch. Is it working as expected? If not, check your wiring carefully.
Modify the sketch to make a project of your own design.
Consider using one or more of the module in your kit (rotary potentiometer, button, sound, light, temperature & humidity, acceleration modules) as inputs to control the colors/blinking of the RGB LED.
You can also do Lesson 6: Crossfading RGB LEDs