Go Down

Topic: Elektret Micophone (Read 2461 times) previous topic - next topic

Ryukenden

Hey guys im having some difficulty reading values from an elektret micrpohone.

the code is use is simpel and shoudlnt be the problem;
Code: [Select]
/**
* AnalogReadSerial
* Reads an analog input pin 0 and prints the result to the serial monitor
* Click on the serial monitor button to open it.
*/

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int sensorValue = analogRead(5);
  Serial.println(sensorValue, DEC);
  delay(500);
}


i used a schematic exactly like this one:http://www.instructables.com/id/Pre-amp-to-electret-mic/
However, i only get 0 as a value, and whenever i make a sound it doesnt go up or down.

I have plugged it onto 5 volts from the arduino itself.
Could it be that 100k resistor is the problem?

I am a total newbie so i just copied what i saw.

tmd3

Are you using the output coupling capacitor, called "C2" in the instructables schematic?  That capacitor is intended to block the DC component of the output signal.  The ADC needs to see that DC component, because it can't read voltages below zero.

Here's my suggestion for what to try next:

  • Power the circuit from the Arduino's 5V supply.  Be sure to connect the circuit ground to the Arduino ground.

  • remove C2 and connect the output of the transistor, "Q1," to the analog input.

  • Try it again.


Ryukenden

Thanks you for the tip, i will try it out later today.
I will keep you posted on the results.

Ryukenden

i have removed the Capacitor as advised, but now i get big random readings.
they vary between 5 and 4685.

also i can not surely say that any noise has influence on the numbers i see.

luisilva

I think that your delay is very long too.
I think too, that you may need to add some DC signal to read something with the ADC of Arduino.

Ryukenden

Ive removed the Capacitor, and i shortend the delay to 50.
it is now wrinting values around 29-36 in the serial vieuw.

however if i tap the mic, it drops down to 14-18, and after that it stays in that.
if i tap it a second time it goes to 0-3 and stays on that.
It looks like it keeps droping without resetting to some sort of base line?

DVDdoug

Quote
have removed the Capacitor as advised, but now i get big random readings.
they vary between 5 and 4685.

also i can not surely say that any noise has influence on the numbers i see.
Hmmmm...  The ADC is only 10-bits so it only goes from 0-1023.

The readings should be "random", but you should get SOME bigger numbers with louder sounds.   

You are reading the voltage of a constantly-changing waveform...  It's like trying to read the height of a wave in the water by taking a fast reading...   You might be reading when the wave is high or when the wave is low and you don't know...  You need to take a bunch of readings and ignore everything except the peaks.   

And yes.  500ms is way too slow.   You can easily miss the peaks.

With the capacitor in the circuit, half your readings will be negative, but the Arduino can't read negative voltages and it will read zero (or near zero).  So about half of your readings will be zero.   (You are not supposed to put negative voltages into the Arduino.)

Without the capacitor, your waveform will be biased at some value (hopefully around half the ADC range, or around 512).    Silence should read around the bias-value.  Louder sounds will give bigger and smaller "random" readings.

tmd3

#7
Jul 06, 2014, 08:45 pm Last Edit: Jul 06, 2014, 10:09 pm by tmd3 Reason: 1
You don't describe your level of experience with the Arduino, or with electronic circuits in general.  I'm going to make a guess about both of those, based on your earlier posts.  Please pardon me if I describe things that seem elementary to you.

For the convenience of others reading this thread, I'm attaching the schematic from the referenced "instructables" posting.

I'd recommend checking the amplifier's DC conditions.  First, I'll repeat two earlier recommendations:

  • Power the circuit from the Arduino's 5V.  The purpose of that is to make sure that the amplifier's output voltage doesn't exceed 5V.  If the amplifier output voltage gets above the level of the Arduino's power supply, it could damage your Arduino.

  • Make sure that the ground of the amplifier circuit is connected to the Arduino's ground.  If the circuit's current doesn't have a way to return to the Arduino's power supply, it won't operate.


Here's how to check the DC output level:

  • Remove the electret from the circuit.  The purpose of that is to make sure that voltage readings won't be affected by sounds in the room, so that we can read the DC voltages in peace.

  • Measure the voltage at the collector of Q1.  That will be the junction between the transistor and the 10K resistor R3.  By my calculations, that should be between about 0.8 volts and 1.3 volts, depending on the actual DC current gain of your particular transistor.

  • If you don't have a voltmeter, then connect the collector of Q1 to analog input A5, and run your program.  Again, by my calculations, you should see analog readings between about 125 and 170, depending on the actual transistor characteristics.


I haven't built the circuit; my calculations could be wrong.  

If you don't get those values, something's likely to be askew.  In that case, I'd recommend disconnecting the amplifier circuit completely, and testing the analog input with the Arduino's onboard 3.3V source.  Connect the 3.3V pin to analog input A5, and run your program.  That should give readings of about 675.  If that test fails, something's certainly askew.

As DVDdoug aptly says, the value 4685 is bigger than any value that the ADC can register.  I don't see any way that your program could show that reading, so I'll presume that it's a typing error.

[Edit: spelling]

DVDdoug

I know we are overloading you with information, but a few more things -

Maybe you should try this SparkFun Electret Breakout Board.  It's got the amplifier and bias circuit built-in.   Building an amplifier with a transistor isn't easy, especially if you don't have a multimeter or oscilloscope to test & troubleshoot it.  I've always used op-amps (or other integrated circuits).     I don't  remember EVER building an analog amplifier with transistors, except maybe in school.   And, I've got an electronics degree and many years of experience.


With the capacitor in your existing circuit the DC voltage on the Arduino input is "floating" and unknown.   The AC audio waveform will ride on top of the floating DC.   With the capacitor in your circuit, put a resistor between the Arduino's analog input and ground.   (10k - 100k is fine.)

The comments in your sketch say you are connected to input A0 but you are actually reading A5.    Make sure you are reading the pin you're physically connected to.

I'm not sure if this will correct the problem of erroneous values greater than 1023, but try defining your variable before setup().
Code: [Select]

int sensorValue = 0;


Try taking the delay out completely.

If all else fails, start with the AnalogReadSerial Example complete with the pot.   When that works, replace the pot with the microphone-amplifier circuit.

Then if you wish to modify the sketch, change one or two lines of code at a time, making sure it works after every change.

Ryukenden

#9
Jul 06, 2014, 10:27 pm Last Edit: Jul 06, 2014, 10:34 pm by Ryukenden Reason: 1
Thanks alot for all the support and information i appreciate it alot.

As a quick update the test Tmd3 wrote:

Quote
f you don't get those values, something's likely to be askew.  In that case, I'd recommend disconnecting the amplifier circuit completely, and testing the analog input with the Arduino's onboard 3.3V source.  Connect the 3.3V pin to analog input A5, and run your program.  That should give readings of about 675.  If that test fails, something's certainly askew


it Does read a value around 675, so atleast the problem is not in the arduino itself sofar.
ill test the rest too and keep u posted

Side note, without yet removing the elekret i could still meassure the Q1 but it reads again between 0-940

Ryukenden

Hey guys,

ive made a new breadboard setup following this:

http://tinkerlog.com/2007/05/20/cheap-sound-sensor-for-avr/

its basically the same setup only on a breadboard format.


To much joy i get a steady reading from this setup wich floats around 760-768.
When i blow on the mic it goes up to 883-930.
It has some small dips that go randomly between 0-760 after it has just peeked to 930.
I guess this has something do to with the waveform?

its connected to the Adruino itself on the 5volt.
Also as adviced by DVDdoug i  added a 10k resistor between the transistor and the analog imput pin.

I am guessing the 760 value is a baseline reading from ambient noise in my room?
also, that value could be lowered in theory? but it is not really necessary.

The main objective i want to use this for is that the arduino detects sound and reacts.
The Elektret micophone is not really ultra sensetive in this setup, but hey it works.


i want to thank u all for your time and effort to help me understand whats going on :)
you have my utmost appreciation!




Go Up