3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Yet Another Daft Punk Coffee Table (5x5 LED Matrix)

Step 7Music Synchronization

Music Synchronization
«
  • rclp133hz.jpg
  • lpmixer133hz.jpg
  • lpfilter.jpg

Circuit Modifications

To allow our LED matrix to synchronize the animations to music, we need to interface it to an audio source. The ATmega328 MCU conveniently contains A/D converters which we can use for this purpose. Although there are various designs for color organs, which work with various frequency bands, I prefer syncing with the bass track.

We could use an analog pin to sample music, and then do frequency analysis on the Arduino, but this would introduce a delay, and still require us to build an antialiasing filter. Since we need to build a filter, we might as well keep things simple. I built an analog low pass filter, fed its output into an analog input in, and then simply tested the amplitude against a threshold.  I started with a the simplest possible filter, a first order low pass RC filter.  Much to my surprise, it worked fairly well.  To design the filter, I first needed to figure out what cutoff frequency to use.  The cutoff frequency, Fc,  of a filter is the frequency where the power is cut in half.  After playing around with graphic equalizers in Winamp while playing music with thumpy bass tracks, I settled on Fc = 100Hz.  I didn't have the proper resistor handy, so I used the closest value I had, which resulted in Fc = 133Hz.  Here is the circuit:

Parts Needed:
(1) 10uF electrolytic capacitor
(1) 120 ohm resistor
(1) 1/8"  TRS jack



The output connects to analog pin 0 on the Arduino.  Connect its input to an audio source, such as the headphone jack of a stereo, or an MP3 player.  DO NOT CONNECT IT TO SPEAKER LEVEL OUTPUTS FROM AN AMPLIFIER UNLESS YOU'RE SURE IT OUTPUTS <= 5V.  Any audio source designed to drive headphones should be safe.  Since I use the headphone jack on a stereo, I can still hear the music even when the circuit is plugged in.  If you're using something with only one output, such as an MP3 player, you can hook up two TRS jacks in parallel, and then feed the audio from the 2nd jack to a set of powered speakers or headphones.

Note that the circuit above only monitors one channel of audio, which works with most songs, since the bass is generally approximately equal amplitude in both channels.  It works OK, but I found that in order to get a high enough input for the Arduino to respond nicely, I have to turn the volume up a bit too high for my tastes.  Therefore, I also built the alternate circuit below:

Parts needed:
(1) 10uF electrolytic capacitor
(1) 120 ohm resistor
(3) 10K ohm resistor
(1) 100K ohm resistor
(1) 1/8" stereo TRS jack
(1) TLC272CP op amp IC



UPDATE: Sorry, the schematic diagram above is wrong.  There should be a third 10K resistor, R5, which connects between pin 2 (- input of opamp) and GND.  The gain of the amp is R4 / R5.

You can substitute any suitable op amp. I used the TLC272CP because that happens to be what I had on hand, and it has the particularly nice characteristic that it doesn't mind running on a single-ended power supply of only 5V, so I could just hook it up to the Arduino's power.  The circuit above mixes the left and right audio channels, and has a gain of 10.  Just hook it up to your stereo audio source, and connect the output to analog pin 0, as before.  The 5V and GND also connect to your Arduino.

If you prefer to use a microphone rather than direct wiring, pepehdes has posted an alternate circuit using an electret mic in Step 1's comments, which he says works well.  Note that it is an all-pass design so it will trigger on all frequencies, not just bass.  I didn't use a microphone, because my design tracks the bass which might not be picked up very well via small speakers and a microphone.
 
Sketch Revisions

Next, we need to modify the sketch to read the audio input, and trigger the next animation frame when a threshold is exceeded.  The new sketch, daftPunkSyncV2.zip, is attached below.  You can switch the sketch between music sync and free-running by modifying
 

   // musicSync =1= sync to music
   //                      =0= use timer
   int musicSync = 1;

 

You will need to manually tune the threshold variable:

   // trigger next frame when music amplitude > threshold
   // increase threshold to decrease sensitivity
   // decrease threshold to increase sensitivity
   int threshold = 5;

The next frame will be triggered when the input read from analog pin 0 exceeds threshold.  If you're running the sketch on a real arduino that has an LED on digital pin 13, it is helpful to uncomment the following line:

   #define BLINKY // blink LED on pin 13

by removing the leading // characters.  This will cause the LED to blink when threshold is exceeded.  I have it turned off in the sketch by default, because I'm using my tiny breadboard instead of an Arduino now, and it doesn't have an LED.  Finally, you may want to experiment a bit with minBeatInterval:

  // debouncing - filter out consecutive triggers that are too close
  // together to slow down the animation. decrease this value
  // to make it more sensitive to shorter beat intervals
  int minBeatInterval = 1000;

Note that this variable is unit-less.  It simply defines how many consecutive loops after the input exceeds our threshold before the sketch is allowed to trigger the next frame.  I found that in many songs, bass beats are actually composed of several very closely spaced peaks.  If we don't filter them out, then the display will advance several frames for each beat.  You might actually like this effect, because it makes the display more lively.  Play around with it, and see what setting you prefer.
 

« Previous StepDownload PDFView All StepsNext Step »
12 comments
Dec 10, 2011. 4:48 PMmoiguille says:
please, I need help with my 5x5 matrix, when installing the program on the Arduino and connect (correctly to the matrix) does the sequence just programmed LED lights a while in order by rows. could help me to know that I'm doing wrong.
Oct 6, 2011. 10:02 PMbostondrummer1 says:
So the only time I can get this thing working is when I have the threshold set to about 884. Then it doesn't even follow the music much, and changing the music usually leads to a need for a new threshold. Any ideas?
Jun 4, 2011. 12:16 PMpsychodot5415 says:
I am setting up a Christmas light show similar to that shown in Arduino Christmas Light Controller instructable. That one gives a sketch for Joy To The World. I like what you have done in step 7, using an audio source to drive the Daft Punk show. If I copy what you have done for that step, and use analog pin 0 as an input, do you think it would work with the Christmas light show? Looks like I would need to share the 5V power source between the light controller and the audio source.
Aug 12, 2011. 5:39 PMpsychodot5415 says:
I finished my project and published. http://www.instructables.com/id/Arduino-Christmas-Light-With-Music-Sync/ Thanks for use of your code.
Mar 30, 2011. 9:59 AMsteaming punk says:
hi, can i use your circuit without aurdino, just add a tip31 transistor for leds to your analog pin 0 ? also what voltage this uses, is 9v okay ?
Mar 8, 2011. 11:00 AMantipico says:
It's alright, I got it. Your instuctable inspired me to build an analog 5x5 led screen driver, analog since I'm not (yet) into programming. It runs on two synced decade counters and 555 timers, pictures on screen are created with combination of diodes. But I wanted more from my big (2.5' x 2.5') screen so I actually finally bought myself a couple arduinos. First thing I got your SyncV2 sketch running and it works great, the frames creator is also very helpful. So I could thank you for giving me the final kick to change from analog circuits to the much more vast world of arduinos!

PS. Here's the first test on the soon-to-be-trashed analog rip-off and my big screen :)
http://www.youtube.com/watch?v=WmJceEuIPD4
Mar 8, 2011. 6:27 AMantipico says:
"Connect its input to an audio source, such as the headphone jack of a stereo, or an MP3 player. DO NOT "

Sooo.. Do I connect it or not?

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
32
Followers
2
Author:lincomatic(Lincomatic's Blog)
For more information on my projects as they develop, visit my blog: http://blog.lincomatic.com