Hey, I bought a adafruit max9814 mic, but I can't readout the data I get from it. I wired the mic like it is shown in picture below, but when I upload my code I always get the same data of around 500 in the serial monitor. Can you guys help me?
The sketch does exactly what you have told it to do, take a single snapshot five times a second.
To measure the forever changing voltage of sound your must measure continuously (thousands of times a second), and store/update min and max values.
Adafruit has a link to example code on the main page of this sensor.
Leo..
Thank you! I got it working now, but still there is the problem, that the differences between the values I get from the mic are all about 0.03V. I added a LED that should glow when there is a sound, but I really have to scream into the mic to see the value changing.
I just modified your code a little bit:
[/****************************************
Example Sound Level Sketch for the
Adafruit Microphone Amplifier
****************************************/
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void loop()
{
digitalWrite (3, 0);
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 1024; // convert to volts
digitalWrite (3, 0); // module power pin ? gain pin ? No pinMode ?
You should have posted according to the forum guidelines.
Code with code tags, and a picture of the setup.
Sensitivity of the Arduino (assuming Uno) can be increased by setting Aref to EXTERNAL, and connecting the Aref pin to the 3.3volt pin. Do BOTH, otherwise you could fry the Aref circuitry of the MCU.
I forgot to delete the "digitalWrite (3,0)". Here is the wiring plan and the code, but if I enter " analogReference(EXTERNAL); // connect Aref to 3.3volt" i just get a lot of zeros in the serial monitor... Thanks for your help!
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode (7, OUTPUT);
digitalWrite (7,0);
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 1024; // convert to volts
if (volts > 0.03)
{
digitalWrite (7,1);
}
else
{
digitalWrite (7,0);
}
Serial.println(volts);
}
Sketch seems ok.
Your "wiring plan" shows the output connected to A5, but your code uses A0.
Ethernet shield? Which Arduino are you actually using, and does it have that shield?.
Fritzing toddler art never seems to represent what's actually used, also the LED is connected in reverse.
Post a 'REAL' picture of the setup.
Leo..