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

7,185

15

4

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 :)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

}

Share

    Recommendations

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    4 Discussions

    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.

    2 replies
    0
    None
    AlexS170Lectric Wizard

    Reply 3 years ago

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

    0
    None
    ashishalhLectric Wizard

    Reply 4 years ago

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