Serial monitor printing only the number 3

Can anyone help me solve this i am using a tilt sensor

int soundSensor =3;
int LED =2;
void setup() 
{
  Serial.begin(2000000);
  pinMode (soundSensor, INPUT);
  pinMode (LED, OUTPUT);
  
}

void loop()

{
  Serial.println(soundSensor);
  int statusSensor = digitalRead (soundSensor);
  delay(1000);
  if (statusSensor == 5)
  {
    digitalWrite(LED, HIGH);
  }
  
  else
  {
    digitalWrite(LED, LOW);
  }
  
}

Don't confuse the pin number with the value returned when reading the pin.

the value does not change even if i tilt the sensor

Serial.println(soundSensor);
:open_mouth:


Serial.println(digitalRead(soundSensor));
:slightly_smiling_face:

Depending on how you wire your sensor:

pinMode (soundSensor, INPUT);
verses
pinMode (soundSensor, INPUT_PULLUP);

it works thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.