Beat Detection and Music Visualizer using Processing, Arduino, LEDs, and a glass head.
I had a strand of RGB LEDs that I ordered from China which turned out not to be individually addressable as I thought, so I came up with this project as a way to put them to good use! Be sure to watch the video to get the full effect.
The software which runs the music visualizer and beat detection is built in Processing 2.0, and communicates with an Arduino in the base of the head over USB, which then sets the colors of the LEDs. The Arduino part is based on the excellent RGB LED Strips tutorial over at AdaFruit.
* Everything used in the AdaFruit tutorial, including Arduino Uno, USB cable, non-addressable analog RGB LEDs, power supply, transistors, MOSFETs, and a breadboard and wiring to put it all together. AdaFruit sells most of those things, but you can also get the LEDs from eBay or AliExpress, and the rest from an electronics shop like Fry's.
* A prototyping board. I got mine from RadioShack for around $3.
* A few headers to slot the proto-board on to the Arduino. A pack of 100 in strips should be around $3 or less.
* Some solder.
* (Optional) Some 4-pin JST connectors, to put a detachment point between the Arduino and the LEDs. AdaFruit sells these for about $2.
* A glass head. Mine came from Pier 1 and was about $20.
* Some cotton balls (for the brain) and pillow stuffing (for the rest)
* A wooden box to use as a base. I used the bottom half of an unfinished jewelry box from Michael's for around $5.
* Some silicone glue to attach the head to the base. Although any reasonably strong glue would probably work.
* 2 screws, nuts, and nylon standoffs to attach the Arduino to the box. Arduino mounts can take M3-0.5 or UNC 4-40 screws, depending on what's available to you. I got all of these at the hardware store for less than $1.
* A little bit of electrical and masking tape
* A soldering iron
* A drill or small saw to cut holes in the box
* Screwdriver and pliers to attach the Arduino board
* A Mac with Arduino 1.0 and Processing 2.0 installed. (You can also use a Windows or Linux PC)
Step 1: RGB LED Strips Tutorial
At the end of that tutorial, you should have a working circuit on a bread board, and verified that your LED strips and power supply are functioning properly.
Step 2: A head full of cotton
One subtle note: With my particular glass head when the lights were off and the LEDs were on, the eyes were a little hard to pick out. To help your brain recognize the shape as a face, I put a layer of translucent masking tape over the eyes and trimmed it with a razor blade. A simple solution!
Step 3: Beat detection, music visualization, Arduino, and Processing
Initially, I wanted the head to detect beats with a microphone. Unfortunately, I had trouble getting the one I had to function with the Arduino, so I switched to a different input source I'd been meaning to play with: Processing. As a side benefit, I didn't have to filter out any ambient noise!
In order to control the Arduino from Processing, I used Firmata (a generic library for controlling microcontrollers from a PC). The Firmata code for Android and Processing, and a brief tutorial are here: http://playground.arduino.cc/interfacing/processing.
Processing ships with the Minim library for dealing with audio, and there was an example provided for using the Fast Fourier Transform (FFT) to analyze spectrum. I found the output to be pretty non-intuitive, so I wrote a music visualizer to help me "see" the music, and try to identify visually when a beat had taken place.
I started getting pretty good results by looking for large changes in any of the FFT "buckets", which roughly correspond to octaves. Ie, if an octave has been at the same volume (usually silent) for a while, and then suddenly has sound, my software guesses that it's a beat. If not a beat, something interesting that you are probably paying attention to!
To get a color, each bucket is assigned a range on the color wheel (which slowly rotates with time.) When the beat happens in a bucket, the Arduino/head is illuminated with the bucket's associated color. Additionally, there's a pretty quick fall-off so that each beat fades away within a second or so. The color of the beat being sent to the Arduino is indicated by the horizontal bar at the bottom of the visualizer.
The program also has some keyboard controls to adjust the vertical scale of the visualizer, the color rotation, or the sensitivity of the beat detection.
Lastly, the Processing sketch analyzes audio from the default Audio Input port of the computer. The computer's operating system controls whether this is your microphone or the input jack on your sound card. On my Mac, I used SoundFlower to route the computer's regular audio (such as from iTunes) into a virtual Audio Input port which I made the system default, so that the Processing sketch could analyze it. Definitely awkward but it worked.
Step 4: Object permanence
My kind didn't have copper connecting each strip, so I had to make connections between components by soldering the leads to each other directly. With enough solder and a steady hand, this worked surprisingly well! I only needed a few extra pieces of wire, and that was mostly to keep the layout looking neat. Also one critical inspiration was that I could solder on both sides of the board.
If your LED strip didn't come with a connector, this would be a good time to put one in. This will allow you to detach the LEDs from the Arduino, which is very useful for building a housing around it.
The last clever thing I did here was to organize the layout of the board and then solder on some headers such that it could be "snapped" onto the Arduino similar to a shield. Annoyingly, one set of headers on the Arduino (the one that includes the ground) is offset by about half a pin. I had to bend the header before soldering it to the proto-board in order for it to align properly.
Step 5: All your base are belong to head
I opted to use only 2 mounting screws because that would allow me to hide them under the neck of the glass head. Plus the holes for the power and USB jacks made the Arduino pretty firmly wedged in there. To keep things tidy, I taped down the connector cable.
Glueing on the head was surprisingly easy. I placed it on the box where I wanted it, and traced a circle around the neck. I picked a silicone glue because it's super goopy and I wanted there to be good contact between the wood and the relatively curvy bottom rim of the neck. The glue starts to set in about 5 minutes, so I had plenty of time to squeeze out a thick ring of it over my tracing and then place and align the head on top. For good measure, I also applied more glue around the outside, and used a paper towel to wipe away any extra. And then vigorously washed my hands with soap! The glue takes about 24 hours to cure and doesn't smell great while doing it - I recommend sticking it outside or in the garage if you have one.