Go Down

Topic: Problem at audio output pin with electret microphone  (Read 1 time) previous topic - next topic

ecestudent17

Mar 16, 2017, 08:34 pm Last Edit: Mar 17, 2017, 01:56 am by Coding Badly
So currently I am attempting to pick up audio signals in an arduino via the analog input pins and an electret microphone circuit.

The device I am using for audio capturing is the spark-fun sound detector [https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide]

I have ordered pins to sodder onto this board, but at the moment, I have it wired up as shown in the attached picture (which may be the issue?)

The problem is, the audio output from the sound-detector board gives me a constant value on the arduino, whether there is sound coming into the microphone or not. The only time the value changes is when I unplug the sound-detector board from the power source, at which point I get values of 0.

The envelope detector output, however, works correctly. In a quiet environment, I get very low voltage values, and when speaking into the microphone, I get varying voltage values depending on how loudly I am speaking into the microphone.

However, for my application, I need raw audio-data and not the audio signal envelope.

Does anyone know what the issue could be, the code is very simply and shown below.

Code: [Select]
float i;

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

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
  delay(2);
}


Moderator edit: [code] [/code] tags added.

el_supremo

Those pins aren't making contact with the module. You have to solder them.

Pete
Don't send me technical questions via Private Message.

ecestudent17

Those pins aren't making contact with the module. You have to solder them.

Pete
Alright. I have some ordered and they are on the way, do you think that is the only issue Pete?

pert

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

When you attach an image it's helpful to embed the image so it's easy for everyone to see it at a glance. Instructions for doing this are found at:
http://forum.arduino.cc/index.php?topic=364156.0

el_supremo

Quote
do you think that is the only issue Pete?
Your code is so simple that I'm sure that if you wire the hardware properly, you'll get a more reasonable result.

Pete
Don't send me technical questions via Private Message.

Grumpy_Mike

Quote
wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:
Their is no need to do this at all.

DVDdoug

Quote
However, for my application, I need raw audio-data and not the audio signal envelope.
You also can't delay 2 milliseconds if you're going to read the audio waveform.    i.e.  CD audio is sampled at 44,100 times per second.  The Arduino can't sample quite that fast but with a 2mS delay you're sampling at about 500Hz.    But of course, you can't really "print out" the data at fast sample rates either.

ecestudent17

#7
Mar 17, 2017, 10:27 pm Last Edit: Mar 17, 2017, 10:50 pm by ecestudent17
You also can't delay 2 milliseconds if you're going to read the audio waveform.    i.e.  CD audio is sampled at 44,100 times per second.  The Arduino can't sample quite that fast but with a 2mS delay you're sampling at about 500Hz.    But of course, you can't really "print out" the data at fast sample rates either.
I am attempting to sample around 8kHz for my application. Below is some code I used to determine the sampling-rate with the basic analogread function.

Code: [Select]

// Arrays to save our results in
unsigned long start_times[100];
unsigned long stop_times[100];
float values[100];

// Setup the serial port and pin 2
void setup() {
  Serial.begin(9600);
}


void loop() { 
  unsigned int i;

  // capture the values to memory
  for(i=0;i<100;i++) {
    start_times[i] = micros();
    Serial.values[i]=analogRead(A0);
    stop_times[i] = micros();
  }

  // print out the results
  Serial.println("\n\n--- Results ---");
  for(i=0;i<100;i++) {
    Serial.print(values[i]);
    Serial.print(" elapse = ");
    Serial.print(stop_times[i] - start_times[i]);
    Serial.print(" us\n");
  }
  delay(6000);
}


The time I get, on average, is about 116 uS, resulting in around 8.6 kHz, which should be fine for my application. I realize in my initial code I was doing a

Code: [Select]

Serial.print(analogread(xyz))


 command, which will greatly slow down the sampling rate. However, I plan on simply storing the values read at the analog input in an array, then continuing on from there with some feature extraction. I only need very small samples so the board memory size is not an issue. It was my mistake to post the Serial.print command in the original code.

Even now, I am still getting the same constant values at the analog input, around 1.2-1.5 volts, from the microphone audio output. These values do not change depending on whether it is completely quiet near the microphone, or very loud. I do not think this is a sampling rate issue, but maybe I am misunderstanding something? If I can get past this audio-output from the sound-detector board issue, I can move on with the rest of the project.

ecestudent17



Well, here is a quick Matlab plot I made of the audio signal (I simply took 1000 sampled values and plotted them against a time vector)

This is actually looking pretty decent, maybe the non-soldered wires are a big issue

If i'm missing anything else that might be effecting this i'm sure someone here will catch it.

el_supremo

#9
Mar 18, 2017, 12:06 am Last Edit: Mar 18, 2017, 12:06 am by el_supremo
Quote
maybe the non-soldered wires are a big issue
There's no "maybe" about it.

Pete
Don't send me technical questions via Private Message.

Go Up