Hi, some advice would be greatly appreciated to understand what is wrong here...
I would like to measure distance between two points using sound.
Ultrasonic transducers can be used for this goal, but they must face the point to measure.
I would like to use "normal" speaker and microphone, so the sound is not so directional, and to some point, I can measure the distance between microphone and speaker even if they do not face each other.
I am using Teensy 3.6,
microphone is this https://www.amazon.it/gp/product/B07PXP8BQ7/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1,
speaker is connected to pin 8 through 100ohm resistor.
Photo of the setup, where speaker and microphone is about 10cm.
Code
For each loop, I start tone, wait 50 microseconds, then start reading the ADC, until i get signal above a threasold that I have measured is slightly under the peak measured during the tone.
The problem is that I get approx 50045us as a reading (50000us are the 50ms that I wait for the tone to "stabiliyze"), so just 45us? It should be approx 300us for 100mm.
I tried with different frequencies for the tone from 200 to 14000, the better result I get is that if I move mic and speaker closer (about 1cm) the reading is about 15us.
But something is wrong, I think.
Thanks!
I would like to measure distance between two points using sound.
Ultrasonic transducers can be used for this goal, but they must face the point to measure.
I would like to use "normal" speaker and microphone, so the sound is not so directional, and to some point, I can measure the distance between microphone and speaker even if they do not face each other.
I am using Teensy 3.6,
microphone is this https://www.amazon.it/gp/product/B07PXP8BQ7/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1,
speaker is connected to pin 8 through 100ohm resistor.
Photo of the setup, where speaker and microphone is about 10cm.
Code
Code:
// Speed of sound 0.34029 millimeters / microsecond
// 10cm = 100mm = approx 300us ??
#include <ADC.h>
ADC *adc = new ADC();; // adc object
volatile int elapsed;
int readPin = A21; // ADC0
int value = 0;
void setup() {
pinMode(readPin, INPUT);
Serial.begin(1000000);
adc->setAveraging(0); // set number of averages
adc->setResolution(12); // set bits of resolution
adc->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED); // , change the conversion speed
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED); // change the sampling speed
adc->startContinuous(readPin);
tone(8, 10000);
}
void loop() {
unsigned long startTime = micros ();
tone(8, 1000);
delay(50);
int uu=0;// (uint16_t)adc->analogReadContinuous(ADC_0);//=analogRead(A21);
//do { uu=(uint16_t)adc->analogReadContinuous(ADC_0); } while (uu<2000);
while (uu<2150)
{ if (adc->isComplete(ADC_0))
{ uu=(uint16_t)adc->analogReadContinuous(ADC_0); }
}
unsigned long endTime = micros ();
unsigned long elapsedTime = endTime - startTime;
Serial.println (elapsedTime);
noTone(8);
delay(50);
}
For each loop, I start tone, wait 50 microseconds, then start reading the ADC, until i get signal above a threasold that I have measured is slightly under the peak measured during the tone.
The problem is that I get approx 50045us as a reading (50000us are the 50ms that I wait for the tone to "stabiliyze"), so just 45us? It should be approx 300us for 100mm.
I tried with different frequencies for the tone from 200 to 14000, the better result I get is that if I move mic and speaker closer (about 1cm) the reading is about 15us.
But something is wrong, I think.
Thanks!