Music Controlled Colored Light
I became interested in understanding more about processing sound, and relating that to frequency distributions.
I had the idea of making a device always listening to the environment and to color a light based on the sharpness of the sound it heard.
Ideally, it would be something that looked nice and would be welcome in your living room all the time as something to look at as music played.
Electret microphone (first time)
3-color LED, driven by PWM via hardware timer/counters
Research and Build
The premise of the visual design:
- There is a 3-color LED in use
- Purplish-blue is a nice color to look at generally
- So that is the color I want to use when “usual” or “soothing” sound is present
- Green is kind of ugly
- So that color will be mixed in when there is a sharp increase in high-frequency sound or unusual intensity
The program is always listening, constantly looping, each loop consisting of:
- Gather 256 audio samples
- Calculate frequency distribution bins
- Figure out how much Red, Blue, and Green to indicate based on frequencies observed
Additionally, I added a time-decay value in such that:
- If there is a sharp increase in the upper frequencies, the color would respond immediately
- If a prior high-frequency vanished, the “high-frequency” color would take time to decay to zero
I had to empirically tweak the frequency ranges to examine for setting the LED colors.
Hardware PWM was used in place of CPU PWM since the CPU was going to be tied up 100% of the time gathering and processing audio signals.
In code, getting fast acquisition of ADC samples required understanding better the underlying mechanisms the AVR uses to get samples, and lessen the accuracy in order to get samples more quickly.
I purchased a nice wooden “thing” with a lid from Etsy to put the electronics in.
A bit of drilling/gluing allowed the installation of the microphone and power jack.
Main file here (link)
Supporting libraries under here (link)
Build Photos and Demo Video