electronicsfan123
Published © GPL3+

Interfacing Arduino Uno with RGB led

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

BeginnerFull instructions provided1,862
Interfacing Arduino Uno with RGB led

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

This is the circuit diagram for interfacing Arduino Uno with RGB led.

Pin diagram

Pin diagram of RGB led

Image

Image

Image

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);  
}

Credits

electronicsfan123

electronicsfan123

5 projects • 8 followers

Comments