i am very new to this comunity . My first project with arduino was using ldr( light dependent resistance ) in a circuit like this . The input i got was as expected between 0 - 1023.
I then tried a similar project this time using a sound sensor like this
my circuit was as follows -
- A0 on mic to A0 on arduino
- GND to GND
- +ve to 5V
- 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 cant figure out the problem myself so came here thanks.