Relay question

Im a noob

Trying to make program something.
I have tried many solutions, but if someone can help me that would be great.

This is what Im trying to do.

I have a Arduino and a 4 relay module.

What I want to have is that two of the relays stay on always
while the other flash every minute, so on and off.

Think airplane lights, that are on and flash on intervals.
I thought I could do this with two lights. One always on and the other light giving the effect of flashing.

Please help

#define RELAY_ON 0
#define RELAY_OFF 1
/-----( Declare objects )-----/
/-----( Declare Variables )-----/
#define Relay_1 7 // Arduino Digital I/O pin number
#define Relay_2 8
#define Relay_3 9
#define Relay_4 10

void setup() /****** SETUP: RUNS ONCE ******/
{
//-------( Initialize Pins so relays are inactive at reset)----
digitalWrite(Relay_1, RELAY_OFF);
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF);

//---( THEN set pins as outputs )----
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
//Check that all relays are inactive at Reset

}//--(end setup )---

void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//---( Turn all 4 relays ON in sequence)---
digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
delay(10000); // wait for a second
digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
delay(50); // wait for a second
digitalWrite(Relay_3, RELAY_ON);// set the Relay ON
delay(10000); // wait for a second
digitalWrite(Relay_4, RELAY_ON);// set the Relay ON
delay(50); // wait see all relays ON

//---( Turn all 4 relays OFF in sequence)---
digitalWrite(Relay_1, RELAY_ON);// set the Relay OFF
// wait for a second
digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
delay(5000); // wait for a second
digitalWrite(Relay_3, RELAY_ON);// set the Relay OFF
// wait for a second
digitalWrite(Relay_4, RELAY_OFF);// set the Relay OFF
delay(5000); // wait see all relays OFF

}//--(end main loop )---

//( THE END )**

You'll definitely get into a mess using delay(). The delay() statements will interfere with each other. Look at the "Blink without Delay" example that comes with the Arduino IDE.

If 2 relays should be on all the time, simply set their pins high in setup() and theses will stay activated throughout the execution of the sketch.

First, it seems odd to have RELAY_OFF defined as 1 and RELAY_ON defined as 0. To me, that makes the code harder to read. Second, it would be useful to know more about the relays you're using. I'm assuming it's some kind of shield as some relays would draw more current than an I/O pin can provide. Finally, please read Nick Gammon's note at the top of this Forum on the proper way to use code tags when posting source code. That helps us help you.

I'm a bit of a noob myself so take what I say with a pinch of salt.

First off using the delay function will pause the entire program so you're delays will pause the whole program, not sure if that's intentional or not.

your sequence will currently sequentially turn all of the relays on with time delays between each operation and then turn them off with time delays again, in terms of your program your not trying to control the relays in the way you have described.

I don't know of an elegant way to do it but you could use an 'if' statement that will count to a value until the target value is reached where it will change the state of the relay and reset the counter restarting the sequence.

int counter = 0;

if (counter >=20000){ //20,000 for example. Not elegant i know but it would work.
// If the relay is on turn it off and vice versa
}else{

counter = counter + 1;

}

I'm sure someone has done something and has a beautiful delay but as I said I'm new to this too so will be interested what the efficient technique is.

I usually put my digitalWrites after my pinModes, but then I also use arrays and post my code inside code tags, so what do I know?

ok Im half way. I got two to stay on.
Now the question is.

can you activate two pins at the exact same time to make them flash.
Can you program this or do you physically need to make one wire two ports.

Two consecutive digitalWrite(), each to a specific pin, statements should do the trick if by "exactly", you mean within a few microseconds of each other.

econjack:
First, it seems odd to have RELAY_OFF defined as 1 and RELAY_ON defined as 0. To me, that makes the code harder to read.

If it's one of the typical Chinese relay modules that comes up in any Google search, the inputs are active low. So wouldn't it make good sense to define them that way?

AWOL:
I usually put my digitalWrites after my pinModes, but then I also use arrays and post my code inside code tags, so what do I know?

No doubt you're crazy enough to make your comments match what is actually happening in the code too.

evanmars:
No doubt you're crazy enough to make your comments match what is actually happening in the code too.

And to post all of your code.

Please go look at the "blink without delay" example. It's in the examples menu in your IDE.