Final Lightbar Controller
I’ve finished the lightbar controller!
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.
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.
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).



[...] – SparkFun – Light bar controller Read more | Permalink | Comments | Read more articles in Electronics | Digg this! Source: MAKE [...]
Daily DIY Network - Science Projects Plans Guides » Blog Archive » Light Bar Controller said this on June 14th, 2008 at 4:00 pm
[...] an interesting DIY light bar controller that might interest your weekend hacking desires. This device analyses the music it picks up via [...]
DIY Sound Sensitive Light Bar Controller! | zedomax.com - Obsessively profiling DIYs, Hacks, Gadgets, Tech, Web2.0,and beyond. said this on June 14th, 2008 at 8:52 pm
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?
sliders_alpha said this on June 20th, 2008 at 6:49 am
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.
Random said this on June 20th, 2008 at 7:59 am
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.
sliders_alpha said this on June 20th, 2008 at 5:25 pm
one last question (i hope^^) when duty = 250, duty cycle is at 100% ?
sliders_alpha said this on June 20th, 2008 at 7:55 pm
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
Random said this on June 20th, 2008 at 9:12 pm
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
sliders_alpha said this on June 22nd, 2008 at 9:19 am
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.
Random said this on June 22nd, 2008 at 8:48 pm
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….
Gavin said this on July 25th, 2008 at 5:59 pm
Brilliant!
Feepkilm said this on August 3rd, 2008 at 5:19 pm
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?
matt said this on August 25th, 2008 at 2:26 am
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.
Random said this on August 25th, 2008 at 12:46 pm
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?
matt said this on August 26th, 2008 at 3:52 am
Sure thing, here you go:
https://randomskk.net/projects/lightstrip/lightstrip.hex
Random said this on August 26th, 2008 at 3:23 pm
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?
matt said this on August 27th, 2008 at 2:50 am
8bits micro controllers are not made for floating point instructions so ofcorse it will make a huge difference when you use floating points
henk said this on September 18th, 2008 at 5:30 am
How about a .pde of this? You have splendid documentation, and this in Arduino code would help MILLIONS!
CreativeCommons said this on November 24th, 2008 at 5:24 pm
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.
Random said this on November 24th, 2008 at 5:34 pm
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.
ANDUS said this on January 26th, 2009 at 9:30 am
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.
Random said this on January 26th, 2009 at 11:27 am
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
BillKilgallon said this on February 13th, 2009 at 7:06 pm
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.
Random said this on February 13th, 2009 at 7:52 pm
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
Justin said this on March 5th, 2009 at 8:14 pm
Heya. Vcc is 5V coming out of a 5V linear regulator IC3 at the top-right of the schematic.
Random said this on March 5th, 2009 at 8:22 pm
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
Justin said this on March 5th, 2009 at 8:54 pm
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!
simone said this on March 8th, 2009 at 7:42 pm
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.
Random said this on March 8th, 2009 at 7:52 pm
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…
etharooni said this on March 27th, 2009 at 2:10 pm
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.
Random said this on March 27th, 2009 at 2:53 pm
[...] 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 [...]
Flashing LEDs – Audio Meter – AVR ATTiny – Guitar Pickup Wiring – Sound Following Circuit said this on December 13th, 2009 at 11:11 pm