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