Creating a RGB LED Arduino Circuit

by YoussefMosalam in Circuits > Arduino

51 Views, 0 Favorites, 0 Comments

Creating a RGB LED Arduino Circuit

IMG_2913.jpg

In this tutorial set, we will be instructing on how to program and hardwire a RGB LED Arduino Circuit. This instruction set will include steps on how to program code onto an IDE using Arduino, as well as working with different components on an Arduino Board. This will allow us to have a functional RGB LED light circuit that can be personalized with patterns or to the creator's liking.

Supplies

A000066_03.front_1200x900.jpg
arduino-ide-2-1-0-serial-montior-enh.jpg

Here is a list of required materials needed to construct the device (Including links to appropriate markets to buy them from):


3x 220 Ω Resistor (13.87 CAD)

1x Arduino Uno Board (42.05 CAD)

1x Breadboard (24.40 CAD)

4x Jumper Wires (31.95/Set CAD)

1x RGB LED (19.95 CAD)

1x USB Cable Type A to B (10.04 CAD)



You will also need to install Arduino's IDE software so that you can program coding that will allow the circuit to recognize and execute (A guide is linked below on how to download and set up the IDE)

"Setting up Arduino IDE"

Connecting Resistors and Wires

IMG_2912.jpg


First, place the RGB LED towards the breadboard and connect the short end (cathode) to a row on the board. Afterwards, connect the three long legs to different rows that are juxtapose to each other so that you can position the Jumper wires (Male to Male).

Afterwards, connect the 3x 220-Ohm resistors to the breadboard. It should be important that each resistor should be aligned to one of the corresponding wires (each row) to provide proper connection.



Reassuring the Wires

Screenshot 2025-01-26 135328.png

The wires that have been aligned with the resistors should look like this diagram above. Make sure that each jumper wire is in its own row to allow proper connection and the resistors as well. If it doesn't look similar to the diagram above, or the resistors are not aligned with the wires themselves, please make sure to redo step 1 and check if the wires are connected to the LED and the resistors are align.

This step is important as proper connection allows for the flow to be secured as you will have to place these measures on the Arduino board



Wire to the Arduino Board

IMG_2910.jpg

After securing the wires and resistors, take the last jumper wire and connect it first to the common cathode of the RGB and the other side to the ground pin on the Arduino Board. Typically this is the wire that is solo and connects to the Board itself instead of the other wires which will connect to the numbered ports.


Connecting to the Ports:

Make sure that on the Arduino Board, the wire is connected to the GND port (on the Arduino Board) located on the right of the reset button in order to properly secure the wire. This will allow a returning path of electricity back to the source and provide power to the LED. Make sure on the breadboard, the Arduino wire is connected to its own row.



Entering Code

Screenshot 2025-01-26 153605.png

Colour Function:

After place the wires in the corresponding place, open the Arduino Software and IDE and begin to enter the first set of code (lines 1-3) into the terminal as shown above. You will have to create a new File by clicking on "File" and then "New". The functions of "redPin, greenPin, and bluePin" should be replaced with the number that the LED is connected to on the Arduino.


Delay and Timing:

Afterwards, you will create a loop function and add the following lines of code from the second set (lines 6-9. This will set a delay timer and allow for certain loops of color to be allowed. You will do this for the other functions "greenPin" and "bluePin"



Connecting the Jumper Wires to the Port

IMG_2910.jpg
IMG_2910.jpg

Next, you will take the corresponding jumper wires, and connect them to ports D5, D6, and D7. Make sure you correspond the wire in the appropriate places.



Connecting to a power source (laptop)

This will allow us to change colors with the LED but also give power to the wires itself from the computer bank. The

type A to type B cable that we bought will come in use. First, take the Type A side and plug it in into your laptop or

computer used to program the Arduino Board. Afterwards, you take the Type B cable and place it into the Type B port

on the Arduino Board. Thus, their is a connect direction to both power and IDE



AEK-CH2-SC2.1-ARDUINO-IDE.png

After ensuring the Arduino is calibrated with coding, you will then code the alternating function of the LED. This will allow the LED to change colors, turn off the LED itself, and delay so that you can have a pattern. You will create functions that will allow for sets to be defined and thus not have to change the LED manually.


const int PIN_RED = 5;
const int PIN_GREEN = 6;
const int PIN_BLUE = 7;

void setup() {
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
}

void loop() {
/ / color code #00C9CC (R = 0, G = 201, B = 204)
setColor(0, 201, 204);
delay(1000); // keep the color 1 second

/ / color code #F7788A (R = 247, G = 120, B = 138)
setColor(247, 120, 138);
delay(1000); // keep the color 1 second

/ / color code #34A853 (R = 52, G = 168, B = 83)
setColor(52, 168, 83);
delay(1000); // keep the color 1 second
}

void setColor(int R, int G, int B) {
analogWrite(PIN_RED, R);
analogWrite(PIN_GREEN, G);
analogWrite(PIN_BLUE, B);
}


Changing the delay will allow for changes in the time frame for transitioning between colours.

The analogWrite function allows for setting colors, whilst the delay(n) variable sets the number set of delay between colours

We set up the loop structure so that the colors do not repeat itself or crash, thus giving us the transitioning facade.


Implementation:

Enter the code and select Arduino UNO in the port menu

Always execute and run the code to find any syntax or bug errors

Upload the code onto the Arduino through the IDE and power on.



LED Fun

IMG_2907.jpg
IMG_2911.jpg

After following Steps 1-6, you should now have a wired and functioning RGB-LED light system. If you can, you can buy other colours and implement more fun with the lights themselves or change the order in which the light shine


Enjoy your lights!