Hi, I am trying to get value readings from a Velleman microphone sensor using an Arduino Uno. From what I understand is that by using analogRead, I will get the peak value from the sensor. I have played a single tone to the sensor and connected it to an oscilloscope. I got perfect sine wave but why am I getting random values from the serial monitor? :smiley-confuse:
From what I understand is that by using analogRead, I will get the peak value from the sensor.
What leads you to believe that? Can you provide a link to where you saw that?
The analog output does not give the peak amplitude, just the instantaneous amplitude. To get a peak amplitude take many samples and look for the peak with software. You get ransom looking data because you are sampling the wave at different points on the wave. If you sample at exactly the frequency of the wave you will get a steady reading, but the reading could be any point on the wave. See aliasing. (https://en.wikipedia.org/wiki/Aliasing)
The digital signal changes state based on a threshold that you set with the pot (not peak either).
Hi, thank you for your reply. Do you know how can I get a constant value then?
What do you mean by constsnt value, peak?
Yes. Is there a way?
Google "arduino input peak detector" for information on how to do it in software and hardware.
Hi. You will be sampling the incoming signal so you have to determine the sampling rate you will be using. For AnalogRead, the sampling rate is defaulted to approximately 10 ksps. Theoretically you can sample up to 5 kHz signals with that. For the peak detector, you'll need to write that in software yourself, and if your algorithm takes too long, you won't be able to sample at the maximum rate. Also, you should make sure the microphone output comes from an opamp. If its a direct output from a mic, then you will need to interface it to an opamp, set the gain, and add a low pass filter to cut off anything above 5kHz. That is called signal conditioning and is needed to provide a strong, quality signal to the ADC in the frequency band of interest.
Hope that helps.