Arduino Project
RGB Module
Course Introduction
In this lesson, we will learn how to use the RGB LED Module with Arduino.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Wiring

Common Connections:
RGB LED Module
R: Connect to 11 on the Arduino.
G: Connect to 10 on the Arduino.
B: Connect to 9 on the Arduino.
-: Connect to GND on the Arduino.
Writing the Code
Note
You can copy this code into Arduino IDE.
Don’t forget to select the board(Arduino UNO R4 Minima) and the correct port before clicking the Upload button.
/*
This code initializes an RGB LED module and displays the primary colors of red, green, and blue.
It then proceeds to display the seven colors of the rainbow in sequence.
Board: Arduino Uno R3 (or R4)
Component: RGB LED module
*/
// Pin numbers for each color channel
const int rledPin = 11; // pin connected to the red color channel
const int gledPin = 10; // pin connected to the green color channel
const int bledPin = 9; // pin connected to the blue color channel
void setup() {
pinMode(rledPin, OUTPUT);
pinMode(gledPin, OUTPUT);
pinMode(bledPin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Set RGB LED color to red
delay(1000);
setColor(0, 255, 0); // Set RGB LED color to green
delay(1000);
setColor(0, 0, 255); // Set RGB LED color to blue
delay(1000);
// Display the colors of the rainbow
setColor(255, 0, 0); // Set RGB LED color to red
delay(1000);
setColor(255, 165, 0); // Set RGB LED color to orange
delay(1000);
setColor(255, 255, 0); // Set RGB LED color to yellow
delay(1000);
setColor(0, 128, 0); // Set RGB LED color to green
delay(1000);
setColor(0, 0, 255); // Set RGB LED color to blue
delay(1000);
setColor(75, 0, 130); // Set RGB LED color to indigo
delay(1000);
setColor(230, 130, 238); // Set RGB LED color to violet
delay(1000);
}
void setColor(int R, int G, int B) {
// Set the intensity of the red color channel
analogWrite(rledPin, R);
// Set the intensity of the green color channel
analogWrite(gledPin, G);
// Set the intensity of the blue color channel
analogWrite(bledPin, B);
}
