#include <Arduino.h>
// Define pins
const int LED_PIN = 26; // LED connected to pin 26
const int BUTTON_PIN = 27; // Button connected to pin 27
// Variable to store the LED state
bool ledState = false;
void setup() {
// Set LED pin as output
pinMode(LED_PIN, OUTPUT);
// Set button pin as input with internal pull-up resistor
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initialize serial communication
Serial.begin(115200);
Serial.println("Basic LED Switch Project Started!");
}
void loop() {
// Read button state
// Because we use INPUT_PULLUP, button press gives LOW
if (digitalRead(BUTTON_PIN) == LOW) {
// Toggle LED state
ledState = !ledState;
// Update LED
digitalWrite(LED_PIN, ledState);
// Print status to serial monitor
Serial.print("LED is now: ");
Serial.println(ledState ? "ON" : "OFF");
// Small delay to avoid multiple triggers
delay(200);
}
}