I have completed my project and I am really satisfied with the result. It was not difficult to make this VU meter, but I had some challenges which I solved and learned a lot. I would say that the hardest part was to put everything together: LED strips around the speaker hiding wire inside the speaker box, making settings panel and putting the microcontroller board in amplifier case.
Audio signal is biased at Vcc/2 and fed into opamp, then to ATmega328 which controls NeoPixel LED strips.
During development I was using my old mp3 player with USB and my first version of hardware seemed fine - I had a cap at opamp feedback and voltage reference circuits. They were dampening signal and removing noise. It was really surprising that the circuit met my theoretical model(!). Audio line level met standard (https://en.wikipedia.org/wiki/Line_level), but when I was almost done and connected VU meter to my PC sound card, it almost always was saturated - all LEDs had been turned on. If I reduced expected reference ADC value, VU meter of course showed lower level but still levels were barely changing. Then I read somewhere (really sorry, don't have link any more...) that audio equipment manufacturers often want that their products sound louder so they increase the audio level their devices output. The same story with my PC sound card. At the end, I have got rid of those dampening and filtering caps, fine tuned reference ADC value for my PC and I works great now (if I plug my mp3 player - max only half of the LEDs light on [scale is logarithmic]).
Another thing worth to mention is settings buttons. Came to debouncing problem, as everyone had in their lifetime. To implemet debounce in hardware, I have connected external interrupt pins to ground through resistors and put small capacitor in parallel. When button is pressed - Vcc is fed to external interrupt pins. It worked great during development - no double or triple interrupts on button press. For testing I was using my 5V 20A power supply, but when finishing project switched to be used 5V 1.5A supply, strange things started to happen - ATmega was resetting after any external interrupt button press. After some hours I made a conclusion, that during button press, when the capacitor between interrupt pin and ground is empty, it starts charging and requires quiet amount of current, thus power supply voltage drops below 5V and, I guess Arduino bootloader has brown-out detection enabled, and ATmega resets. I really did not want to make any changes to my complete PCB, so I just hooked a big cap (10mF) between PSU Vcc and GND and it solved the problem. Not a great solution, but works great.
Oh, by the way about the specs - VU meter has 4 modes:
- classic where bottom leds are green, few in the middle yellow and top - red;
- preset color;
- cycle color;
There are 2 buttons - one for changing mode and another (called "POT") for enabling potentiometer read. Potentiometer sets setting according by mode. If mode is classic or rainbow - it changes brightness. For preset color mode it changes color and for cycle color mode it changes color cycle speed. After pressing "POT" button again it saves settings to EEPROM and loads it when device is powered again (the same with changing mode).