However, when I try to read the sensor, it provides really small numbers and does not variate depending on the sound levels. It just stays in a certain range and sometimes jumps to 1023 or 0.
Exactly how do you have it connected, and exactly what code are you using to look at it? The analogRead() function only runs at about 10000 samples/second, which makes it "just barely" able to process audio (somewhat worse than a telephone), and it would be easy to have code that did enough "not quite right" to get essentially random results when trying to sample audio...
I have the electret microphone hooked up straight into the Arduino. So the Analog Output is connected to Analog Pin 0, the Ground Pin is connected to ground and the VCC pin is connected to 5 Volts.
The code I used is this:
void setup()
{
Serial.begin(9600);
}
int average()
{
int x = 0;
int y = 0;
for (int i = 0; i <= 10; i++)
{
x = analogRead(0);
y += x;
}
Serial.println(y);
delay(500);
}
void loop()
{
average();
}
Also, if there is something extra I need to buy, please let me know so I can purchase it as soon as possible. But I think that we should be able to get it working without spending any extra money. As in all I need to do is distinguish between a gun shot in which the gun is going to be right next to the sensor, and just regular commotion. So basically I need to control a threshold value.
How do I change the analog reference to 1.1 volts?
The opamp in that sound module is biasing the output at 1/2 of the vcc used to power the board. So if you use the standard +5vdc power pin to power this module (and ground to ground) you should get a steady analog reading value of around 512 counts with no audio signal present.
Any audio (AC voltage) received and amplified will just randomly add or subtract from that 'center' value. unless you are into writing fast fourier transform routines I think there is little useful information you will be able to do anything with. Best to think clap on, clap off sensor and with some coding I think that is the best you can do with that module.
So is it possible for me to distinguish a gun shot from just regular talking voice? The module will be right next to the gun and if the shooter talks, it should not pass a threshold?
What is the best way to connect the module and code the Arduino to do this project?
So is it possible for me to distinguish a gun shot from just regular talking voice? The module will be right next to the gun and if the shooter talks, it should not pass a threshold?
With proper software design I would think it would be possible to be able to distinguish a gun shoot from nearby ambient noise like talking. Might require a lot of bullets in the testing of the code.
What is the best way to connect the module
The module wires up with just three wires, ground, +5vdc, and signal output wired to a Arduino analog input pin.
and code the Arduino to do this project?
That's what you will be able to do once you learn arduino C/C++ programming skills.
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.
I even averaged it after 10 inputs. What should I do?
Sorry if you felt that way. I did not mean in any way to give that notion but it is just because I purchased 10 of these and wanted to make sure I get it right this time.
It is worth adding that capacitor/diode? Will it solve my problem? I was watching a couple of videos of people using a electret microphone and none of them had bought the Sparkfun board, rather they found success in building their own circuit. Should I do this?
I am up for all opinions whether I have to purchase something or not.
I connect the diode between the Sparkfun AUD pin to the Arduino Analog Pin.
Between the diode and the Arduino Analog Pin, I connect the resistor from the Arduino Analog Pin to ground and the capacitor from the Arduino Analog Pin to ground.
This is what I understood from the Wiring circuit...
Thanks for all your help so far! I need to go purchase the parts used in the circuit from RadioShack so I will give you a response back tomorrow on the progress.
Wait where can I find the diode 1N1002? I tried to look in RadioShack but could not find it. Not even Sparkfun has it.
My bet would be that it is a misprint, yes it happens, (xkcd: Duty Calls).
Just about any silicon diode would work in that application, and I would guess they meant to draw it as a 1N4002, although any of the 1N40xx series would work, -01 to -07
I put all of the extra components on the board, yet it make no difference. It still shows values from 400 - 600 continuously and when I clap, it makes no spike but when I hit the mic, it jumps to a really high number or goes down to 85 or 0.
I put the 1N4001 Diode, 2.2k Ohms Resistor, and 10 microFarat Electrolytic Capacitor. I connected the diode between the AUD Pin and Analog Pin 0 of the Arduino, the Resistor from the Analog Pin 0 to Ground, and the Capcitor from Analog Pin 0 to Ground.
It seems that it made no change? Any suggestions? Should I just build my own microphone circuit? I found people had a lot of success in doing so.
int average()
{
int x = 0;
int y = 0;
for (int i = 0; i <= 10; i++)
{
x = analogRead(0);
y += x;
}
Serial.println(y);
delay(500);
}
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.