Help creating a sound-sensing LED display

Hey everyone,

I'm learning to use Arduino for a class, currently working on a Freeduino v1.22 board. I have no prior knowledge to circuits, wiring, and coding in any language.

For my project, I wanted to create a simple sound-sensitive LED display, something not unlike those LED equalizer shirts.

Heres an example:

However, I would just want it to light up to two really bright LEDs. I've done some research but the most I can come up with is something about an electret condenser microphone, and from there I'm completely lost.

The only thing I've tried so far is to use a Piezo sensor with KnockSensor, and even then I can't even figure out how to make the LED go from:

Knock: OFF->ON->OFF
Knock2: OFF->ON->OFF

The given code on the website results in:

Knock: OFF->ON
Knock2: ON->OFF

My goal is to have the LEDs basically "sync" to the bass of ambient music (say, for concerts).

Any help would be greatly appreciated. Noobs need loving too.

And for anyone curious, I'm trying to make the eyes of my Deadmau5 head light up: http://imgur.com/mnMzP.jpg

For full sound to lights it is simplest if you get help from external hardware, see this project:-
http://skoba.no-ip.org/msgeq7/index.html

The given code on the website results in:

First thing you need to do is to learn how to read software. Pretend to be the computer, take one line at a time and ask your self the question "what does that do?", you will have to look it up at first but you will get the hang of it. Try reading some of the tutorials and even doing some. If you want specific help then post the code you have (use the # button in the reply box) and we will say where you are going wrong.

Woops, sorry about that. Heres the code that I currently have set up for Knock Sensor:

/* Knock Sensor
 * ----------------
 *
 * Program using a Piezo element as if it was a knock sensor.
 *
 * We have to basically listen to an analog pin and detect 
 * if the signal goes over a certain threshold. It writes
 * "knock" to the serial port if the Threshold is crossed,
 * and toggles the LED on pin 13.
 *
 * (cleft) 2005 D. Cuartielles for K3
 */

int ledPin = 13;
int knockSensor = 0;               
byte val = 0;
int statePin = LOW;
int THRESHOLD = 100;

void setup() {
 pinMode(ledPin, OUTPUT); 
 beginSerial(9600);
}

void loop() {
  val = analogRead(knockSensor);     
  if (val >= THRESHOLD) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    printString("Knock!");
    printByte(10);
    printByte(13);
  }
  delay(100);  // we have to make a delay to avoid overloading the serial port
}

I want to set it so that each Knock turns on the light but turns it off as well right after.

However, I don't think the Piezo sensor is the right tool to use for my project, since it only picks up direct almost physical "taps". Perhaps a microphone.

Thanks for the insightful Grumpy!

Here is a link to a Sparkfun thread that is pretty much what I'm aiming for. All the tech talk is going way over my head, and I'm somewhat stuck in a timecrunch.

http://forum.sparkfun.com/viewtopic.php?f=14&t=11430

Here is the code provided in the thread:

int audioIn = 1;
int val = 0;

void setup() {
pinMode(audioIn, INPUT);
Serial.println(9600);
}

void loop() {
val = analogRead(audioIn);
Serial.println(val);
}

From here, I'm completely clueless. I don't know what code to add, where to add it, and I'm not even sure if its wired together right.

Current setup:
Electret Condensor Microphone
VCC -> Arduino 5v
Ground-> Arduino Digital Gnd
Output->Arduino Analog 0-Pin

-EDIT-

Here is more code I found online (http://www.dtic.upf.edu/~jlozano/interfaces/microphone.html), hopefully this one proves more helpful

// these constants won't change:
const int ledPin = 13;      // led connected to digital pin 13
const int electret = 0;  // the amplifier output is connected to analog pin 0


// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int sensorMax = 0;
int sensorMin = 500;
int threshold;


void setup() {
  pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
  Serial.begin(57600);       // use the serial port
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  while (millis() < 3000) {
    threshold = analogRead(electret);

    // record the maximum sensor value
    if (threshold > sensorMax) {
      sensorMax = threshold;
    }

  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);
  threshold = sensorMax;

}

void loop() {
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(electret);    

  // if the sensor reading is greater than the threshold:
  if ((sensorReading >= threshold)) {
    Serial.println(sensorReading-threshold); //Will send only positive and absolute values of waveform         


  }



  delay(2);  // Better for Processing showing data
}

You have an electret microphone? If so, you'll definitely need some additional amplification. Fortunately everything you need for this circuit should be available at Radio Shack since time is short.

How about you post the hardware you already have. Somewhere at home I have a simple circuit that worked well with an electret mic, I'll look for it later tonight.

I did some research and after a quick run to Radioshack, heres a list of what I have:

-Arduino Freeduino v1.22
-Electret Condenser Microphone (RadioShack.com Official Site - America's Technology Store)
-A whole lotta LEDs
-A whole lotta resistors
-LM386 Amp
-2 x 22p capacitator
-3 x 0.1u capacitator
-Breadboard

andddddddd... that's about it. Thanks for the help, macegr!

Unfortunately couldn't locate the circuit that I was trying to find...it was really just an electret preamp like you'll find on the SparkFun board or around the web: http://www.sparkfun.com/datasheets/BreakoutBoards/Amplified-Mic-Electret-v14.pdf

And there's another circuit you might find useful. Trying to filter the audio in software might not work too well. I use this circuit to rectify the audio and do a peak detection. You could combine the two circuits by getting rid of everything to the left of R5 on the VU circuit and connecting the output of the electret preamp through a 10uF capacitor. Run the output into an analog input of the Arduino and you should be able to do sound reactive stuff pretty easily. You could use a single opamp chip like the LM324 to do everything, it has four opamps.

Maybe you can hack something with just a single diode and capacitor for the peak detection, but it won't respond to low levels, which will be pretty crucial if it's listening to ambient sound. In all cases you can't omit the electret preamp circuit, there's just no other way to get enough signal out of it.

Another option is to use some device that already has a good microphone and can output amplified audio. One example would be an iPhone, you can get apps that just input audio and play it out the headphones with volume adjust. This could also let you play your own music, if you split off some amplified speakers.

Good luck...time is short