const int buttonPin = 2; // Pin number where the push button is connected
int buttonState = 0; // Variable to store the button state (LOW or HIGH)
void setup() {
pinMode(buttonPin, INPUT); // Set the button pin as an input
Serial.begin(9600); // Initialize serial communication for debugging (optional)
pinMode(13,OUTPUT);
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the state of the button (LOW when not pressed, HIGH when pressed)
// Check if the button is pressed
if (buttonState == HIGH) {
Serial.println("Button is pressed!"); // Print a message to the serial monitor (optional)
digitalWrite(13, HIGH);
delay(5000);
// Add your code here to perform actions when the button is pressed
// For example, you can control other devices, change states, etc.
// delay(500); // Add a small delay to avoid bouncing issues (optional)
}
}