Are you still using this code?
int x = 0;
int y = 0;
for (int i = 0; i <= 10; i++)
x = analogRead(0);
y += x;
One of the problems you’ve had all along is averaging. Sound is by nature an AC signal, and the average of an AC signal is zero. So by averaging your code is able to suppress any audio except for a big THUMP.
Is your goal is to distinguish gun shots from voice? Gun shot should give a THUMP big enough to deviate the average while voice will generally not. Maybe you already have what you need!
Yea but right now it is not recognizing any noise. It just stays at a range between 300 - 500 and moves whether there is noise or not. When I tap it, it jumps to 1023 or it goes all the way down to 0.
Look for the value to JUMP on a gun shot. LESS averaging makes it MORE sensitive.
You can also use the envelope detector (diode and RC filter) to distinguish gunshot from voice. Use a small signal diode if you can, 1N914 or 1N4148 Radio Shack 276-1122. Use RC time constant of around 10 millisec. This gives you the “envelope” of audio rather than the instantaneous AC, so greatly relieves the Arduino processing load.
The software method is based on normal human speech having a syllable rate of between 0.2 Hz and 3.2 Hz. Google “syllabic squelch” or “syllable rate Hz squelch”, the word “squelch” suppresses hits for human speech disorders, you are interested only in audio processing. It is a very reliable discriminator for speech with few false positives even in a noisy environment. Your software would need to process data for a few seconds to make the distinction, I leave the code as an exercise for the reader.
Richard Crowley is right, even an experienced designer would not wish to attempt this without an oscilloscope. For example all the microphone audio your software is missing by averaging would be shown by an oscilloscope. Beg borrow or steal one if at all possible.
Good luck with your voyage of discovery !