Rachana Jain
Published

Interfacing RGB LED with Arduino Nano

In this project, we'll explore how to use an RGB LED with an Arduino Nano and make the LED glow in different colors.

BeginnerProtip1 hour113
Interfacing RGB LED with Arduino Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
RGB LED common cathode
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
BC547
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Code

Arduino Code

C/C++
// Pin definitions
const int RedLed   = 6;    // Red LED connected to pwm pin 6
const int GreenLed = 5;    // Green LED connected to pwm pin 5
const int BlueLed  = 3;    // Blue LED connected to pwm pin 3

void setup() {
  // Initialize PWM pins as outputs
  pinMode(RedLed, OUTPUT);
  pinMode(GreenLed, OUTPUT);
  pinMode(BlueLed, OUTPUT);
}
void loop() {
  int index1, index2;
  analogWrite(GreenLed, 255);  // Green
  for (index1 = 0; index1 < 256; index1++) {
    for (index2 = 0; index2 < 256; index2++) {
      analogWrite(RedLed, index1);   // Red
      analogWrite(BlueLed, index2);  // Blue
    }
  }
  analogWrite(BlueLed, 255);  // Blue
  for (index1 = 0; index1 < 256; index1++) {
    for (index2 = 0; index2 < 256; index2++) {
      analogWrite(GreenLed, index1);  // Green
      analogWrite(RedLed, index2);    // Red
    }
  }
  analogWrite(RedLed, 255);  // Red
  for (index1 = 0; index1 < 256; index1++) {
    for (index2 = 0; index2 < 256; index2++) {
      analogWrite(GreenLed, index1);  // Green
      analogWrite(BlueLed, index2);   // Blue
    }
  }
}

Credits

Rachana Jain

Rachana Jain

1 project • 1 follower
I'm an avid Arduino and electronics enthusiast with a passion for tinkering, experimenting, and bringing innovative ideas to life.

Comments