digitalWrite(doorContactPin,LOW);
val = digitalRead(doorContactPin);
The doorContactPin pin is defined as an input. Setting it HIGH or LOW turns on or off the pullup resistor. Turning the pullup resistor on an off in the code makes no sense. You either want it always on, or always off.
val = digitalRead(doorContactPin);
while(val == HIGH){
val = digitalRead(doorContactPin);
}
Some comments that describe why this code is here, in setup(), would be a good idea.
time = 0;
while((val == LOW)&&(time < time_threshold)){
time = time + 100;
val = digitalRead(doorContactPin);
delay(100);
digitalWrite(doorContactPin,LOW);
}
if (time >= time_threshold){
digitalWrite(doorContactPin,HIGH);
}
Ditto for this code. Turning the INPUT pin off and on makes no sense, as I mentioned.