programming relay switching timer

Hi i have written a sketch for 2 8 channel relay boards
the problem i have is i need one of the relays to stay on for just about 2 seconds while another relay come on
what i need is the 1st one to overlap the second one
but what happens is the first one comes on then goes off then the second comes on etc
i want if to overlap
can you do this?

Jcneo: can you do this?

Well you can ;) but you will probably need to look at how use millis() to take care of the timing, as described (for instance) here and here.

You should also post the sketch you have so far.

Hi thanks for your rely i m new to this do not know how to post the scketch

Jcneo:
Hi thanks for your rely
i m new to this
do not know how to post the scketch

See How to post a programming question at the top of the page

#define RELAY1 6
#define RELAY2 7
#define RELAY3 8
#define RELAY4 9
#define RELAY5 10
#define RELAY6 11
int timer = 1000;





void setup() {

  //Initialise the arduino data pins for output:
  pinMode(RELAY1, OUTPUT);//this pin is trigger
  pinMode(RELAY2, OUTPUT);// relay Pin7 charge bank1
  pinMode(RELAY3, OUTPUT);//relay Pin8 high bank 3
  pinMode(RELAY4, OUTPUT);//relay Pin9 low bank4
  pinMode(RELAY5, OUTPUT);//relay Pin10 rest bank2
  pinMode(RELAY6, OUTPUT);//relay Pin3 charge bank 2
  

}

void loop()
{
  digitalWrite(RELAY1, HIGH);     //Turns ON Relays triggercoil 1
  delay(timer);                   //Wait 3 seconds
  digitalWrite(RELAY1, LOW );    //Turns Relay Off


  digitalWrite(RELAY2, HIGH);     // turns ON pin 7relays RedBank 1,2,11,12,15,16
  delay(10000);                    //Wait 3 seconds
  digitalWrite(RELAY2, LOW);     //Turns Relay Off

  digitalWrite(RELAY1, HIGH);     //Turns ON Relays triggercoil 1
  delay(timer);                   //Wait 3 seconds
  digitalWrite(RELAY1, LOW);    //Turns Relay Off

  digitalWrite(RELAY3, HIGH);     // turns ON pin 8 Relays GreenBank7,8,17,18,21,22
  delay(10000);                    //Wait 3 seconds
  digitalWrite(RELAY3, LOW);     //Turns Relay Off

  digitalWrite(RELAY1, HIGH);     //Turns ON Relays triggercoil 1
  delay(timer);                   //Wait 3 seconds
  digitalWrite(RELAY1, LOW);    //Turns Relay Off

  digitalWrite(RELAY4, HIGH);     // turns ON pin 9 Magenta Relays purpleBank 13,14,23,24,3,4
  delay(10000);                               //Wait 3 seconds
  digitalWrite(RELAY4, LOW);     //Turns Relay Off


  digitalWrite(RELAY1, HIGH);     //Turns ON Relays 1
  delay(timer);                   //Wait 3 seconds
  digitalWrite(RELAY1, LOW);    //Turns Relay Off

  digitalWrite(RELAY5, HIGH);    // turns ON pin 10 BlueBank relays 19,20,5,6,9,10
  delay(10000);                    //Wait 3 seconds
  digitalWrite(RELAY5, LOW);     //Turns Relay Off


  // put your main code here, to run repeatedly:

}

Yeah that’s what I expected to see, and obviously you have found that while relay “x” is in its delay, relay “x+1” won’t start. That’s the so-called “blocking” nature of delay.

So you do indeed need to have a look at those links I gave earlier, where you can leave the old behind and enter a whole new universe of delay-less timings with millis().

The problem is that when you use delay() the processor stops looking at any other instructions for the whole of the delay time. But if the timing is simple enough you can still do it without the relative complexity of millis() provided you work out the combined timing exactly e.g. switch Relay 1 on, delay(1000), switch Relay 2 on, delay(1000) switch Relay 1 off etc. That switches Relay 1 on for two seconds with Relay2 switching on halfway through the two seconds.

But using millis() is a much better general solution.

Steve

slipstick's approach is very sensible, and in thus case might be exactly what you need.

Draw a time line: time from left to right, and a line across for each relay. Mark the on and off times for each relay on their lines. Then work from the left and do exactly what slipstick suggested, building the overlaps in.

It's going to be a pain to maintain though, since if one delay requirement changes and you change its delay in the code, everything to the right of that point on the timeline will shift by the amount of the change.

But it's a nice simple approach which may well do the trick.

millis() will allow all the timings to be independent of each other. Have a look at this youtube video which highlights this exact problem, and solves it with millis().