const int buttonPin = 2; // Pin connected to the button
const int ledPin = 13; // Pin connected to the LED
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as an input
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // If button is pressed
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
}