Please some help :) : Controlling Lock and LEDs via bluetooth

Im making a project in which i control a solenoid lock and 2 LEDs via bluetooth from an app.

So far i've been able to tell the lock and LEDs when to be high or low, pressing an OPEN/CLOSE button on the app, but i've been trying to add a new line of code, where the Arduino it self closes the lock after "X" seconds, without having to press anything on the app.

The code is the following:

const int lock = 2;
const int LEDopen = 3; // green LED
const int LEDclosed = 4; // red LED

byte serialA;

void setup()
{

Serial.begin(115200);

// initialize the LOCK and LED pins as an output:

pinMode(lock, OUTPUT);
pinMode(LEDopen, OUTPUT);
pinMode(LEDclosed, OUTPUT);

digitalWrite(LEDclosed, HIGH); // red LED starts high, and lock and green LED low.

}

void loop()

{

if (Serial.available() > 0) {serialA = Serial.read();Serial.println(serialA);}

switch (serialA) {

//OPEN

case 1:
digitalWrite(lock, HIGH); // LOCK OPENS
break;
case 3:
digitalWrite(LEDopen, HIGH); // green LED on
break;
case 6:
digitalWrite(LEDclosed, LOW); // red LED off
break;

//CLOSE

case 2:
digitalWrite(lock, LOW); // LOCK CLOSES
break;
case 4:
digitalWrite(LEDopen, LOW); // green LED off
break;
case 5:
digitalWrite(LEDclosed, HIGH); // red LED on
break;

}
}

// UNTIL HERE EVERYTHING WORKS JUST FINE, BUT NOW I WOULD LIKE THE ARDUINO TO DO LIKE A "FORCE CLOSE" AFTER "X" SECONDS, IF THE LOCK IS LEFT OPEN. I TRIED WITH THIS PIECE OF CODE (AND SOME VARIATIONS) BUT DIDN'T WORK, ANY CLUES OF HOW'S THE RIGHT WAY TO DO IT?

if (lock == HIGH)

{delay(15000); //wait 15 seconds

digitalWrite(lock, LOW); // LOCK CLOSED
digitalWrite(LEDopen, LOW); // green LED off
digitalWrite(LEDclosed, HIGH); // red LED on

}

(deleted)

WOO HOOOOOOOO!!

LEEGEND!

Thank you soooo much :slight_smile:

Cheers,

Iggy