// Define the pins #define BUTTON_PIN 5 #define LED_PIN 6 // Variable to store button state int buttonState = 0; void setup() { // Set button pin as INPUT (reads signal from button) pinMode(BUTTON_PIN, INPUT); // Set LED pin as OUTPUT (controls the LED) pinMode(LED_PIN, OUTPUT); // Initialize the LED as OFF digitalWrite(LED_PIN, LOW); Serial.begin(115200); Serial.println("Button-Controlled LED Started!"); } void loop() { // Read the button state (HIGH when pressed, LOW when not pressed) // Note: This assumes a pull-down resistor setup buttonState = digitalRead(BUTTON_PIN); // Check if button is pressed if (buttonState == HIGH) { // Button is pressed - turn LED ON digitalWrite(LED_PIN, HIGH); Serial.println("Button pressed - LED ON"); } else { // Button is not pressed - turn LED OFF digitalWrite(LED_PIN, LOW); Serial.println("Button released - LED OFF"); } // Small delay to avoid reading the button too rapidly delay(50); }