Go Down

Topic: Having an led flash in time with music (Read 504 times) previous topic - next topic

ro_har_

I am new to Arduino and wanting to learn more.

I have a Mega 2560 board and wondered if there is any way to have the LED flash in time with the music, not the tempo but the beat?

DVDdoug

#1
Jan 17, 2020, 05:40 pm Last Edit: Jan 17, 2020, 05:56 pm by DVDdoug
Maybe not exactly what you want, but just to get started look at my World's Simplest Lighting Effect.*   It flashes the led/light on when the signal is above average and off when below average  so it responds to the music (or other sound) with lot's of "LED action" and it automatically adjusts to the average volume.

My post includes a attached schematic for a DC bias circuit  if you want to connect a line-level or headphone-level audio signal or it will work with or LOW power** speaker connection.  The signal has to be biased because negative voltages can damage the Arduino and/or the Arduino can "damage" (distort) the negative half of the signal.

Or it will work with the SparkFun microphone break-out board, or similar, (which already has a biased output) if you want to pick-up room sound.

Quote
not the tempo but the beat?
What's the difference?

You can Google "Arduino beat detector". 

I made a crude beat detector effect but I lost the source code in a computer crash.  (Of course, the code loaded into the Arduino still works.)

- It works by comparing the current peaks to the past detected "beat peak". 

- It waits about 1/4 of a second and if an equal or higher peak comes-along it triggers, and as the milliseconds go-by it gets more sensitive so it will eventually trigger again even if the next beat isn't as strong.

- It saves that new peak level as the new reference and starts the sequence over after waiting another 250ms.

It's imperfect but as a lighting effect I like it better than a perfect and boring "1-2-3-4, blink-blink-blink-blink", all night long...



I haven't looked at other beat detector code/algorithms but I think it needs some "smarts" so it knows about when the next beat is coming.    For example, when you tap your foot to the music you don't wait to hear the beat.   You get in-sync and anticipate  when the beat is coming and subconsciously make little adjustments to stay in-sync.  (And if the song ends suddenly and unexpectedly, you'll tap your foot one extra time before you realize the music has stopped...   ;) )

I'm not sure if it helps to filter-out everything except the bass.  In most music the kick-drum "defines" the beat, but there is also bass guitar.  And sometimes the snare or some other instruments dominate the beat.






* This is really just a demonstration effect to get people started with sound-activated lighting.   I use something similar in my "real" lighting effects, but there are 2 (or more) lamps and there are a couple of variations.  Randomly-sometimes the 2-lamps blink together and sometimes they run-opposite (one is off whenever the other is on) and sometimes when working opposite lamp-A is on with loudness and sometimes lamp-B is on with loudness.   Sometimes when working together they are both inverted so louder turns both lamps off.  That keeps it a little more interesting.  And, I have several other effects that run randomly, each with random variations.


** The Arduino can be damaged by voltages above 5V so more than 1 or 2 Watts can be "dangerous".

zenkyle

im working on a similar project. check out this tut.

Go Up