# Musical Rainbows in the Van

June 25, 2012

I always intended on creating my own driver for the LED lights in my van but with the thieving skum pointlessly taking the remote for the included unit, I was spurred into action. Having installed a sound system, a musical light system was a given, to enable the van to live up to the Bang Bus name it has acquired (of certain definition!).

## Stand Alone Arduino

I started out looking at taking the analogue voltage variation created by music, analysing it in some way, then using it as an output for the LEDs. ‘In some way’ was the issue here, I hadn’t really considered what I could do with on a small microcontroller. I thought maybe I could look for spikes of a beat or get the frequency but that was becoming too complex for the Arduino. I decided I would take the signal amplitude and simply translate it to LED brightness so you still see the beat in effect but it wouldn’t take advantage of the RGB.

What to do with the signal was the least of my problems as I quickly found the analogue inputs aren’t sensitive enough to take a audio signal. A quick delve into my A-level electronics, along with some web refreshers, and I created a transistor amplifier using the TIP122 that I used to drive the 5050 RGB strip [left-side of Figure 1] (more on that below).

The Arduino code is extremely simple. I take the reference (no music) of the audio input, take this away from the music signal, get the maximum amplitude, then divide 255 by this max to find a scale to apply to the amplitude. 255 is used as this is the number of values available to the 8 bit DAC, creating the output voltage for the LEDs.

Results are good, it does what it says on the tin really; the LED’s brightness varies according to the music intensity. It make use of RGB though, so I set about looking at what my computer could do as the processor, feeding via serial.

## Computer Processing via Serial

Turning to Minim, a library included with Processing for analysis of audio. In particular the Fast Fourier Transform (FFT), which I use to extract the amplitude of parts of the frequency spectrum rather than the complete waveform as before, and BeatDetect to…detect the beat!

It is worth noting I actually went down this avenue before completing the non-serial method above so I’ll talk about the circuitry now. I’m driving a 5050 RGB LED strip, constructed of 30 RGB LEDs per 1m, each drawing 60mA. With 5m of the stuff in my van, the maximum draw is 9A – far more than the Atmega can supply. Using the TIP122 transistor, with the base connected to the arduino output, the strip connected to the collector and drain sunk to the 12V ground solves this. If using a few LEDs or single RGB package you can remove this part.

Onto the software. To get an idea of how to use Processing, I started with the examples. BeatDetect can differentiate between musical beats (snare, high hat, kick) so I used this to output each to a different colour. It was cool but still not the dynamic, rainbow effect I wanted. FFT applies a fast fourier transform to the music and outputs the spectrum as a number of lines whose length depends on the amplitude. This was more my ball park. Breaking the spectrum into ranges for the bass (green), mid (blue) and treble (red) and I had my dynamic musical lights. Looking at the code will explain this further.

I converted the code to use get.LineIn rather than a sample file, involving changing BeatListener to use AudioInput rather than AudioPlayer. Then, to make the line in of my Macbook the output of the sound card, SoundFlower is required to create a software device that is then defined in the MIDI setup to be the output and input device.

The results once connect to the van lighting are great. The dynamic colours are a lot nicer to look at than the pulsing single colour or flash to a beat.

# Code and Parts

Code on GitHub

UPDATE 16/01/13 I re-used the code in another project, and think the version there is better; you can fine tune the frequency bands.

Parts List

# Future Work

• I’ve got the parts on the way to convert this from prototype to a contained unit. I’m going to make it stand alone to sit by the AUX in the van, with a USB jack for when I have my laptop. I’ll probably tweak the code a bit before this, and include a button input to cycle functions, along with a pot to vary sensitivity.
• I’m not done with the LED strip, I’ve got some neat ideas once I can get my ANT+ receiver working…