Trending

How to control RGB LED using Arduino

Introduction

What is an RGB LED?

An RGB LED is a 4 terminal light emitting diode, the 3 pins are for 3 different colors(Red, Green, and Blue) and the fourth pin is a common cathode. It is made by combining 3 different colored LEDs and can be used to create any type of color by altering the brightness of each LED.

Components required

  1. Arduino Board (Obviously )
  2. RGB LED ( Common cathode)
  3. Resistance ( optional)
  4. Connection wires and PCB/Breadboard

Circuit Schematics

Note- As a safety precaution, add a 220 Ohm resistor between the GND pin of arduino and the cathode of the LED.


Connections

LED's Cathode (-) to GND
LED's Anode red (+) to Pin 8
LED's Anode green (+) to** Pin 9**
LED's Anode blue (+) to Pin10
Note - Using PWM pin is recommended , so to control brightness of each colour .

Code

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}
void loop() {
  digitalWrite(8, HIGH); 
  delay(1000);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH); 
  delay(1000);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH); 
  delay(1000);
  digitalWrite(10, LOW);          
}




No comments