Blinking LED

I am making a robot where his face is powered by LED's, and I am trying to make the LED's to flash to a pre-recorded sound, but I don't know how. I thought of taking a mono output from my laptop and using the Button Sample Sketch to flash the LED's, but it still wouldn't work. :( Are there any suggestions on how to make it work?

Thanks in Advance!

Button Sample Sketch to flash the LED’s, but it still wouldn’t work

What didnt’ work?

I thought of taking a mono output from my laptop

If you run audio into the Arduino’s analog input, you should be careful not to put-in a negative voltage, or a voltage over 5V. Your laptop’s headphone output won’t hit 5V (in fact, you’ll probably want to use the optional 1.1V ADC reference), but audio is AC, and half the waveform is negative.

With an application like this, you can simply “kill-off” the negative half of the waveform, and detect the positive half. I normally use a peak detector circuit (an op-amp circuit), but you could use a current-limiting resistor (about 1k is fine on a headhpone output) followed by a diode-to-ground on the Arduino-input, wired to “short-out” the negative voltage.*

I just finished a project with sound-activated lights. One of the “modes” is to simply flash/blink the lights to the music. It works by taking a “sample” about once a second, storing that value in an array (of about 20 elements), and then I calculate a 20-second “running average”. (Take a look at the [u]Smoothing Example[/u].)

At the same time, I’m running a fast-loop loop, reading the input every time. Whenever the input is above average the lights come on, and whenever the input is below average, the lights are off. …Very simple. And since the average is automatically updated, it adjusts to the volume level automatically. (I am doing something like the “blink without delay” example to update the average once per second, while looping and updating the LED much faster.)

Now, if this is all you are doing, you can do it with an op-amp (or two)… No Arduino or “brain chip” required. If you run the (rectified) audio signal into the op-amp’s +input, and put the average-reference voltage on the -input, plus an LED on the output. The LED will turn-on the signal is above average, and off otherwise.

A resistor/capacitor (RC circuit) can be used for averaging, and/or you could use a fast-average (less than a second) on the “real” +input, and a long (several seconds) average on the “reference” -input.

You might need a couple of op-amps used as buffers so that the RC time circuits work properly and don’t interfere with each other, but the concept will work

Or if you can use a fixed-reference, you can just use a voltage divider (2 resistors or a pot) on the op-amp’s -input. It would be best if you still use a recitifer and capacitor on the signal-input, otherwise the LED will always be off during the negative half-cycle, and you’ll only get about half-brightness from the LED.

  • Diodes don’t turn-on 'till you get 0.5 to 0.7V across them, so using a diode the “normal way” won’t work well with the headphone-level signal. Using the diode “backwards” to “short-out” the negative signal gets around this, and although you’ll do get a fraction of a volt negative going into the Arduino, that’s OK.