RGB LED With Arduino Uno R3

About: PrimeRobotics is a E-Commerce site, which focus on supplying right products to Electronics Hobbyists, Enthusiast & Students.

Previously we've used the PWM technology to control an LED brighten and dim. In this lesson, we will use it to control an RGB LED to flash various kinds of color. When different PWM values are set to the R, G, and B pins of the LED, its brightness will be different. When the three different colors are mixed, we can see that the RGB LED flashes different colors.

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

Step 2: Principle

RGB LED means red, blue and green LEDs. RGB LED can

emit different colors by mixing the 3 basic colors red, green and blue. So it actually consists of 3 separate LEDs red, green and blue packed in a single case. That’s why it has 4 leads, one lead for each of the 3 colors and one common cathode or anode depending of the RGB LED type. In this tutorial I will be using a common cathode one.

Step 3: The Schematic Diagram

Step 4: ​Procedures

In this experiment, we will also use PWM which, if you’ve followed the lessons thus far, you already have a basic understanding of. Here we input a value between 0 and 255 to the three pins of the RGB LED to make it display different colors. After connecting the pins of R, G, and B to a current limiting resistor, connect them to the pin 9, pin 10, and pin 11 respectively. The longest pin (GND) of the LED connects to the GND of the Uno. When the three pins are given different PWM values, the RGB LED will display different colors.

Step 1:

Build the circuit.

Step 2:

Download the code from https://github.com/primerobotics/Arduino

Step 3:

Upload the sketch to the Arduino Uno board

Click the Upload icon to upload the code to the control board.

If "Done uploading" appears at the bottom of the window, it means the sketch has been successfully uploaded.

Here you should see the RGB LED flash circularly red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple.

Step 5: Code

//RGB
LED

//The RGB LED will appear red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple.

//Email:info@primerobotics.in

//Website:www.primerobotics.in

/*************************************************************************/

const int redPin = 11; // R petal on RGB LED module connected to digital pin 11

const int greenPin = 10; // G petal on RGB LED module connected to digital pin 10

const int bluePin = 9; // B petal on RGB LED module connected to digital pin 9

/**************************************************************************/

void setup()

{

pinMode(redPin, OUTPUT); // sets the redPin to be an output

pinMode(greenPin, OUTPUT); // sets the greenPin to be an output

pinMode(bluePin, OUTPUT); // sets the bluePin to be an output

}

/***************************************************************************/

void loop() // run over and over again

{

// Basic colors:

color(255, 0, 0); // turn the RGB LED red

delay(1000); // delay for 1 second

color(0,255, 0); // turn the RGB LED green

delay(1000); // delay for 1 second

color(0, 0, 255); // turn the RGB LED blue

delay(1000); // delay for 1 second

// Example blended colors:

color(255,0,252); // turn the RGB LED red

delay(1000); // delay for 1 second

color(237,109,0); // turn the RGB LED orange

delay(1000); // delay for 1 second

color(255,215,0); // turn the RGB LED yellow

delay(1000); // delay for 1 second

color(34,139,34); // turn the RGB LED green

delay(1000); // delay for 1 second

color(0,112,255); // turn the RGB LED blue

delay(1000); // delay for 1 second

color(0,46,90); // turn the RGB LED indigo

delay(1000); // delay for 1 second

color(128,0,128); // turn the RGB LED purple

delay(1000); // delay for 1 second

}

/******************************************************/

void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function

{

analogWrite(redPin, red);

analogWrite(greenPin, green);

analogWrite(bluePin, blue);

}

/******************************************************/

Step 6: Code Analysis

Step 7:

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions