1
votes

Arduino sound sensor does not give accurate values

I've tried reading pin from D0 as well as reading from analog on A0. Pin constantly gives me 1 and A0 gives me almost exclusively the value 26 and can go up to 29 if I blow on the sensor really hard.

void setup() {
    pinMode(A0, INPUT); // changes nothing
}
void loop() {
    int soundVal;
    soundVal = analogRead(A0);
    Serial.print("Sound = ");
    Serial.println(soundVal, DEC);
    delay(500);
}

I expect to get a value between 0 and 1024 or something like that but I only get values between 25 and 29, making it extremely difficult reading if a sound is high or low as well as if a sound was detected

Edit: I've connected GRD on the sound sensor to GRD on my Arduino, A0 from the sound sensor to A0 on Arduino, the + pin on the sound sensor to 5V and left the D0 pin on the sound sensor untouched since I don't really need it I guess.

2

2 Answers

1
votes

Let's start with

I've tried reading pin from D0 as well as reading from analog on A0

Depending on the sensor and the thing you want to achieve you can you one over the other but it's important to know the basic difference. Digital pins have only 2 states (HIGH & LOW) which you can see as 1 and 0. Read more about the digital pins here

While an analog pin's value can indeed be between 0-1023. Read more about the analog pins here

Now when we clear this. Let's move to:

Pin constantly gives me 1 and A0 gives me almost exclusively the value 26 and can go up to 29 if I blow on the sensor really hard.

So clearly there is some voltage coming into your pins. I think one of two things are happening here.

  1. This transition from 26-29 is nothing but a standard value changing because of the precision of the board and some other environment factors. (Which may also be broken sensor or being connected wrong)

  2. I assume that you are using some sort of resistor in your circuit to make sure your sensor can handle the current. If that's the case I think you may be using a resistor with a much higher resistance than what is needed for the sensor.

When it comes to the code it's straightforward, you are doing it right. Attach a scheme or provide information about your circuit if you want more detailed help.

0
votes

It appears as if the sound sensor does work but really only cares about sound changes REALLY close to it, hence why the numbers does not really change. Solution: buy another sound sensor or adapt accordingly.