There are various guides around instructables about pure circuit visualizers, but those are generally some kind of amplifier to make the lights pulse and change intensity in response to the power conveyed in the audio signal. I wanted something more along the line of multiple strobes responding to different frequencies of music. The end result is the mutant stepchild of this and this and a little of this, but it is totally worthwhile.
The actual audio signal gets read in from the microphone jack on the computer, so it can either accept its own sound fed back or the sound from an iPod / Rock Band / karaoke / whatever you crazy kids can dream up.
Yay new music! Courtesy of DoKashiteru and the Creative Commons, I bring you an uncensored video of the system in action:
Step 1: Parts / Tools
LEDs - Obviously. I bought really bright 10mm ones in varying colors in bulk from eBay, but you can find them on Digikey or Mouser. Higher millicandela ratings are better, especially if you want these to illuminate anything and not just be a spot of color. Shop around to find a good deal.
Resistors - One for each LED. Mine required 470 ohms, but make sure you check the ratings on your LEDs so that you get as much light as possible without burning them out.
Solderless breadboad - For all the circuitry.
Arduino - The computer/circuit interface. An awesome little board. Buy it online.
Wire - Lots of solid-core wire. I needed a lot, fast, so I ended up cleaning out my local RadioShack of this stuff, but you should be able to find it a lot cheaper. Having two strands held together like this is extremely useful, as you'll see later.
Computer - Where the actual computation takes place. Yes, this may be slightly overkill to flash a few lights, but as we inevitably end up playing our dance music from a laptop anyway it worked out just fine.
Power supply - The LEDs will likely draw more power than the arduino can provide, so we're going to be powering them externally and switching them with transistors. You should have a bunch of these lying around from old electronics, or you can find them at thrift stores. See the planning page for what voltage / amperage you need.
NPN transistors - We're using these as current amplifiers / switches. A little current drawn from the arduino controls a lot of current drawn from the power supply that runs through the LEDs. Find them online or at RadioShack.
Soldering iron - Pretty self-explanatory.
Speakers / audio splitter / male-male audio cable - Speakers for sound, splitter and cable to feed the signal from the headphone output to the speakers and microphone jack.
Arduino - Download the arduino software environment from here.
Processing - Processing talks well with arduino, and has some awesome libraries built in. Download it from here. Make sure you have the latest version of the Minim audio processing library from here. You may also need to get the 'arduino' library to get them to communicate - get it from here and stick it in your Processing/libraries folder.
Step 2: Circuit Design
An overall view of the circuit we're building. The two strands of the wire are connected to the high and low voltages, and each LED/resistor pair bridges them to light up. The low voltage strand is actually connected to ground through a transistor so that we can control the amount of current that flows (and therefore the brightness of the LEDs).
Step 3: Planning!
The most important step is to plan out what colors you want, and where. The ceilings in my dorm are best described as "waffle-shaped," with square indentations tiling the surface. These made a very natural grid to lay out the colors, but you'll need to come up with your own plan. You can figure on up to 8 or so LEDs to a single control strand, meaning that those 8 will turn on and off simultaneously.
With a layout all drawn up, now we need power calculations. Check the datasheets for your LEDs to figure out the forward voltage and current. Mine have a voltage drop of ~3.5 volts and have a maximum current of 20 milliamps. As I had a 12 volt power supply lying around, we can do a little simple circuit math using Ohm's Law (V=IR): (12 - 3.5) = 0.02 * R --> R = 425 ohms. For simplicity we round that to 470 ohms. Most 5mm LEDs will have voltage drops around 2 volts and current ratings around 15 milliamps, but check so that you don't burn them out. Remember: the light intensity is proportional to the current, so use a bigger resistor to limit the current if they are too bright. Also make sure the power supply can handle all this current - some small ones are only rated to a few hundred milliamps, meaning you can only power 10-20 LEDs in parallel like we are.
Step 4: Prepare LEDs and Wire
It's a lot easier to attach the LEDs to the wires if we first solder them together with the resistors. Cut both the negative (shorter) lead of the LED and one side of a resistor about in half, then solder them together. Once this is done, bend the positive lead and the resistor outwards so that the LED sticks up a little. See the picture for a much clearer explanation.
Next, lay out all the wire and make sure you have enough for each strand to reach. Measure out and mark where each LED needs to go. Once again, the explanation for the actual attachment is best given by the picture. Solder the LEDs to the wire, making sure to keep the polarities consistent - all the positive leads to one wire, and all the negative leads to the other. Once you've finished, test the strands BEFORE you put them up - connect the wires to your power supply or a 9 volt battery to make sure all the lights turn on.
Next, put all the wires up! In my case, this involved lots and lots of white gaffer tape and a standing on chairs. Make sure the free ends all come together at one location, where we're going to put the breadboard, arduino, and computer. I also put little origami globes over the LEDs to diffuse the light - just cut small slits radially outward from the hole in the balloon to make four tabs and it will slip on nicely. See the picture on the previous page for the effect. Bonus points if the globes are made from old lecture notes.
Step 5: Build the Circuitry
There's really not much more to say. Connect the positive and negative leads from your power supply to the power rails on your breadboard, and connect the arduino ground pin to the same negative rail. See the picture for a good layout system. Test that everything is working by removing the leads from the arduino (shown in blue, black, and red below) and connecting them to the positive power rail. Current will flow through the transistors and allow the LEDs to turn on (if everything is connected properly). Put these back how they should be and connect the arduino to your computer with a usb cable.
To set up the sound system, plug the speakers and the male-male cable into the splitter. Send the other end of the male-male cable into the microphone jack on your computer. Again, this is slightly overkill if you're only going to play sound from your computer (especially if you can figure out how to use jack) but this way the system can flash to Rock Band or karaoke or anything else that can output on a 3.5mm audio jack.
Make sure your microphone is working - plug the splitter into any audio source, then open up a sound recording program to see if you're registering a signal. Oftentimes the microphone can be muted, so if you have problems that's the first place to look.
Step 6: Code Code Code
Open up the arduino software environment, and upload the StandardFirmata example sketch to the board. The sketch will allow you to control the arduino over a serial interface, meaning arbitrary code on the computer can control the lights we just hooked up.
The code that actually processes the audio signal is (conveniently) a Processing sketch. It is based around the awesome BeatDetect library in the minim library. The BeatDetect class computes the Fourier transform of the audio signal, and keeps track of the mean and variance of each of the coefficients for the last few seconds. If the value in any of the FFT bins exceeds the variance, a beat is detected and the light associated with that frequency will turn on. </technical>. What this means is that each strand of LEDs will correspond to a different frequency of music - one strand will flash to bass beats, another to snare hits, another to high vocal notes, and so forth, for 26 different frequencies.
Download the attached Processing sketch from below, and modify the ledPins array on line 10 to reflect your own setup. The first pin number corresponds to the lowest frequencies. Once that's done, you're finished! Plug the audio splitter into your headphone jack, start the sketch, and start playing some music. If everything works as expected, a waveform visualizer will pop up and the lights will being flashing. Enjoy!
Step 7: Troubleshooting
The main problems you're likely to encounter are getting Processing and the arduino to talk to each other. Make sure you install the arduino software - this will bring with it all the necessary serial libraries. You can find avoid problems with the circuit by testing as you go - test each LED, then each strand, then each transistor set. If all else fails go back to this to diagnose where the problem lies.
Now that I've managed to squash all the bugs from my own setup, I can't think of what they were off the top of my head. Post any problems you have, as I probably ran into them and have since forgotten.
Participated in the
Get the LED Out! Contest