Project tutorial
Interfacing Arduino Uno with RGB led

Interfacing Arduino Uno with RGB led © GPL3+

In this tutorial we are going to see how to interface Arduino Uno with RGB led. So let's start !!!

  • 353 views
  • 0 comments
  • 0 respects

Components and supplies

Apps and online services

About this project

First we need to know what is meant by a RGB led ?

A RGB led is a combination of blue led, green led and red led. It is also called tri-color or multicolor led. With this led obviously you will able to produce the red, green and blue and you can also produce different colors by configuring the intensity of each led. The first picture shows an simple RGB led and the second one is RGB led module :

if (typeof(lightBoxImages) == 'undefined') { lightBoxImages = {}; } lightBoxImages['a8cb34014a'] = [{ URL: 'https://hackster.imgix.net/uploads/attachments/1307934/image_t0ieFzDyHb.png?auto=compress%2Cformat&w=1280&h=960&fit=max', caption: 'RGB led ', type: 'image' }];

if (typeof(lightBoxImages) == 'undefined') { lightBoxImages = {}; } lightBoxImages['2aa18b142e'] = [{ URL: 'https://hackster.imgix.net/uploads/attachments/1307935/image_2VIbmsA2eR.png?auto=compress%2Cformat&w=1280&h=960&fit=max', caption: 'RGB sensor module ', type: 'image' }];

A RGB led has four pins namely Green pin, Blue pin, Red pin and Cathode ( - ). The cathode is considered as the negative pin and it is connected to the ground of the system. Other three pins control their individual colors.

if (typeof(lightBoxImages) == 'undefined') { lightBoxImages = {}; } lightBoxImages['af2b620330'] = [{ URL: 'https://hackster.imgix.net/uploads/attachments/1307937/untitledrjb_ledhj_daz3mvKoGC.png?auto=compress%2Cformat&w=1280&h=960&fit=max', caption: 'Pin diagram of RGB led', type: 'image' }];

Now we can start the connections :

Green pin to D13 to Arduino

Blue pin to D3 pin of Arduino

Red pin to D5 pin of Arduino

Cathode ( - ) to the Gnd of Arduino

if (typeof(lightBoxImages) == 'undefined') { lightBoxImages = {}; } lightBoxImages['fac309183c'] = [{ URL: 'https://hackster.imgix.net/uploads/attachments/1307940/editing_components_(1)_uKwkPgIve0.png?auto=compress%2Cformat&w=1280&h=960&fit=max', caption: 'Circuit diagram of RGB led ', type: 'image' }];

The circuit diagram, images and references are uploaded in the hardware section. Here is the code :

// Interfacing RGB led with Arduino Uno
int redPin = 5;// Red pin to digital pin 5 of arduino
int greenPin = 12;// Green pin to digital pin 12 of arduino
int bluePin = 3;// Blue pin to digital pin 3 of arduino
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE 
void setup()
{
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);  
}
void loop()
{
 setColor(255, 0, 0);  // red
 delay(1000);
 setColor(0, 255, 0);  // green
 delay(1000);
 setColor(0, 0, 255);  // blue
 delay(1000);
 setColor(255, 255, 0);  // yellow
 delay(1000);  
 setColor(80, 0, 80);  // purple
 delay(1000);
 setColor(0, 255, 255);  // aqua
 delay(1000);
}
void setColor(int red, int green, int blue)
{
 #ifdef COMMON_ANODE
   red = 255 - red;
   green = 255 - green;
   blue = 255 - blue;
 #endif
 analogWrite(redPin, red);
 analogWrite(greenPin, green);
 analogWrite(bluePin, blue);  
}

To create more colors with RGB led we need to set the intensity of each internal LED and combine the three color outputs. We are going to use PWM to adjust the intensity of the red, green, and blue LEDs individually and the trick here is that our eyes will see the combination of the colors, instead of the individual colors because the LEDs are very close to each other inside. This is the color chart of RGB led :

if (typeof(lightBoxImages) == 'undefined') { lightBoxImages = {}; } lightBoxImages['3a389bbd8e'] = [{ URL: 'https://hackster.imgix.net/uploads/attachments/1307945/image_naPAubXLRn.png?auto=compress%2Cformat&w=1280&h=960&fit=max', caption: 'RGB led color chart', type: 'image' }];

Code

Code C/C++
This is the code for interfacing Arduino Uno with RGB led.
// Interfacing RGB led with Arduino Uno
int redPin = 5;// Red pin to digital pin 5 of arduino
int greenPin = 12;// Green pin to digital pin 12 of arduino
int bluePin = 3;// Blue pin to digital pin 3 of arduino

//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE 

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);  
}

void loop()
{
  setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 255, 0);  // green
  delay(1000);
  setColor(0, 0, 255);  // blue
  delay(1000);
  setColor(255, 255, 0);  // yellow
  delay(1000);  
  setColor(80, 0, 80);  // purple
  delay(1000);
  setColor(0, 255, 255);  // aqua
  delay(1000);
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

Schematics

Circuit diagram
This is the circuit diagram for interfacing Arduino Uno with RGB led.
Editing components (1) iil4lqyogo
Pin diagram
Pin diagram of RGB led
Untitledrjb ledhj 21irlzw3op
Image
Img 20210605 wa0044gh w3oc3o67tq
Image
rgb_led_2_5sq9ckHxS7.jfif

Comments

Similar projects you might like

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO

Project tutorial by Giovanni Gentile

  • 12,851 views
  • 1 comment
  • 20 respects

How to Use an RGB LED

by MisterBotBreak

  • 13,525 views
  • 6 comments
  • 26 respects

LED Emergency Lights using WS2812 RGB LED Module

Project tutorial by bigboystoys13

  • 24,771 views
  • 10 comments
  • 43 respects

RGB LED Snowflake with Arduino Uno

Project in progress by James Cameron

  • 17,426 views
  • 8 comments
  • 35 respects

Controlling an RGB LED with Color Detector Camera

Project tutorial by Zowail

  • 4,268 views
  • 0 comments
  • 2 respects

Interfacing Arduino UNO with SURE Electronics LED Dot Matrix

Project tutorial by Arduino_Scuola

  • 6,958 views
  • 1 comment
  • 3 respects
Add projectSign up / Login