MOD EDIT
Fixed code tags and improved sketch formatting
const int buttonPin = 4;
const int rlyPin = 2;
int buttonState = 0;
int rlyState = 1;
unsigned long previousMillis = 0;
;
const long interval = 1000;
unsigned long currentMillis = 0;
void setup()
{
pinMode(rlyPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(rlyPin, LOW);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
rlyState = LOW;
currentMillis = millis();
}
else
{
rlyState = HIGH;
}
}
digitalWrite(rlyPin, rlyState);
}