Introduction
Today we will program RGB LED using Arduino.
RGB stands for Red, Green, and Blue color (which combine to form millions of other colors using these three colors.)
In this Arduino project, we will glow the RGB LEDs based on the color code programmed. The components can be either purchased online or offline as per convenience, or online projects can also be made using the Tinkercad website.
Supplies
In order to program RGB LED using Arduino, we will require the following components:
Components
- Arduino Uno R3
- 1 RGB LED
- 3 Resistors
- Connecting wires
Circuit Diagram
Steps To Program RGB LED Using Arduino
Step 1: Gather all the components on the Digital Board or Physical Table.
Step 2: Connect the Cathode terminal of the RGB LED to the GND pin of the Arduino.
Step 3: Connect the other three terminals of the RGB LED to pin numbers 11, 12, & 13 of the Arduino thru resistors.
Source Code
void setup() { pinMode(11, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT); } void loop() { analogWrite(11, 0); analogWrite(12, 0); analogWrite(13, 255); delay(1000); analogWrite(11, 255); analogWrite(12, 0); analogWrite(13, 0); delay(1000); analogWrite(11, 255); analogWrite(12, 255); analogWrite(13, 0); delay(1000); analogWrite(11, 255); analogWrite(12, 0); analogWrite(13, 255); delay(1000); }
Explanation of the Code
1. We are using two different functions in this code: setup & loop.
2. In the setup function, we are declaring that we will be using pin numbers 11, 12 & 13 for Output Purposes.
3. In the loop function, we are using the color code in different pins for 1 second of time.
4. These color codes are prebuilt. For example, to get the color red in the LED, we need to use 0, 0, 255.
5. For Green color, it is – 255, 0, 0, similarly for Blue, it is – 255, 255, 0, and so on.
6. We are using a delay function, which takes time in milliseconds.
7. Since this is a loop function, our code inside this will keep on looping until and unless we click on either stop simulation or turn off the Arduino.
Output
We will get the following output on the successful completion of the Arduino project.
We have used 4 colors in this single LED, so it will glow for 1 second of time for each color that we have programmed. That is, in this series – Red, Green, Blue, and Yellow. …RGBYRGBY…

Cisco Ramon is an American software engineer who has experience in several popular and commercially successful programming languages and development tools. He has been writing content since last 5 years. He is a Senior Manager at Rude Labs Pvt. Ltd.
0 Comments