What is RGB LED?
1.Introduction
In this project, we will introduce the RGB LED and show you how to use the Plus control board to control the RGB LED. Even though RGB LED is very basic, it is also a great way to learn the fundamentals of electronics and coding.
2.Components Required
|
|
|
|
|
|
---|---|---|---|---|---|
Keyestudio Plus Mainboard*1 |
RGB LED*1 |
220Ω Resistor*3 |
Breadboard*1 |
Jumper Wires |
USB Cable*1 |
3.Component Knowledge
RGB LED:
The monitors mostly adopt the RGB color standard, and all the colors on the computer screen are composed of the three colors of red, green and blue mixed in different proportions.
This RGB LED has pin R, G and B and a common cathode. To change its brightness, we can use the PWM pins which can give different duty cycle signals to the RGB LED to produce different colors.
4.Circuit Diagram and Wiring Diagram
Note:
RGB LED longest pin (common cathode) connected to GND.
How to identify the 220Ω 5-band resistor
5.Code
/*
RGB LED
http//www.keyestudio.com
*/
int redpin = 11; // select the pin for the red LED
int bluepin =9; // select the pin for the blue LED
int greenpin =10;// select the pin for the green LED
int val;
void setup() {
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
}
void loop()
{
for(val=255; val>0; val--)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
for(val=0; val<255; val++)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
}
6.Result
Upload the project code, wire up, power up and wait a few seconds, you will see a colorful LED.