const int buttonPin = 2; // the pin number of the button
const int relayPin = 3; // the pin number of the relay
unsigned long lastPressTime = 0; // variable to store the last time the button was pressed
const unsigned long debounceDelay = 50; // debounce time to prevent button bouncing
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // set the button pin as input with internal pull-up resistor
pinMode(relayPin, OUTPUT); // set the relay pin as output
}
void loop() {
// Read the state of the button
int buttonState = digitalRead(buttonPin);
// Check if the button is pressed and debounce it
if (buttonState == LOW && (millis() - lastPressTime) > debounceDelay) {
lastPressTime = millis(); // update the last press time
// Turn on the relay for 2 seconds
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);
// Disable button for 60 seconds
delay(10000);
}
}