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);
}
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 ?
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).
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.
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.