Don’t take this as an insult, but you’re probably in over your head. You need to scale the project goal way back and get through the basics first.
I’m going to tear your project to bits here. Don’t be offended, you just need to know what you’re doing wrong. OK? Here goes:
Your pictures are WAY too big. Before posting, resize them to no more than 1000 pixels wide. Viewing them in the forum requires a ton of scrolling just to follow your wires.
You didn’t put a current-limiting resistor between the output pin and your LED. Consequently, you may have burned up your LED, or your output pin, or both. If they’re both OK, they may not be for long. Stick a 220R to 1K resistor in between.
You didn’t post a schematic or a datasheet for the mic, but from what I can see, you’re using an electret mic capsule connected to an analog input with no pull-up resistor. The mic is not powered and will not produce a usable signal this way.
You’re reading the analog value and dividing by 50. Why?
You have a conditional that checks if the analog value is less than 0. In the real world, your chances of having an analog reading stay at one value is very small due to noise and natural fluctuations. You need to be checking for a small range, or within a threshold (e.g., <10). Tune as needed.
Checking for 0 = silence is not correct for an audio signal anyway. Audio is AC, and as such, needs to swing above and below a reference voltage. In typical single-rail (one voltage) audio circuits, that means you have to create a 1/2 * Vcc rail (e.g., 2.5v) so your signal can swing between 0 and 5, with 2.5 being the middle – i.e., silence. This is tricky though, because you also have to know what analog value corresponds to no signal, and then get the difference between this “zero value” (ideally 511, which is 1023/2) and the reading from your mic. Then, you take the absolute value of the result to get your signal level. If the electret mic is the type that has a Gnd and Vcc/Out pin driven by a resistor, then it has an internal divider to allow AC swing around a set point, however, you won’t have a good way to read that reference point to calculate the audio signal offset, so you might need to run it through a DC-blocking cap, and provide your own Vcc/2 rail for comparison.
#5 is the part where most electronics newbies throw in the towel, but there are a lot of guides out there with basic circuits to do what you want to do. If you don’t understand how it works, just copy one that already does.
- I’m not really sure what you were hoping to accomplish with this:
for (i = 0; i < left; i++)
… I assume it’s an attempt to vary the LED’s brightness based on signal level. That isn’t what it does though. It just turns the LED on (value of left) times. This does nothing different than just turning it on once, aside from taking a tiny amount more time to complete the loop. If you were hoping to vary the brightness, you’ll want to look into PWM instead.
- Same goes for this part:
for(i = i; i < 10; i++)
… except you’ve arbitrarily chosen a value of 10 to stop for some reason. The first time through the loop, the LED turns off. And it doesn’t turn any offer the next however many times it runs. Since this loop exists right after the on loop, you’re not likely to see the LED ever light up at all. Depending on how fast the entire loop() function runs, you may get a very dim light that kinda varies with the signal level, but it probably won’t work nearly as well as you’re hoping for.
So, definitely start with something simple. Find and copy a known-good schematic. Then just turn the LED on and delay(100) or something before turning it off. Once you get that working, well… take that bridge when you come to it.