Musical Ball

Hi,

I'm trying to build the project listed here (its in Spanish)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277468653/

I've connected all the wires properly and used the code provided, but I seem to get weird results.

Instead of the RGB LED changing colors acoording to the analog input, I'm finding that the LED is constantly blinking in all 3 colors. The other colors are not turning off when one color is supposed to turn on at a time. Ex. Red is constantly blinking while blue and green are constantly blinking at the same time. Red is supposed to blink by itself acoording to the input of the elecret microphone.

Here's the code provided:

/*
////////////////////////////////////////////////////////////////////////////////
  Bola musical luminosa

 Es una bola que reacciona a la presion sonora iluminandose.
 Según el nivel se ilumina secuencialmente  en azul, verde y rojo.

 El circuito:
 * LED RGB de 4 patillas. Ánodo conectado a 5v, cátodos conectados a
   pines 9,10 y 11 y luego a tierra a través de resistencias de 220 Ohm.
 * Microfono preamplificado en pin analógico 0. (yo use el Breakout Board
   for Electret Microphone sku: BOB-08669 de sparkfun ).
   Tambien se puede utilizar cualquier elemento que nos proporcione un
   voltaje variable hasta 5V.

 Vídeo:                        http://www.youtube.com/watch?v=_QrF_CfAFEY
 Mira tambien:                 http://www.youtube.com/watch?v=hckZEcqkg40


 creado el 22 de junio de 2010
 Por Alejandro Taracido Cano (TCRobotics)
 Canal de youtube:             http://www.youtube.com/user/TCRobotics
 ///////////////////////////////////////////////////////////////////////////////
  Musical ball light
  
 It is a ball that reacts to the sound pressure with light.
 According to the sound level it sequentially lights in blue, green and red.
  
 The circuit:
 * 4-pin RGB LED. 5v connected to anode, cathodes connected to
   pin 9,10 and 11 and then to ground through 220 Ohm resistor.
 * Analog microphone preamplifiers in pin 0. (I use the Breakout Board
   for Electret Microphone sku: BOB-08 669 from SparkFun).
   You can also use anything that will give us a variable voltage
   between 5 and 0 volts.

 Video: http://www.youtube.com/watch?v=_QrF_CfAFEY
 See also: http://www.youtube.com/watch?v=hckZEcqkg40


 created 22 Jun 2010
 By Alejandro Taracido Cano (TCRobotics)
 Youtube channel: http://www.youtube.com/user/TCRobotics
////////////////////////////////////////////////////////////////////////////////
 */
int MicPin = 0;          // pin that the mic is attached to

int redPin = 9;          // pins that the cathodes of LED are attached to  
int greenPin = 10;
int bluePin = 11;

int MicValue = 0;        // the Microphone value

void setup() {
  //Serial.begin(9600);  //for test the input value initialize serial
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  analogWrite(redPin, 255);       //turn off all LEDs
  analogWrite(greenPin, 255);
  analogWrite(bluePin, 255);
}

void loop() {

  MicValue = analogRead(MicPin);  //read the value of the microphone

  //Serial.println(MicValue);     //for test the input value

  if (MicValue > 530) {     //adjust this value to the desired sensitivity
    analogWrite(bluePin,0); //lights up blue
    delay(15);              //small delay for quick response at low noise levels
    }
  
  if (MicValue > 540) {       //adjust this value to the desired sensitivity
    analogWrite(bluePin,255); //lights up green and turn off blue
    analogWrite(greenPin, 0);
    delay(60);               //mid delay for response at mid noise levels
    }
  
  if (MicValue > 550) {        //adjust this value to the desired sensitivity
    analogWrite(greenPin,255); //lights up red and turn off green
    analogWrite(redPin, 0);
    delay(140);                //high delay for response at high noise levels
    }

analogWrite(greenPin, 255);    //Turn off all LEDs
analogWrite(redPin, 255);
analogWrite(bluePin,255);  

}

Also, the electret microphone seems to be outputting values around 500. When I talk into the microphone it doesn't seem to change much unless I actually tap the microphone (which then prints values of 0 and around 1000). Could this be the problem? I've connected AUD to analog input 0, GND to ground, and VCC to 5V.

Thanks for any help.

Also, the electret microphone seems to be outputting values around 500. When I talk into the microphone it doesn't seem to change much unless I actually tap the microphone (which then prints values of 0 and around 1000). Could this be the problem?

That is what I would expect, you microphone only provides a tiny amount of voltage it will need amplifying.

I've connected all the wires properly

The wiring in that link is total rubbish. You don't wire up an RGB LED anything like that. You appere to be sinking current through the arduino when it is on and through the resistor when it is off. I would expect the LED to be on all the time and get brighter when the arduino's output is low. I also would expect that the arduino and the LED will be damaged with this circuit as there is no effective current limiting resistor. The resistors that are in are in the wrong place to limit current.

That is what I would expect, you microphone only provides a tiny amount of voltage it will need amplifying.

I used the breakout board on the link provided which claims to already amplify the microphone. Should I amplify the circuit even more? Thus, using another op-amp?

The wiring in that link is total rubbish. You don't wire up an RGB LED anything like that. You appere to be sinking current through the arduino when it is on and through the resistor when it is off. I would expect the LED to be on all the time and get brighter when the arduino's output is low. I also would expect that the arduino and the LED will be damaged with this circuit as there is no effective current limiting resistor. The resistors that are in are in the wrong place to limit current.

I've connected the LED as such in this link:

Pin 1: "Red" to Digital 9
Pin 2: Ground
Pin 3: "Green" to Digital 10
Pin 4: "Blue" to Digital 11

I'm not sure how to connect it any other way. Thanks again for the help.

Should I amplify the circuit even more?

Yes or shout louder.

That way is the right way to connect a common cathode RGB LED (is that what you have?), it is not the way that was shown in that first link.

So what way have you got it wired up? The code assumes current sinking but this correct way you just posted is current sourcing so the code is backwards for that.

Ok, I'll try to connect the microphone to another pre-amp circuit tonight.

So what way have you got it wired up? The code assumes current sinking but this correct way you just posted is current sourcing so the code is backwards for that.

I wired the RGB LED just as I wrote in my second post. The link I provided had the second pin going to power (current sinking?) and I connected it into ground (which I believe is correct).

I'm trying to find where I should modify the code, but my programming experience isn't as great as it should be. :-/ How should I fix the code for "current sourcing"?