const int buttonPin = 2; // Pin connected to the push button
int buttonState = 0; // Variable to store the button's state
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with internal pull-up resistor
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button's state
// Check if the button is pressed (LOW)
if (buttonState == LOW) {
Serial.println("Button Pressed");
delay(500); // Add a small delay to debounce the button
} else {
Serial.println("Button Released");
delay(500); // Add a small delay to debounce the button
}
}