Introduction: Random Arduino LED Fader.

Picture of Random Arduino LED Fader.

Randomness. It is so easy in the real world. In the electronics world, is really hard. Sure it is possible to create "pseudo-random" effects but not truly random. The only way to actually create randomness is to use programming. Even then, randomness will eventually repeat itself.

Fading. It is also hard.Without programming, it is possible but it is not efficient. The circuits aren't small. In fact, most fading circuits use large capacitors that take up space. Not pleasing.

Put these two together and it is extremely tough to make.

In the end, I must subject to programming.

To be specific in this case,

Arduino programming. 

This project involves Pulse Width Modulation and is achieved through the use of an Arduino, a computer and a breadboard with LEDs. Inverting a signal will be achieved through the use of sinking and sourcing.

Update: I changed the code a bit. It now fades a bit faster and a bit better and smoother to view. If you downloaded the code look again at the code.

Step 1: What You Need.

You will need:
An Arduino
6 LEDs (possibly more.)
Jumper Wires
Breadboard and/or protoboard

Step 2: Programming.

Picture of Programming.
Program the Arduino with the code below. It will give you a slow fade from each LED.

Step 3: Circuitry.

Picture of Circuitry.

Take the ground of each LED and connect it to the ground rail of the breadboard. Connect the positive leads to pin 3, 5, 6, 9, 10, 11 on the Arduino. 

Step 4: Fading Away!

Picture of Fading Away!

Now, the LEDs should fade in a pseudo-random way. You are done but, for less impressed people, click "Next Step."

Step 5: Sinking and Sourcing.

Picture of Sinking and Sourcing.

Here's how I teach sinking and sourcing.

By sinking, I mean from output pin to ground. By sourcing, I mean from positive to output pin. 

Think of it this way. Power can flow from the LED to the pin in sourcing. In sinking, power comes from the pin. Power is always coming into the pin so, when the pin goes high, the current "passes" through the LED to the pin thus, turning it off.

To most people, they should say, "What difference does it make?"

To moi, a random person, it means, "I can invert signals thus create more randomness!"

Remember, to avoid using a resistor (living dangerously) power it from 3.3 volts.

Step 6: Doing So...

Picture of Doing So...

Now take pin 3 and source it.

Take pin 6 and source it.

Take pin 9 and source it.

Then, take pin 11 and source it.

Leave the rest where they are.

Step 7: Really Done.

Picture of Really Done.

Now, a random effect can be achieved (time for me to evily cackle) (excusez-moi...BWA-HA-HAHA-HA!)



514872 (author)2016-08-31

how to make the fade faster

brzi (author)2013-08-16

You should use curent limiting resistors on your LEDs, baud rate didnt killed it!

Higgs Boson (author)2012-01-16

This works well, but the LEDs repeat a pattern.

blinkyblinky (author)Higgs Boson2012-01-16

So, you're saying you made it?

Also, did you sink and source?

Higgs Boson (author)blinkyblinky2012-01-16

Yeah. I did sink and source, and I used your code. It starts out seeming random, but after a while a pattern emerges.

blinkyblinky (author)Higgs Boson2012-01-16

Try rewiring the sink and source. Plus, don't stare at it too long otherwise the pattern will emerge.

I will now rework the code.

Higgs Boson (author)blinkyblinky2012-01-16

You've heard of the random function on the arduino right? have you tried using it in the code? I'm trying to use
int x = random(1, 7)
to get a random number, and list all of the combinations the lights could be, and use the number gotten from the result of the random function to randomly select one of the combinations (and yes I know that that would only be capable of choosing only 6 possible combination of something like 30 to 36.)

blinkyblinky (author)Higgs Boson2012-01-16

I guess I'm more low-tech than I thought I was...


I will try that.

Higgs Boson (author)blinkyblinky2012-01-16

that's something I just learned today. I'm trying it now, so if I get it to work I'll post it here.

blinkyblinky (author)Higgs Boson2012-01-16


Higgs Boson (author)blinkyblinky2012-01-16

that's weird, what was the baud rate that you used?
are you going to order another atmega, or get a new arduino?

blinkyblinky (author)Higgs Boson2012-01-16

I have new ATMEGA328s. They just don't have the bootloader.

The EEPROM seems busted...the TX LED stays on all the time.

I will have to run the Command Prompt to see where it doesn't work.

Higgs Boson (author)blinkyblinky2012-01-16

Okay well I hope you get it working. I will continue experimenting with the code. I might try using radomSeed, and use an analog pin with nothing attached.

blinkyblinky (author)Higgs Boson2012-01-16

I am ready to rip my hair off my head.

blinkyblinky (author)Higgs Boson2012-01-16

Great. Let me know about you results.

BrunoG (author)2011-12-19

Yay I´m the first to write a cament.
Very cool I did it and it works!!!!

blinkyblinky (author)BrunoG2011-12-19

Good for you!

About This Instructable




Bio: I love building things and taking pictures. If you want me to build something...I'm open to ideas. My motto? "If you want something ... More »
More by blinkyblinky:Keeping Up Appearances with ChindoguA Complete Beginner's Guide to Raw Files And Raw ProcessingHypercard - An Impossible Paper Object
Add instructable to: