So here I am, back with the second part of my DIY Arduino Music Lights, which will cover the programming.
If you want to check out the first part of this build, follow the link: DIY Arduino Music Lights.
Unlike akcarl, I added a 74HC595 shift register, because later on, I would like to expand this project to an 8×8 pixel screen. This makes the build slightly more complicated, but still, the circuit itself is very straight forward. Basically, it’s just 8 LEDs connected to a shift register through 220 ohm current limiting resistors. And the shift register is controlled with an Arduino.
LED anodes (longer legs) are connected to the 74HC595 chip’s pins 1-7 and pin15. The positive supply for the chip goes to pin 16 and pin 8 is grounded. Three control pins – Serial input (pin 14), Clock pin (pin 11) and Latch pin (pin 12) are connected to Arduino’s digital output pins. In my case, Clock signal (pin 11) goes to Arduino DigitalPin 4, Latch signal (pin 12) goes to Arduino DigitalPin 3 and Serial input signal (pin 14) goes to Arduino DigitalPin 5. Don’t forget to change the code, if you are using different pins on the Arduino.
More information on how to use the 74HC595 shift register can be found on the Arduino website: Arduino shift out tutorial.
The 3.5mm female audio connector’s ground must be joined with the LEDs’ common ground and the other end goes to Arduino’s AnalogPin 0.
Here’s a test run of the code below:
As I mentioned before, the code is based on Fast-Fourier-Transform (FFT), which can be downloaded from here. In short, it calculates the Discrete Fourier Transform and its inverse. In other words, it splits the audio signal into frequency bands (up to 14) which then can be represented on an LED bar.
The following code is based on this post by akcarl on Instructables, although I made some changes to use it for my project. Make sure that you place the library files exactly in ..\Arduino\libraries\FFT. Then it will appear in the library drop-down menu under ‘Contributed’ libraries.
The original code used by akcarl can be found here. But you’ll need to tweak it, if you’re using a shift register.
Here’s the code to run your LED bar:
If you want to change the frequency band that is being displayed, change the line 62, which says:”int bass = data_avgs;”
For the actual build I modified my code a little more and added extra hardware. The idea was to have a couple of different states for the lights – off, an LED chaser and music sync. It’s possible to add more modes, if you like.
The button is connected to Arduino DigitalPin 2. Indicator LEDs are connected to Arduino DigitalPins 6, 7, 8 and 9. The v2 version of the code can be found in here.
If you want to read the first part of this build, please follow this link: DIY Arduino Music Lights.
Enjoy, and until next time guys.