loading
This was one of the first codes I ever wrote to understand how to use variable analog outputs to dim LEDs.
I got a couple tri-colour LEDs in my Arduino kit, and once I realized they were common anode rather than common cathode, I thought this would be a cool use for it.

The cycle basically does a transition starting with blue. It then goes to blue and red, then fades the blue so there's just red. Then it transitions to red and green, then to just green, then to green and blue, then to just blue, and starts over.

Initially I put a paper sleeve around the LED because the LED is really bright and blinded my cameras, and just showed up white.
Then I thought that made a really nice ornamental lamp that way.

I also put it through a laser etched crystal with the image of a cat on a branch in it.
The effects were pretty cool!

The LED simply hooks up to pins 9, 10, and 11 on the arduino and to either ground or 5V depending on if the LED is common cathode or anode through a current limiting resistor (I suggest 100-220 ohms).

Of course you can also use 3 individual LEDs with one anode each in pins 9, 10 and 11 and the other pins to ground though a current limiting resistor each.

If you're wondering about the penny on my Arduino, see my instructable on Beefing Up your Arduino Power.

A copy of my code was posted as a response to someone else's instructable here:

That's nice!
Thanks for posting a reply. I can't post code directly in the description because it interprets &lt; and &gt; as HTML code. In a reply, I can use the Rich Editor, which allows these without taking math symbols as HTML. Here's the code for the 3 LED or tri-colour LED project.<br> I have one for 4 LEDs too, but I think anyone with this code can make the 4 LED one (but I'll post it if asked).<br> <br> <br> <br> int maxLed=255;<br> &nbsp; int minLed=0;<br> &nbsp; int Blue=minLed;<br> &nbsp; int Green=minLed;<br> &nbsp; int Red=minLed;<br> &nbsp; int Bluepin=9;<br> &nbsp; int Greenpin=10;<br> &nbsp; int Redpin=11;<br> &nbsp; int OnDelay=2000;<br> &nbsp; int MidDelay=50;<br> <br> &nbsp;<br> <br> void setup() {<br> &nbsp; pinMode (Bluepin, OUTPUT);<br> &nbsp; pinMode (Greenpin, OUTPUT);<br> &nbsp; pinMode (Redpin, OUTPUT);<br> &nbsp; analogWrite (Bluepin, Blue);<br> &nbsp; analogWrite (Greenpin, Green);<br> &nbsp; analogWrite (Redpin, Red);<br> &nbsp; }<br> &nbsp;<br> void loop() {<br> <br> &nbsp; for (Green=minLed;Green&lt;maxLed;Green++) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Greenpin, Green);<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Greenpin, maxLed);<br> &nbsp;&nbsp;&nbsp; delay (OnDelay);<br> &nbsp; for (Blue=maxLed;Blue&gt;minLed;Blue--) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Bluepin, Blue);<br> &nbsp;<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Bluepin, minLed);<br> &nbsp; delay (OnDelay);<br> &nbsp; for (Red=minLed;Red&lt;maxLed;Red++) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Redpin, Red);<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Redpin, maxLed);<br> &nbsp; delay (OnDelay);<br> &nbsp; for (Green=maxLed;Green&gt;minLed;Green--) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Greenpin, Green);<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Greenpin,minLed);<br> &nbsp; delay (OnDelay);<br> &nbsp; for (Blue=minLed;Blue&lt;maxLed;Blue++) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Bluepin, Blue);<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Bluepin, maxLed);<br> &nbsp; delay (OnDelay);<br> &nbsp; for (Red=maxLed;Red&gt;minLed;Red--) {<br> &nbsp;&nbsp;&nbsp; analogWrite (Redpin, Red);<br> &nbsp;&nbsp;&nbsp; delay (MidDelay);<br> &nbsp; }<br> &nbsp; analogWrite (Redpin, minLed);<br> &nbsp; delay (OnDelay);<br> }

About This Instructable

3,080views

13favorites

License:

Bio: Just getting into the microcontroller craze. I used to do this sort of thing building circuits for 8 bit microprocessors back in the early 80s ... More »
More by SuperTech-IT:8X8X8 3D RGB LED Cube Arduino 8 A.C. Outlet (plug) Timer / Vampire Killer One Part $1 Computer Security Power Lockout 
Add instructable to: