Electronic – arduino – Controlling colors in RGB LED

arduinoled

I have RGB LED(s) similar to the the 5mm in the pic. I have had success in uploading the example Blink program and testing it with a single LED connected to pin 13 of my Arduino Nano/ATMEGA328.

The LED timing is correct as per the program – One second OFF and One second ON – however, the colors are emitted at random.

Is there someway I can programmatically instruct the LED to display particular color at particular point of time. For example, first emit only Blue, then Red and so on.

Here is the code (its standard example with Arduino IDE):

int led = 13;
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Best Answer

I assume you have one of those LEDs that include a small chip that does the blinking? In that case there is no way you can reprogram that chip.

enter image description here

If you want the color to be under your control use a four-legged LED with separate connections for the three colors.