Lisleapex Blog
Published © CERN-OHL

How to Control RGB LEDs With Arduino

In this guide, you will learn how to control an RGB LED using an Arduino.

BeginnerWork in progress2 hours156
How to Control RGB LEDs With Arduino

Things used in this project

Story

Read more

Schematics

circuit_HJpIl9p1Hp.png

Code

Untitled file

Arduino
int redPin= 11;
int greenPin = 10;
int bluePin = 9;

void setup() {
  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, 0); // Yellow Color
  delay(1000);

  setColor(0, 255, 255); // Cyan Color
  delay(1000);
  
  setColor(255, 0, 255); // Magenta Color
  delay(1000);
  
  setColor(255, 165, 0); // Orange Color
  delay(1000);
  
  setColor(128, 0, 128); // Purple Color
  delay(1000);
  
  setColor(255, 255, 255); // White Color
  delay(1000);
}

void setColor(int redValue, int greenValue, int blueValue) {
  analogWrite(redPin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}

Credits

Lisleapex Blog
26 projects • 0 followers
Fast Delivery of High-Quality Electronic Components
Contact

Comments

Please log in or sign up to comment.