RGB Example

RGB Example

The RGB is a Led that can produce three different light signals: Red(R),Green(G), Blue(B). It is formed from four pins and it can have two different configurations: common cathode and common anode. In this example is used a RGB common Cathode and it will realize a sketch to switch on the led Red,Green and Blue alternately.

Hardware Required

Arduino Board

common cathode RGB

Wires

Breadboard

3 resistors of 220 Ω

Circuit

Connect the first pin (R) from flat side to a resistor of 220 Ω and to Pin 2 of the board, connect the second (cathode), usually is longer than others pins, to ground (GND) of the board, connect the third pin (G) to a resistor of 220 Ω and to Pin 3 of the board and finally connect the fourth pin (B) of RGB to a resistor of 220 Ω and to Pin 4 of the board.

Schematic

Code

The code defines with red, green, blue the RGB pins. It is created a function called Led_on to switch on the singles Leds. In the setup red, blue and green are defined as OUTPUT pins. In the loop is called the function Led_on and every second is changed the parameter supplied to the function, so it changes the led on. NOTE: When you use a RGB common cathode if you want to switch on the led you must write HIGH, if you want to switch off you must write LOW, instead when you use a RGB common anode you must write in opposite mode.