const int limitPin = 2; // Pin connected to the limit switch const int ledPin = 13; // Onboard LED void setup() { Serial.begin(9600); pinMode(limitPin, INPUT_PULLUP); } void loop() { // Read the state of the switch int switchState = digitalRead(limitPin); // If switch is pressed (LOW due to INPUT_PULLUP) if (switchState == LOW) { digitalWrite(ledPin, HIGH); // Turn LED on Serial.println("Limit Switch Triggered!"); } delay(100); }