Arduino Uno - Color Organ with Electret Mic and LEDs Troubleshooting

Hello,

I apologize in advance if this is the wrong subforum.

I'm trying to do a rudimentary color organ with an Arduino UNO, a Sparkfun Electret Microphone breakout board (https://www.sparkfun.com/products/9964). I'm currently testing it with 3 of these LEDs (https://www.sparkfun.com/products/10632).

WIRING

I have each of the LEDs hooked up to a digital output pin. A 270 Ohm resistor connects each LED back to ground.

The microphone is wired so that: Voltage goes to Arduino's 5V Signal goes to pin A0 Ground goes to Arduino's Ground (I've seen people use anywhere between no resistance to 10k resistors to ground but the best results I've gotten is with no resistors)

CODE

I understand that this microphone returns a wave form so I process the signal as follows: volume = abs(AnalogRead(Microphone_Input) - 750) With no ambient nose the microphone returns ~750 without any processing, I subtract 750 to give a no-noise reading of 0.

My plan is to use if loops and different thresholds of volume magnitude to light LEDs. IE if the volume is greater than 100, light one LED. If greater than 200, light 2 LEDs. Etc.

int red = 13;
int blue = 12;
int green = 11;
int mic = A0;

void setup() {                
pinMode(red, OUTPUT);   
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(mic, INPUT);
Serial.begin(9600);
}

void loop() {

int volume = abs(analogRead(mic)-750);
Serial.println(volume);
delay(75);

if (volume > 200) {
 digitalWrite(red, HIGH);
}
else digitalWrite(red,LOW);

if (volume > 300) {
 digitalWrite(green, HIGH);
}
else digitalWrite(green,LOW);

if (volume > 400) {
 digitalWrite(blue, HIGH);
}
else digitalWrite(blue,LOW);

}

ISSUE

My current issue is that I can't get a stable reading from my microphone. If the microphone is the only thing wired to the arduino I get believable values, 0 at no noise and spikes to 300 when I clap. The moment I wire in even one LED the signal jumps between 0 to 600 or consistently oscillates between 200 and 600.

Other times the code will start at normal readings but the moment it detects a sound the signal will erratically bounce everywhere.

I feel like there is a wiring error or an electronic limitation on the Arduino UNO I'm not aware of that is preventing me from reaching my goal. Does anyone have any suggestions on what to troubleshoot?

I think you need resistors in series with leds, 200 OHm or so

Whoops, forgot to mention that I'm connecting them back to ground with 270Ohm resistors.

Post your code, and wiring diagram

I've updated my main post with my code and wiring.

On diagram A0, in code A1?

Sorry, I tried to change the analog pin thinking that was the cause of my issues at one point. My diagram/code has been corrected.

Thanks for your patience while helping me!

I don't see any problem with a code, except you don't need this line : pinMode(mic, INPUT); What is the power source? Strange things you are reading 750, should be close to 512. You can try to power mic board from 3.3V, of course all scale has to be scaled down

At the moment the power is coming from my computer via the USB connection. I plan on supplying my final project's power via a battery pack.

It's very strange; the input will look realistic for moments and then destabilize. Wiring LEDs exacerbates the problem.

I've been fighting this for a while. I've ruled out bad microphone hardware as I've bought another one and am experiencing the same issues.

Does this seem like an issue caused by a damaged Arduino board? I know that's a very vague hypothesis but maybe this is a symptom of a fried board?

Do you have a DMM?
I find it unusual, as I sad that you are reading 750. To completely cross out a mic board from suspects list, you need a DMM to measure VCC and VCC/2 at audio out. Other scenario, wire a pot instead of mic, and rotating try to simulate an issue