Picture of RGB LED transition (Arduino)
Hello Guys, in this instructable I will give you a code for transtioning an LED. My group, Newton Labs, has spent quite a bit of time on this. Transitioning isn't as easy as it seems for a nice smooth transition.

Submitted by Newton Labs for the Instructables Sponsorship Program

Step 1: The circuit

Picture of The circuit
In this circuit, you will need to use 3 Pulse Width Modulation pins, PWM for short. Pins that are not specified as PWM pins are digital pins, which can only turn on and off. PWM pins can go from lets say 3.3 volts to five volts to 1.1 volts.

In my program  Red = pin 3, Blue = pin 5, and Green = pin 6.

This was a very useful tutorial and program to help me get started in using the Arduino, thank you!

Because of the way the "i" counter works, this program will fail if you start using RGB values that are different than 255 or 0. I had many problems with the software counting too far.

I modified the software and created two completely different ways of processing the data (with slightly different results). If you or anyone is interested, get in touch with me :-) it allows you to custom set the RGB values without affecting the quality of the transition from one colour to the other.

TheTwim5 months ago

You may try using ALA library. This example shows how easy it is to create color animations with an RGB LED.

You can also create animation sequences.

yaser ha5 months ago

My led is 1 Positive and 3 Negative

simonfrfr (author)  yaser ha5 months ago

The LEDs vary; both variants are sold.

redkcir made it!6 months ago

Nice job! One note. Your drawing of the leads to the Arduino show that the long lead on the LED is hooked to GND (six pins down from the power plug). This should be to the 5volt plug (5 pins down). I tried to made a video of the project running and have posted it here. This is my first video with a new camera so don't expect a lot. The camera is mounted on a roll of duct tape, a coffee cup (newly emptied) and an old container of Crystal Light Peach Tea (ya do what works, right?). I covered the LED with a piece of paper to tone down the light so the changing of the colors could be seen. I don't know why it is so jumpy, it played fine before I uploaded it.

Clip0000.mp4(516x387) 26 KB
nice project! do you have any videos you could post of the sketch above?
simonfrfr (author)  amandaghassaei3 years ago
Sure, Great Idea!, I actually do, I think I will use my Voice recognition system video for this!
maewert3 years ago
Similar instructable here:

Also I uploaded code to continuously change from one random color to another here (just change the color pins to your pin numbers):
int red = 11; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 9; //this sets the blue led pin

int redNow;
int blueNow;
int greenNow;
int redNew;
int blueNew;
int greenNew;

void setup()
{ //this sets the output pins
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
redNow = random(255);
blueNow = random(255);
greenNow = random(255);
redNew = redNow;
blueNew = blueNow;
greenNew = greenNow;

#define fade(x,y) if (x>y) x--; else if (x<y) x++;

void loop()
analogWrite(blue, blueNow);
analogWrite(red, redNow);
analogWrite(green, greenNow);
redNew = random(255);
blueNew = random(255);
greenNew = random(255);
// fade to new colors
while ((redNow != redNew) ||
  (blueNow != blueNew) ||
  (greenNow != greenNew))
  analogWrite(blue, blueNow);
  analogWrite(red, redNow);
  analogWrite(green, greenNow);
simonfrfr (author)  maewert3 years ago
Well, I know that my group was the only one who was trying to do this, but its nice to know that we aren't the only ones trying to do this.