I am learning Arduino and pardon me if this is nooby. I am trying to make an LED glow when the tilt switch is tilted. The LED should not glow if the tilt is in normal position. The circuit and the code are in the attached image.
Based on my understanding of the code, I thought that when the tilt switch pin 5 is passed with HIGH signal from 5V the IF condition gets satisfied and tje LED on pin 13 would glow.
But it does not happen. The LED just glows before I tilt the tilt switch. Could you please clarify/correct my mistake. Thank you.
Attaching the code below as per suggestion
int ledPin = 13;
int switchPin = 5;
void setup() {
pinMode(ledPin,OUTPUT);
pinMode(switchPin,INPUT);
}
void loop() {
Serial.begin(9600);
if (digitalRead(switchPin) == HIGH) {
digitalWrite(ledPin,HIGH);
Serial.print("we are here");
}
if (digitalRead(switchPin) == LOW) {
digitalWrite(ledPin,LOW);
Serial.print("there");
}
}

