In this tutorial, we will learn how to interface an RGB led with Arduino.
An RGB led consist of three Led’s namely red, green and blue inside a single package.
It is having three pins the longer one(2) is the GND(in the case of the common cathode) and the other three pins represent the three colours.
You all must have heard about the RGB colour model, it is a model representing the colours that can be generated with the combination of three basic colours.
Now let’s interface the led and have some fun with it.
Components required
- Resistor 1No. 200 ohms
- RGB led 1No.
- Arduino UNO 1No.
- Few connecting wires
int led1 = 3;
int led2 =5;
int led3 =6;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop()
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop()
{
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
}
The above code is to observe the basic colours; other combinations can also be generated.
Now apply your own logic and try to generate your own patterns.
The common cathode (which we have used in the tutorial)
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
digitalWrite(led2, HIGH);
delay(1000);
digitalWrite(led2, LOW);
delay(1000);
digitalWrite(led3, HIGH);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
digitalWrite(led3, LOW);
delay(1000);
}
The above code is to observe the basic colours; other combinations can also be generated.
Now apply your own logic and try to generate your own patterns.
- RGB LEDs are of two types:
The common cathode (which we have used in the tutorial)
Thinking?
Join our hands-on training courses.
To know more visit us at https://karkhana.club/
Comments