2 relays with delays

pvera:
Thanks guys, yes i dont have my terminology right. At the mometn i have:

const byte bIn1=5;
const byte HEATER=12;
const byte MOTOR=13;

void setup()
{
pinMode(bIn1,INPUT);
pinMode(HEATER,OUTPUT);
pinMode(MOTOR,OUTPUT);
}

void loop()
{
if (digitalRead(bIn1)==LOW)
{ digitalWrite(MOTOR,HIGH);

digitalWrite(HEATER,HIGH);
delay(5000);

digitalWrite(12,LOW);
delay(5000);}

else { digitalWrite(MOTOR,LOW);
digitalWrite(HEATER,LOW);};

;
}

It does what i want it to with the switch being on a door so it stays on (lid closed ) and off (lid open), the only issue i have is that i want the motor and heater to stop immediately when i open the lid but it waits until the delay is finished and then stops. How can i get it to stop immediately?

Thus why everybody told you to not use delay, forget that it exists. Delay like goto is something you should NEVER need to use unless it's part of interfacing with low level hardware and even then it's dodgy. Instead of delay 5000 you setup a variable and set it to millis() + 5000 and switch it off via an if statement. Please go look at the blink without delay sample sketch it's all in there.