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

Picture of 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

Picture of 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

Picture of 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

}

Comments

kavish laxkar (author)2016-05-12

SIMPLE

Lectric Wizard (author)2015-03-23

Why did you use D8 as the anode? You could connect it to +5v and eliminate the diodes & having to write the highs to pin 8.

AlexS170 (author)Lectric Wizard2015-12-16

could you make a page on how to do it without the diodes? And use the +5V?

ashishalh (author)Lectric Wizard2015-03-24

Absolutely right, but the pin 8 will be handy in case we want to switch off the led in between two colours.

About This Instructable

2,249views

15favorites

License:

More by ashishalh:ARDUINO UNO - Commom Anode RGB LED 3-colour Blink Using Simple CodeARDUINO UNO - Commom Cathode RGB LED 3-colour Blink Using Simple Code
Add instructable to: