// Button and LED GPIO pins
#define BUTTON_PIN 5 // GPIO for button
#define LED_PIN 2 // GPIO for LED
void setup() {
// Initialize the button pin as input with pull-up resistor
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initialize the LED pin as output
pinMode(LED_PIN, OUTPUT);
// Start serial monitor for debugging
Serial.begin(115200);
}
void loop() {
// Read the state of the button
int buttonState = digitalRead(BUTTON_PIN);
// Check if the button is pressed
if (buttonState == LOW) { // LOW indicates button is pressed
Serial.println("Button pressed!");
digitalWrite(LED_PIN, HIGH); // Turn on the LED
} else {
Serial.println("Button not pressed.");
digitalWrite(LED_PIN, LOW); // Turn off the LED
}
// Add a small delay to avoid bouncing issues
delay(50);
}