semsemharaz
Published

Interfacing RGB Led with Arduino

In this project, we will learn how to interface RGB LED with Arduino Uno. The RGB LED is controlled by PWM signals.

BeginnerProtip1,089
Interfacing RGB Led with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
RGB Diffused Common Anode
RGB Diffused Common Anode
×1
Resistor 220 ohm
Resistor 220 ohm
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic for the project

Code

Code

C/C++
// *Interfacing RGB LED with Arduino 
// * Author: Osama Ahmed 

//Defining variable and the GPIO pin on Arduino
int redPin= 5;
int greenPin = 6;
int bluePin = 7;

void setup() {
  //Defining the pins as OUTPUT
  pinMode(redPin, OUTPUT);              
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}
void loop() {
  setColor(255, 0, 0); // Red Color
  delay(1000);
  setColor(0, 255, 0); // Green Color
  delay(1000);
  setColor(0, 0, 255); // Blue Color
  delay(1000);
  setColor(255, 255, 255); // White Color
  delay(1000);
  setColor(170, 0, 255); // Purple Color
  delay(1000);
  setColor(127, 127, 127); // Light Blue
  delay(1000);
}
void setColor(int redValue, int greenValue, int blueValue) {
  analogWrite(redPin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}

Credits

semsemharaz
6 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.