Arduino uno random analog values

My arduino uno clone analog pins read different values Even though I've used different analog pins.
power is from computer port, Vcc to arduino 5v, gnd to gnd and out to analog input.
I've tried 2 different micro phone all seems same and I'm using the online compiler.
The values are not different from when no sensor is connected in variation. I've used the sample code below.
Thanks

type or paste code here
int sensorValue;
float voltage;

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

void loop() {
  sensorValue = analogRead(A0);
  voltage= sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
}

Welcome to the forum

What sensor are you using ?

1 Like

micro phone sound sensor

Is there any hope of you providing more details as to exactly which sensor you are using and details of how it is connected to the Arduino ? What is the label on the spare pin on the sensor module ?

Where do the others wires connected to the Arduino go to ?

1 Like

You seem to have used the analogue output of this microphone board.

Sound is random waves, so why are you surprised when you get random analog values.

The module also has a digital output, with threshold pot, to detect (loud) events.
Leo..

1 Like

There are basically 3 kinds of microphone boards...

  • Some put-out a biased analog audio signal. (Biased because audio is AC and the Arduino can't read the negative-half of the waveform.)

  • Some put-out a varying DC voltage proportional to the "loudness".

  • Some put out a digital-high or digital-low depending on if the loudness is above or below a threshold set by the pot.

And, I've seen a board with all three outputs.

If you are reading a (biased) audio signal the readings will normally "look random". If you look at the values in a WAV file they will also "look random". You are "sampling" a constantly-changing "waveform". Every cycle has a positive peak, and negative peak, and it crosses-through zero twice per cycle. (That's ignoring the bias, or with the bias subtracted-out.) You don't know where along the wave you are reading and real-world audio is NOT a "nice" sine wave.

With silence you should read about 512 (2.5V) but there will always be some noise.

Depending on what you're doing you'll usually want to find the peaks or the average (or a moving average). But the true mathematical average will be zero (it's positive half the time and negative half the time) or it will be about 512 if biased. So, you need to find the average of the positive values or the average of the absolute values.

P.S.
You probably don't need to calculate voltage. You can probably use the raw ADC readings (0-1023 with the 10-bit ADC).

1 Like

thanks for the response, I've turned the pot in different directions all to no avail, it's actually having 3 pin outs. even tried another version it's same random output, at least there should be a difference when loud sound is detected but this just work as If sensor isn't present.

Link to sensor

1 Like

Thanks for the input, [Link to sensor ] I actually tried that raw reading too it's still same,, is there a format that I must use in the code to get the sound detected value.
Thanks (https://www.amazon.com/Electret-Microphone-Amplifier-Adjustable-Breakout/dp/B08N4FNFTR/ref=mp_s_a_1_2_sspa?keywords=Arduino+Microphone&qid=1645478317&sr=8-2-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExTEc3SlNZQ0lEWks3JmVuY3J5cHRlZElkPUEwMTA3MjU5M0w1SUM0S0paWUg2QiZlbmNyeXB0ZWRBZElkPUEwMzA2NzE1RUpWRlZIM0IzUUlPJndpZGdldE5hbWU9c3BfcGhvbmVfc2VhcmNoX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU=)

Yes. Over-time you should see a difference...

If you're reading the biased analog audio signal quiet sounds should read around 512 (2.5V).

With louder sounds you should see some bigger numbers (for the positive half of the waveform) and some smaller numbers (for the negative half of the waveform) but loud sounds still have a zero-crossing you'll still get some readings near 512.

I wrote a little program that finds the peaks and calculates a 20-second moving-average of the peaks. If the current peak is above average the built-in LED turns-on and it's off when the peak is below average.

The pot sets the sound threshold for the digital output.

You seem to have links for a different sensor than the one pictured in your first posts.
Leo..

1 Like

Thanks for this, it appreciated. I'll try out the code and send you an update. Thanks again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.