Instructables

Arduino RGB LED control

On the internet there are lot of instructions about connecting RGB LEDs and Arduino but nothing about controlling brightness except connecting potentiometer to every LEDs input but what when you don't have enough potentiometers? Then this instructables will help you.

 
Remove these adsRemove these ads by Signing Up

Step 1: Parts list

2.jpg
3.jpg
4.jpg

You will need:
arduino board
10KΩ potentiometer
button
breadboard
10KΩresistor
RGB LED module(if you don't have RGB LED module but only RGB LED you will need to connect 330Ω resistors to led)

Step 3: Code

Here is sketch
int ledRed = 3;
int ledGreen = 5;
int ledBlue = 6;
int buttonPin = 12;
int redLedBrightness;
int greenLedBrightness;
int blueLedBrightness;
int counter = 0;
int potentiometerPin = A0;
void setup()
{
  pinMode(potentiometerPin, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledGreen, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  loop();
}

void red()
{
  while(counter == 1)
  {
    redLedBrightness = analogRead(potentiometerPin) / 4.096;
    analogWrite(ledRed, redLedBrightness);
    if(digitalRead(buttonPin) == 0)
    {
      loop();
    }
  }
}

void green()
{
  while(counter == 2)
  {
    greenLedBrightness = analogRead(potentiometerPin) / 4.096;
    analogWrite(ledGreen, greenLedBrightness);
    if(digitalRead(buttonPin) == 0)
    {
      loop();
    }
  }
}

void blue()
{
  while(counter == 3)
  {
    blueLedBrightness = analogRead(potentiometerPin) / 4.096;
    analogWrite(ledBlue, blueLedBrightness);
    if(digitalRead(buttonPin) == 0)
    {
      counter = 0;
      loop();
    }
  }
}

void loop()
{
  counter++;
  switch(counter)
  {
    case 1:
    delay(200);
    red();
    break;
    case 2:
    delay(200);
    green();
    break;
    case 3:
    delay(200);
    blue();
    break;
  }   
}

With potentiometer you can adjust or reduce brightness of actual color and with button you change color.
Sorry for my english.

Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!