Serial monitor says 0 constantly when using arduino and sound sensor

I am having problems with arduino sound sensor and LEDs. I keep getting the value 0 in my serial monitor, the same happens with the other sound sensor I have. I am currently trying to light the LEDs based on sound, but with monitor sequential view of 0 it does not activate the code. Photo must be attached. The indicator on the sound sensor is on, so I know GND and 5V are working. As it is difficult to say that I am using 330 ohm resistors. I got the sound sensor from an empty elegoo kit so I know it might be cheap. The image is at the end of the link. Thank.

     int MicPin = A0;
     int MicValue1 = 0;
     int MicValue2 = 0;

     int led1 = 2;
     int led2 = 4;
     int led3 = 6;
     int led4 = 8;

     void setup() {
     pinMode(led1, OUTPUT);
     pinMode(led2, OUTPUT);
     pinMode(led3, OUTPUT);
     pinMode(led4, OUTPUT);
     pinMode(MicPin, OUTPUT);
     Serial.begin(9600);
      }

     void loop() {
     MicValue1 = analogRead(MicPin);
     Serial.println(MicValue1);
     delay(1);
     MicValue2 = analogRead(MicPin);
     Serial.println(MicValue2);

     if (MicValue1 - MicValue2 > 1) {
     digitalWrite(led1, HIGH);
     delay(2000);
     }
     else {
     digitalWrite(led1, LOW);
     }
    } 

      

enter image description here

+3


source to share


1 answer


I am assuming you have a simple analog output module that provides 10 bit analog values ​​based on the volume of the environment. If this assumption is correct, you connected all the pins correctly and the resulting value is always out of range or maximum, you may have had to integrate a resistor to get the actual value. Try a small resistor and increase the resistance until you get the appropriate values. Perhaps your module's documentation has more information.

There is a small rotary knob connected to the sensor that we need to rotate to adjust certain resistance values, you can see different values ​​in the serial monitor output.



Useful link

+1


source







All Articles