SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By keithg
#82237
I want to read values from an LM386. The circuit is from "Physical Computing" p.357. I have made this a number of times with the same results; inconsistent figures, mostly 1~20. I assume the problem lies with the sketch. ADC is something of puzzle, even though I have read a number of descriptions. Would you please advise an alternative to: Code:
Code: Select all
void setup() {
   Serial.begin(9600);
}

void loop() {
  
  int soundLevel =  analogRead(0) ;
  
  Serial.print( "soundIn = ");
  Serial.println(soundLevel, DEC);
 delay (1000);
}

By mpeg2
#82251
It might be helpful if you described the circuit. You're trying to read from what I assume is an AC signal - without some form of filtering, you are taking instantaneous readings of a time varying signal - so the value read will depend upon where you hit the waveform

You may want to put some type of filter between the output of the 386 & the pin...

Rich
By mpeg2
#82275
That circuit has the necessary bits - rectification (gets rid of the negatative voltages) and a low pass filter (smooths out the signal a bit).

From your sketch, it appears that you're sampling the audio every second or so - what's the audio source? Audio bounces around over time - taking a sample every second would be expected to yield varying values (look at the graphs in the article you pointed to).

What are you trying to measure? What do you expect to see?

Rich
By keithg
#82303
I am designing a noise monitors for our school cafeteria that will use led's to indicate level of sound over each pod of tables. I was hoping to harvest values from the LM386, average them over time, and program a response. Sound it seem presents unexpected problems for the inexperienced. Thanks for your help.
User avatar
By leon_heller
#82304
I'd use an op amp instead of the LM386.

Leon
By lyndon
#82345
I'd study the methods used by commercial sound pressure level meters. It's not as simple as just sample and average. The human ear responds differently to different frequencies and that has to be taken into account if you want any level of accuracy.
leon_heller wrote:I'd use an op amp instead of the LM386.

Leon