door lock with Arduino and a servo

and that the time before he locks again getting longer?

The way that it is done at the moment is madness because loop() will run so fast that the value of timer will get to zero in practically no time at all despite the waste of time pointed out by Paul.

The answer is, of course, use the BlinkWithoutDelay principle. Save a start time then check each time through loop() whether the desired interval has elapsed and if it has, act on it. If not, go round again until it has or until user input is used to terminate the wait prematurely.