// When button connected to pin 4 is pressed, LED on pin 8 turns ON
const int buttonPin = 4;
const int ledPin = 8;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Start serial monitor
}
void loop() {
delay(50); // simple debounce delay
int state = digitalRead(buttonPin); // Read the state of the button
if (state == LOW) {
digitalWrite(ledPin, HIGH);
Serial.println("Button Pressed - LED ON"); // Set the LED to ON
} else {
digitalWrite(ledPin, LOW);
Serial.println("Button Released - LED OFF"); // Set the LED to OFF
}
}