Final Lightbar Controller

I’ve finished the lightbar controller!

Lightbar Visualiser

This device analyses the music it picks up via the electret microphone, then flashes the LEDs in time to the music. It’s encased in the box SparkFun sent me the microphones in, since the box was just begging to be used as a case for something! I’m sure that was intentionally designed.

Lightbar Visualiser

Getting a bit more technical:

The microphone picks up the noise and sends this to the LM386 amp, which amplifies it about 200x before it’s read by the ATtiny13’s ADC at 8-bit resolution. The ATtiny13 then keeps a running average of the noise level, and flashes the LEDs if the current volume exceeds the average by a scalar amount.

Lightbar Visualiser

As a result, the LEDs flash on when the music hits a peak, and are off otherwise – no matter what volume.
The brightness of the LEDs is also somewhat correlated to the loudness of the peak, since a louder peak will generally keep the LEDs on for longer.

Check out the video of it in action:

Download the schematic, PCB layout, code:
https://randomskk.net/projects/lightstrip/ (all files released under Creative Commons BY-SA-NC 3.0).

31 Responses to “Final Lightbar Controller”

  1. [...] – SparkFun – Light bar controller Read more | Permalink | Comments | Read more articles in Electronics | Digg this! Source: MAKE [...]

  2. [...] an interesting DIY light bar controller that might interest your weekend hacking desires. This device analyses the music it picks up via [...]

  3. hi, i’m very intested in your project.
    i was reading the code and find some weird stuff.

    firstly, avg isn’t initialised does it matter?
    secondly, all your variable are char type. i guess it’s an error?

  4. avg not being initialised – nope, it doesn’t matter because avr-libc automatically initialises all variables to 0. Bad coding practise, though!
    Char type isn’t an error, either – it can be used as a one-byte integer which is all I need. It’s basically the same as uint8_t but quicker to type.

  5. thanks, i’m going to translate your code for an 16F88 an see what i get.
    i’ve done a similar thing but it wasn’t really ideal.
    i kept all frequency below 100Hz and 0V = duty 0% and 1.2V = 100% it’s was only working with the maximum volume.

  6. one last question (i hope^^) when duty = 250, duty cycle is at 100% ?

  7. In my case, duty varies from 0 to 100. Those two last for loops set the LED on, do three nops for each iteration i

  8. well, after re-reading your code, if i understand correctly you light the led if the audio signal (without the negative part) is 1.3 times superior to the average, am i right?

    how much time last a nop? (in µs)

    each time the lead are turned on, the las loop do 300 nop

  9. Right, if the audio signal is 1.3 times average – you can change this for your microphone, amplifier etc since it makes the biggest difference on what volumes turn it on.
    A nop is one clock cycle long – on a 16MHz clock, that’s 1/16000000 of a second, while on a 1.2MHz that’s only 1/1200000 seconds.

  10. Do you have a BOM for this? What are the in/output voltages? Can I use less LEDS? I have a cool project i’m trying to do and am trying to redo a board like this to fit in a 0.70″ ID tube… Any help would be great….

  11. Brilliant!

  12. when i compile this in avr studio, it says the code is much to large to fit on an ATtiny13.

    (250.4% full for program space, 412.5% full for data)

    i’m using avr studio 4, and winavr 20080512

    any suggestions?

  13. That’s pretty odd. I can only imagine AVR Studio is adding lots of useless header files or something. Check the optimisation settings – when I compile this on avr-gcc I’m using -Os which optimises for minimum size.

  14. i am compiling with avr-gcc and using -Os. I am pretty sure it’s just adding useless libraries, but i’m not really sure how to stop it since the only #includes are the ones that are in your code…

    could you send me the .hex file so i don’t have to worry about how it’s compliling?

  15. Sure thing, here you go:
    https://randomskk.net/projects/lightstrip/lightstrip.hex

  16. I figured out the cause of the problem. When I compile with “PEAK” as 1.3, the code size is huge. When I compile with “PEAK” as a non-float number, it’s small and fits the attiny13. Do you get a significant change in code size when you do this?

  17. 8bits micro controllers are not made for floating point instructions so ofcorse it will make a huge difference when you use floating points

  18. How about a .pde of this? You have splendid documentation, and this in Arduino code would help MILLIONS!

  19. The C code linked above would probably be fairly easy to modify to work with an Arduino, but it’s written for an ATtiny13 (a somewhat different micro) and uses its peripheral control registers generally in ways the Arduino doesn’t provide functions for, so the resulting ported code would have very few, if any, actual Arduino functions.

    More importantly, all this code is really doing is reading the ADC repeatedly then flashing an LED – this is a fairly straightforward task, and the difficult part is really amplifying the microphone to get a useful signal, which is done in hardware.

    Of course, everything is released under a creative commons license, so anyone is welcome to port it and tinker with it and improve it.

  20. In fact I like your project and the way it works, but I would easily make it without using any microprocessor.
    Just a couple of transistors would do.

  21. Thanks! I realise a transistor system could switch the LEDs when the voltage reached a certain level, but I’m not sure how it could analyse the noise level over time to change the activation voltage dynamically – that’s mainly what the microprocessor is doing in this case.

  22. Hmmm. I’m playing with an audio project on a PIC 16F819 now, which has 3 A2D’s and allows you to set your own VREF for + and -. So I put it together going right from the output of the electret mic’s decoupling cap, no amp.

    It works well for moderately loud noises, and great for yelling and clapping, but not for “normal room noise”.

    Using your 386 op amp, how sensitive is the noise floor for this whole thing? Does the noise have to be loud, or can you tune it for normal ambient noises?

    That Sparcfun mic is one of the more sensitive ones I have seen, so that probably makes the difference. My mic is whatever was in the box at Mendelsons that they were selling by the bucket :)

  23. In my application the sensitivity is pretty poor, but this leads to better synchronisation with the music as other noises (typing on the keyboard, talking, etc) are ignored. I haven’t tested it extensively but I don’t believe the sensitivity is brilliant for long ranges like a room – I get the feeling it is better for noises very nearby which obviously are louder for it. In other words, great to talk into it, not great for picking up noises in the room. You may want to try either a better (not electret, for one) microphone or some kind of noise amplification.

  24. Hi I just found your project and I’m an fairly new EE student and I’m working on a similar project involving this mic was just wondering what your Vcc value was. Thanks looks great

  25. Heya. Vcc is 5V coming out of a 5V linear regulator IC3 at the top-right of the schematic.

  26. Hey thanks i see it now guess i wasnt looking hard enough I seen the voltage regulator in your schematic but missed the rest. Thanks again

  27. Hi, i am doing a project involving noise detection and motorspeed control. I was wondering, where did you buy your amp?
    thanks. i’m new to all this, great project!

  28. I got the amp (and most of the parts) from Rapid Electronics in the UK (see my Suppliers page). In the US, I hear Digikey and Mouser are good for that sort of thing.

  29. Cool project! I’m actually turning your code into a high speed strobe photography rig. Unfortunately, you code has several build errors. I diagnosed several of them myself, but just to let you know…

    In file included from ../HighSpeed.c:8:d:/program files/winavr/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning “This file has been moved to .”
    In file included from d:/program files/winavr/lib/gcc/../../avr/include/avr/delay.h:37,
    from ../HighSpeed.c:8:

    d:/program files/winavr/lib/gcc/../../avr/include/util/delay.h:90:3: warning: #warning “Compiler optimizations disabled; functions from won’t work as designed”

    ../HighSpeed.c: In function ‘main’:
    ../HighSpeed.c:54: error: ‘for’ loop initial declaration used outside C99 mode
    ../HighSpeed.c:57: error: redefinition of ‘j’
    ../HighSpeed.c:54: error: previous definition of ‘j’ was here
    ../HighSpeed.c:57: error: ‘for’ loop initial declaration used outside C99 mode

    make: *** [HighSpeed.o] Error 1
    Build failed with 4 errors and 2 warnings…

  30. Thanks for the heads-up. I think you’re using a different version of the AVR libc, which is causing the warnings about delay.h.
    The errors are definitely just bad code – you should be able to just define an “int j;” earlier on and then “for(j=0…” later to fix them.

  31. [...] circuit and code itself was based on a part of the circuit and code I found at Negative Knowledge.  One point to notice is that the LEDs are connected in parallel, usually a no-no, but in this [...]

Leave a Reply