15 second delay

give this code a try. not sure whether it is the way you wanted. use NO pin on relay.

int x;
int y;
unsigned long lastMillis = 0;
unsigned long lastMillis1 = 0;

void loop()
{
  Cayenne.loop();
  y = digitalRead(DoorStateSensorPin);
  if ( y == 0) //door is open
  {
    digitalWrite(RELAY_CONTROL_PIN, x);//turn on relay
    delay(100); //this delay in your code is very small.
    x = 0;
    digitalWrite(RELAY_CONTROL_PIN, x);//turn off relay
    if (millis() - lastMillis > 10000) {
      lastMillis = millis();
      Cayenne.virtualWrite(DoorButton, LOW);//make dashboard button to low
    }
  }
  else //door is closed
  {
    if (millis() - lastMillis1 > 10000) {
      lastMillis1 = millis();
      Cayenne.virtualWrite(DoorButton, LOW);//make dashboard button to low
    }
  }

}
CAYENNE_IN(DoorButton) // Get current value of Close Door button
{
  x = getValue.asInt();
}
1 Like