comparing time difference between two microphones

Hi all,

So all i am trying to do is loclaise a sound source. I have tow (Sound inpu module) from freetronics, i am using the SPL input,

So far, the code i wrote compares which microphone has a higher SPL and gives me a direction, but i can make this more precise if i can cimpute the time difference betwen microphone one and two

float splSensor = A0; // the SPL output is connected to analog pin 0
float splSensor1 = A1;
void setup() {
Serial.begin(57600);
}

void loop() {

if (analogRead(splSensor1) > analogRead(splSensor))
Serial.println("L");

if (analogRead(splSensor) > analogRead(splSensor1))
Serial.println("R");

if (analogRead(splSensor1) == analogRead(splSensor))
Serial.println("C");

delay(200); // delay to avoid overloading the serial port buffer
}

You haven't included a link to details of that device.

It is difficult to do what you want with the Arduino alone, because it has only one ADC.

First, you have to decide what constitutes the signal of interest (a given sound pressure level or waveform peak, etc.). Then you measure the input on two channels, marking the time on each channel where that signal is observed. Since the signals on the two channels won't be identical, that is not completely straightforward.

It takes a significant amount of time for the Arduino to switch channels and make each individual measurement, which introduces additional uncertainty. Printing while making measurements makes this even worse.

float splSensor = A0;   // the SPL output is connected to analog pin 0
float splSensor1 = A1;

Are you sure that you don't want to be using pin number 3.14159 for one of the sensors?

pin number 3.14159 for one of the sensors

That would be for measuring sine waves.

The other problem of course, is that each analog read takes about the time it takes your sound to travel about 3.5cm.

Thanks Guys

all good points you raise,

The link to the Microphone is here

So i can specy a certain cound level to look for and then compare the time difference. i am happy it will not be super accurate however, all i want to do is allocate a time stamp for when hte first one received a signal, then the other and compare the two, is this difficult?

Yes, it's incredibly difficult, unless you restrict the task to very simple requirements. For example, only detect a single loud impulse (bang, snap, crack, etc.). Condition the signal with some kind of analog filter and peak detector prior to the Arduino input. For anything better you would need a DSP. I think you will be disappointed with the results of anything basic that you can do.

There is a long list of technical difficulties involved. Unless you are a human being, a rabbit or a porpoise.

You'll have much better results using an external ADC that take sample in 5-10uS vs 110uS.
For example, this one:

Using D10 as the chip select, SPI divisor set to 2 for 8 MHz clock speed:

PORTB = PORTB & 0b11111011; // cs low  - 2 clocks
upperByte = SPI.transfer(0);                     - 17 clocks
lowerByte = SPI.transfer(0);                      - 17 clocks
PORT = PORTB | 00000100; // cs high        - 2 clocks
result = (upperByte << 8) + lowerByte;     - 10 clocks?

Total, 48 clocks @ 62.5nS/clock = 3uS

A faster ADC will not help you if you want to localize something like a cat meowing. Not with the processing power of an Arduino. Because the signal has to processed, even if in a very rudimentary way.