The Prototype

Musical Rainbows in the Van

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!).

Figure 1: Circuit diagram. Transistor amp on left of breadboard is only used for non-serial musical display, to boost audio input to Arduino (can use it for serial too as preamp). Transistors on the right are used to drive the RGB strip from the 12V DC. If you are just using a few LEDs you don’t need this either.
Figure 1: Circuit diagram (updated Jan.13). Transistor amp on left of breadboard is only used for non-serial musical display, to boost audio input to Arduino (can use it for serial too as preamp). Transistors on the right are used to drive the RGB strip from the 12V DC. If you are just using a few LEDs you don’t need this either. Here’s the .fzz

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!

The Prototype

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.

An overlay of the Java applet output showing roughly how I have broken the spectrum up.

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…

UPDATE I’ve now finalised this project

cropped-JBRLogo.png

50 thoughts on “Musical Rainbows in the Van”

  1. This is the exact implementation of an RGB strip musical sensitivity I’ve been looking for. I have no experience with projects like this however. Do you think it’s easy enough for a newbie to construct?

    1. Yes it should be fairly easy. It was my first ‘proper’ Arduino project and the electronics required are fairly simple. You should be able to build it up from the parts list, circuit diagram and code provided in the post. Let me know if you decide to do it and encounter any problems.

  2. Thanks for encouragement! I think I’ll give it a go. I’m just a little bit uneasy because of my total lack of experience in this field. I’m a tinkerer however, so it’s a challenge 🙂 Thanks for help, I’ll report if I have any problems (and of course if I finish it as well!)

  3. This looks good. I was looking to originally try to make a project using some LED Christmas lights, but the LED strip looks a lot nicer, at least in the dark 🙂 I think I’ll start trying to put together the parts for something similar thanks to this 😀

  4. You’re right, it is rather hard to see connections. Here is the fzz along with a schematic screenshot. Please excuse any funny wiring/missed connections, it’s been a learning process with Fritzing getting the schematic right (things have changed a bit from the photo in the post).

    Thanks for the comments!

    Schematic
    MusicalColours.fzz

    ps. The amplifier schematic is identical to the example here: http://hackaweek.com/hacks/?p=327

    1. Unfortunetly can’t open the page with the Frizing file. Is it possible for you to please fix this? Would really be appreciated, as I am doing something similar for a school project and find your resources extremely useful. Thank you. Cheers.

        1. Thank you so much John! I really did not expect to get a reply since this project is a bit older, but it is really appreciated, and especially not so quickly. You saved me a lot of work and confusion. Once again, thank you so much. 😀

  5. Hi John, Like Oliver, this is just what i was looking for and is my first processing project also. I am having trouble getting the code to run, this is coming up
    “No library found for cc.arduino
    Libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.”
    Also I’m not sure what part of the code to use, as you have 4 links, or do i need them all and put them in separate tabs?
    Thanks for the inspiration.
    Willy

    1. Hi Will. With regards to the error, have you followed these steps in order for Processing to interface with the Arduino? In particular, adding the arduino library to ~/processing/libraries?

      http://playground.arduino.cc/interfacing/processing

      In terms of which part to use for Processing. You need to download BeatListener.pde and MusicalColours.pde, put them both in a folder named ‘MusicalColours’, then stick that in your processing sketchbook location (should be ‘My Documents’ or ‘Documents’ on a Mac, same place as the library). Finally, run MusicalColours.pde, which will run BeatListener.pde with it.

      Hope that helps.

  6. Sorry if this is a silly question but I’m having trouble finding a 1uF 6.3V Electrolytic Capacitor, the proper 3.5mm stereo jack, and the proper generic female header. If anyone wants to point me in the right direction it would be very much appreciated. Can’t wait to get started on this!

    1. Actually I’m only having trouble with the 3.5mm stereo jack, I don’t have very good electronic stores around where I live.

      1. Here’s the sort of jack I used: http://uk.rs-online.com/web/p/jack-trs-connectors/0476328/

        You want to connect to pins 1,2 and 3: http://docs-europe.electrocomponents.com/webdocs/0031/0900766b80031a27.pdf

        Here’s the female connectors too if your still looking, I just desoldered the one that came on the controller for the lights though.
        http://www.ebay.co.uk/itm/10-X-4-PIN-Female-RGB-Connector-Cable-For-3528-5050-SMD-LED-Strip-DIY-new-AB-/271127742735?pt=UK_Light_Bulbs&hash=item3f2079090f

        1. Thank you very much! One other thing me and my friend we’re looking at and couldn’t figure out was what the jack is used for. Because we’re figuring that the data from beatdetect and FFT comes through the usb cord and tells the LEDs what to do, and the music is just being played through the audio jack of the computer, what is the need for the audio jack? Thank you a ton, you are the man!

          1. Yes, if you’re just using Processing through your computer to control it you don’t need the audio jack or the amplifier circuit to the left of the circuit diagram for that matter. They are just for the stand-alone arduino version that I built.

            Let me know who you get on with it. I’m currently in the toying around with bits of this for another project of mine so might update various bits of the code soon.

        2. So I’ve got it built but I was wondering before powering it on, because I’m omitting the amplifier on the left, if I can also omit the resistors on the left, or do they play an role in changing the amps for the LED.

          1. Yes, you can omit everything on the left side of the breadboard; it isn’t used.

            The ones leading to the transistors on the right from the PWM aren’t absolutely necessary either but protect the Arduino pins.

            Let me know if you have any problems.

          2. Okay it’s working but the lights are very dim, I have omitted everything on the left side including the 5V and GND cables and I think that’s why. I’ve messed around to try and get them brighter but it doesn’t work and no light ends up working. If I actually am supposed to use the 5V and GND, how should I have it wired to the right side?

            1. Yes. Sorry, the power rails (5V and 0V) need to be connected on the left side using either setup. I did notice a mistake in my diagram thanks to this though: the black wires from the transistor emitter should be connected to 0V (the top rail, they were connected to 5V before), so check your circuit before you power up (I’ve corrected the diagram above).

              Hopefully connecting the 0V will solve the problem, the lights will be dim because they aren’t being properly grounded. Also, do you have a 12V supply connected to the Arduino?

            2. I do have a 12V supply connected to it, but I’m uncertain where to plug in the 5V rail, on the .fzz it’s going to the left side and I’m wondering where to put the 5V power rail on the right side. But the 0V rails are now properly connected.

              1. The 5V rail isn’t actually used on the right side. I just have it connected for prototyping. Hopefully your circuit should work as it is now.

                1. Thanks a lot, my dorm is way better and I hope other people can benefit from all my questions :p

  7. John I’m having some trouble getting it to work, do you think you can email me and see if you could help me through it?

      1. Hi John,

        I am also having problems with Processing, at Line 65, it mentioned i can’t use the size(). Could you email me back so we could discuss about it?

  8. array index out of bounds exception:1 error messasge. I also get duplicate field name error message when trying to process the code

    1. In the Processing application I assume? Do you know what line number the error flags at? It sounds like the FFT is not being performed on the input sound so the array is not being created, causing an error as it tries to look at the amplitudes.

      1. Hi John, was there ever a solution for the array index out of bounds error?
        My error message reads:
        at MusicalFlash.setup(MusicalFlash.java:57)
        Sorry if this an old topic just thought I would give it a try and see.
        Thanks

  9. Hi there

    First time ever doing this kind of stuff so sorry if I come across a bit daft, but from what I can tell I’ve got the software more or less working and the hardware is fine. But I’m having trouble finding a way to take the audio in rather than audio player. Being on windows I can’t use sound flower and jack audio is just confusing, any ideas on easy alternatives?

    When I run the musical colours script the java box opens but immediately crashes. I’m guessing this is because haven’t given it any audio to buffer?

    Any help is greatly appreciated!

    1. Thanks, no problem asking any questions. I’ve only used this on a mac and from a quick look, JACK audio looks like your best bet so looks like you’ll have to try and get your head around it! You could use the audio input of your computer with a physical device instead.

      In terms of the java box crashing, that shouldn’t happen even with no audio. I believe it is due to the certain applets being removed in Processing 2.0 that this script uses, which was built in 1.5. Try installing Processing 1.5.1 from https://processing.org/download/?processing

      *In fact, the problem is P3D rendering method in size. Remove it from line after void setup() {size(512,200) ... }*

      1. Thanks for replying. After working on it all last night and giving up I found another way to go with the sparkfun spectrum shield and I seem to have it working. Don’t get me wrong it isn’t as responsive as yours (I’m jealous) but it’l do the job after a few days tweaking.

        Anyway thanks for the help and I do love your project/van!

    1. Thanks for this. I came across this from Adafruit recently, which uses a FFT Arduino library and got me thinking about optimising this. I think the library you linked uses an faster improved version of this.

      Since having started working as for acoustic consultant, I’ve got better knowledge of the octave bands and how to better use them using the log average in processing – this script could be much better on reflection. I’m working on a new project at the moment, to change the colour of an led orb based on an Leq difference from the background noise levels, to show when an office or classroom gets noisy so am going to look at using this Arduino library.

  10. Hi John, Ok, so I have Processing working Fine, But it isn’t doing anything on the arduino. Is there a sketch I am suppose to upload to the arduino for this to work?

  11. Can you please help me with the music RGB LED project? Do you have a facebook or Google plus you can share with me so we can chat? i added you to my circles on google plus.

  12. https://twitter.com/j_whittington/status/496639481584549888

    Penultimate Song: Arcade Fire – Shadows
    Last Song: Architecture in Helsinki – Off the first album, can’t remember title!

    Are you using the 3.5mm input jack or input from processing via Windows audio input? Since you talk about the transistor, I assume you’re using the 3.5mm jack, it is fairly flakey and prone to noise. Either way it sounds like the signal isn’t being received properly.

    I wrote this a while ago and it’s operation isn’t that refined. The code from this project is slightly better: Light Feedback – Playing Halo with an Arduino. It uses the audio input of the soundcard (you can plug your 3.5mm jack in here or create a virtual bridge).

    I’m working on a much better version of this at the moment :).

    1. Ahh, okay. I am using the USB version. It’s working a bit better using the link you sent me rather than stereo mix so thank you for that, but I’m fairly sure now it’s down to the transistors since 220 resistors barely let anything through. It’s starting to look a little bit like what you showed but is still mostly random. There is also a higher delay (Around half a second or so) which I’m fairly sure is the transistors also. Thanks for all your help, and I’ll see if I can pick one up somewhere.

      -Chase

  13. Dear John,

    I am currently working on a similar project and using your project as a guide, but am a bit confused in terms of how to actually get the Arduino to make the LEDs work in the certain way as you have done. What exactly is needed to be done in terms of code, software and its implementation. Would be very grateful if you could help me out, since I do not have too much knowledge interms of coding and the Arduino as a whole.

    Maybe we can communicate over Email, which could be easier. If that is fine with you, just pop me an Email and then we can take it from there.

    Thanking you

    Yash

Leave a Reply