Tuesday, March 6, 2012

[arduino] Music to RGB with LOLSs

Just in case you guys wonder, the previous LOLSs suffers from oxidation, poor solder joints and frequent breakdown with intermittent connectivity. Lih Sheng + helmi had kindly solder another piece of it for my use. Not to forget Kay Jin for helping to fix the broken leads on the RGB LEDs . Thanks!~

As of the previous challenge #3 posted to the lads and lasses to make the RGB LED change colour according to music, sadly none came forward and show me their stuff! Why I got to do everything myself
:(

update Sept 2012 this project was incorporated on a headphone and featured at Singapore Maker Faire


Time is a rare commodity. It is very difficult to prioritize which should come first (interest, hobby, $, love, life, work). So to save time, we should reuse as much as possible of what the stuff we had done previously!

If you guys could still recall my Arduino VU spectrum analyzer with FFT using LOL shield, courtesy of Andy Doro. Ready code are available for converting analog data on time domain to frequency domain.

The tricky part is actualy "mapping" the amplitude of each frequency bands (14 bands in total, coded for the LOL shield) and for all of the frequency bands into RGB. To further make the matter more complicated, Amplitude transition within each frequency band should be represented with the intensity/lumen of the RGB via the use of PWM, follow by hue/fading when transition in-between frequency bands.  Courtesy of "akgraphics" for the hue controlled RGB, my this experiment was made slightly easier......

In other words, my idea is to
1. Arrange the frequency bands into 3 "groups", low mid and high frequency and "map" into R, G then B.
2. Amplitude of each frequency band would translate into the brightness/intensity of each colour using PWM
3. Cycling from one frequency band to another, the R<->G<->B would "fade" by changing the hue of each colour.

Now, for the connection part
Using a 3.5mm" stereo jack to tap audio signal from computer/smart phone into A0 of arduino.
PWN pin 9,10,11 are use for controlling the RGB. LOLSs (it has a darlington IC) is used to "switched" 12v for the RGB LED strip with PWM.




 Just a point to note, test your RGB LED first. One of the RGB LED is not functioning properly when the pin for Red is held logic high. Time to get more RGB LED strips.








SWEEEET! Not bad for the first iteration.


If you have notice from the video, the "mapping" of sound frequency to RGB is not ideal. I get mostly RED, yes RED LIGHT. It is going to be any EYE SORE if I would stick this LED strip on my cheapo headphone as a bling bling. More time is needed to discover the relationship between the frequency appeared in music and the relevant colour to represent it (through code, that is). *hint: use the serial monitor* Another thing to note, how to repackage it so small (code size is 6k only), easy to retrofit on existing headphones (I DIZZ pseudo DR.Dre beats/senheizer), battery operated etc. Did I mentioned $$$ making?! LOL

Here comes the SUGAR. It can be intimidating, but the comments should make you feel at ease. Feel free to use/modify and let's ROXXX! Share your findings. A ping on new discoveries are much appreciated.

2 comments:

Anonymous said...

Hi mate,

I found a solution for just the reddish colour. I modified one line and it seemed to give a much wider colour response (basically all rainbow colours light up).

data_avgs[i] = map(data_avgs[i], 0, 4, 0, 9);

I changed the map ratio. Still there is room for adjustment but it depends on the music and all.

sjteo said...

thx for the update!