Skip to main content

Problem with simple sound detection circuit using microphone

I am very new to this community . My first project with Arduino was using a LDR( light dependent resistor) in a circuit like this:

enter image description here

The input i got was as expected between 0 - 1023.

I then tried a similar project this time using a sound sensor like this:

enter image description here

My circuit was as follows -

  1. A0 on mic to A0 on arduino
  2. GND to GND
  3. +ve to 5V
  4. led along with resistor to digital pin 9 on arduino

My program is as follows :

const int analogInPin = A0; 

int sensorValue = 0;            
void setup() {
  pinMode(analogInPin,INPUT);
  pinMode(9,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(analogInPin);
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\n");
  if(sensorValue > 900 )
  digitalWrite(9,HIGH);
  else
  digitalWrite(9,LOW);

}

The problem is the serial monitor gives a weird reading, randomly giving 1023 and 0 after regular intervals.

sensor = 124
sensor = 0
sensor = 1023
sensor = 39
sensor = 352
sensor = 1023
sensor = 142
sensor = 0
sensor = 1023
sensor = 44
sensor = 338
sensor = 1023
sensor = 163
sensor = 0
...
...

I can't figure out the problem myself so I came here.

95_96
  • 131
  • 1
  • 1
  • 3