I am conducting a science experiment to calculate the speed of sound through various solids. I wanted to use Arduino to help me with this.
So onto the reason I need help.
I want to put an 8 ohm speaker at one end of a meter long piece of pvc and and microphone at the other end. I need help getting the microphone to detect a sound spike. I want the serial monitor to print when the speaker sends the pulse (the time in milis) and to print the time when the microphone detects the spike.
The part I am using are:
The microphone:
The Speaker:
If some one could post some example code to help push me in the right direction that would greatly appreciated.
Might be simpler to put two mics, one at each end, and trigger the sound yourself by tapping the material. That halves the number of devices you need to interface to.
What materials will you be measuring the speed of sound through?
It might be an idea to cheat a little bit and lookup the speed of sound in those materials to make sure the system you build is capable of detecting the differences.
Also will your speaker have a delay beween you outputting a sound and the speaker actually producing it?
I don't see how using two mics is half the devices of a mic and a speaker.
Anyway... a speaker, as pointed out, isn't going to couple vibration very effectively into a solid. A piezo disk would work better, if pressed against a very smooth end.
An alternative method that should get any phase delay from electrical pulse to physical vibration out of the picture, and compensate for phase delay in the mics and preamps is to use two mics, one at each end, and as PeterH says tap it, or drive a solenoid to tap it. Then look at the difference in time of arrival of the pulse at each mic.
As for the microphones, you'll have the same issue with the speaker in reverse. An electret microphone won't do a good job of coupling vibration, because it has to pass through air and then into the mic. Why not use a couple of piezo disks as pickups? Press them firmly to the ends of the solid, preferably somewhere very flat and with some kind of gap filling grease.
Don't press the piezo elements in the middle, that'll dampen the sensitivity. - press in a ring around the outside. Use a bare piezo element.
polymorph:
I don't see how using two mics is half the devices of a mic and a speaker.
Once you know how to interface to a mic, doing it twice does not take any more effort. Interfacing to a speaker means learning how that hardware works, designing the external circuit and writing the software to interface to it - all additional work.