2 relays with delays

Hi guys im in urgent need of putting together code for an arduino duemilanove to control two relays. One relay needs two continually run when it is started by a push button and then the sequence will begin, start motor then after 2 mins start second relay, run 2nd relay for 2mins then stop. this will continually run until told to stop. i know how to wire everything up but im having trouble with the code. Any ideas?

Any ideas?

Don't use delay().

One relay needs two continually run when it is started by a push button

Relays don't run. The open or close. Push buttons don't start relays. They may generate a signal that the Arduino can read.

and then the sequence will begin

What sequence?

start motor then after 2 mins start second relay, run 2nd relay for 2mins then stop.

Motors run. Relays don't.

but im having trouble with the code.

No, you are having trouble with the requirements and terminology. You haven't even started to code. Get the terminology straight, define the requirements correctly, and the code will be easy.

To get around having to use long delay(xxx) calls in your code, which stall
the processor, take a look in the IDE at the "File > Examples > 2.Digital >
BlinkWithoutDelay" sketch.

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?

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.

Instead of delay 5000 you setup a variable and set it to millis() + 5000

Addition with unsigned longs is not guaranteed to work. Subtraction is. Now - then > interval as test will always work. Then + 5000 > interval may not. Might as well learn to do it properly from the beginning.

Looks like others explained it above but i found this pretty helpful, I was doing the same thing:

http://arduino.cc/playground/Code/AvoidDelay