Introduction: ARDUINO UNO - Commom Anode RGB LED 3-colour Blink Using Simple Code

While getting a 3-colour blink from a common cathode RGB LED is simple I found it a bit tedious to get the same result from a common anode one due to my very basic knowledge of the ARDUINO UNO programming. So I figured out a simple circuit using diodes which needs a simple code to run (actually its modified ‘Blink’ example code). All you need is basic information about Arduino UNO. Understanding of basic electronics and simple Arduino Code. So lets get started :)

Step 1: Components Required

(1.) ARDUINO UNO (Or any Arduino UNO Clone)

(2.) Common Anode RGB LED

(3.) 3X220 Ohm Resistor

(4.) 3X Diode

(5.) Breadboardper Cables

(6.) Jumper Cables

Step 2: The Circuit

Connect the Common Anode of the RGB LED to Digital Pin - 8 on the Arduino UNO.

Connect the 3 cathode legs to 220 Ohm resistor and diode as shown in the circuit diagram.

The anode of the diode should be connected to the resistor.

Connect the diode legs to ARDUINO UNO Digital Pins- 5, 6 and 7 respectively.

The circuit is done now head over to the Arduino IDE to type in our code.

Step 3: The Code

void setup() {

// initialize digital pin 5,6,7 & 8 as an output.

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

digitalWrite(5, HIGH);

digitalWrite(6, HIGH);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH); }

// the loop function runs over and over again forever void loop() {

// Here the as pin 8 is common anode

// As pins 5 and 6 are set to HIGH,the diodes connected to

//blue and green LED are in reverse biased condition

//therefore only the Red colour will be seen on the RGB LED

digitalWrite(5, HIGH);

digitalWrite(6, HIGH);

digitalWrite(7, LOW);

digitalWrite(8, HIGH);

delay(500);

// Here the as pin 8 is common anode

// As pins 6 and 7 are set to HIGH,the diodes connected to

//blue and red LED are in reverse biased condition therefore

//only the Green colour will be seen on the RGB LED

digitalWrite(5, LOW);

digitalWrite(6, HIGH);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(500);

// Here the as pin 8 is common anode

// As pins 5 and 7 are set to HIGH,the diodes connected to

//red and green LED are in reverse biased condition

//therefore only the Blue colour will be seen on the RGB LED

digitalWrite(5, HIGH);

digitalWrite(6, LOW);

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

delay(500);

//Further mixture of colours can be produced by switching on any 2 colours at the same time

}