Quick question. I'm working with a MAX4466 mic/amp, trying to set up some audio reactive LEDs. The mic (powered by 3.3V) works fine up to a certain voltage -- 1.12, roughly. Once the mic/amp reaches this threshold, the serial monitor (displaying volts) shows something like this:
1.11
0.05
1.14
1.11
0.07
1.12
The actual voltage should be 0.05 or 0.07, but for some reason it reads in a 1.12 or so.
Even more weirdly, when I close the serial monitor and re-open it, the input goes back to normal -- until it reaches 1.12 V again.
Any suggestions would be much, much appreciated. Oh, another problem is that the mic output seems to peak at 2.19V, not the expected 3.3 V.
Thanks!
P.S. The code I'm using is below:
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
Code: Select all
void setup()
{
Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}
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(3);
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 * 3.3) / 1024; // convert to volts
Serial.println(volts);
if (volts > 0.5){
digitalWrite(10, HIGH);
}
if (volts > 1){
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
}
if (volts > 1.5){
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
}
if (volts < 0.5) {
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
if (volts < 1) {
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
if (volts < 1.5) {
digitalWrite(10, LOW);
}
}