const int buttonPin = 2;
const int ledPin = 3;
void setup() {
pinMode(buttonPin, INPUT); // Button input (uses external 10kΩ pull-down)
pinMode(ledPin, OUTPUT); // LED output
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // LED ON when button is pressed
} else {
digitalWrite(ledPin, LOW); // LED OFF when button is not pressed
}
}