const int LED_PIN = 5; // Replace with your chosen LED pin
const int BUTTON_PIN = 2; // Replace with your chosen button pin
int buttonState = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Internal pull-up resistor for button
digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
Serial.begin(115200); // Optional: For serial communication
}
void loop() {
buttonState = digitalRead(BUTTON_PIN);
if (buttonState == HIGH) {
digitalWrite(LED_PIN, HIGH); // Turn on LED
} else {
digitalWrite(LED_PIN, LOW); // Turn off LED
}
}