const int buttonPin = 2; // Pin number where the button is connected
const int ledPin = 13; // Pin number where the LED is connected
void setup() {
pinMode(buttonPin, INPUT); // Set the button pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the state of the button (HIGH when pressed, LOW when not pressed)
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // If the button is pressed, turn on the LED
} else {
digitalWrite(ledPin, LOW); // If the button is not pressed, turn off the LED
}
}