Timer with offset

Hello,

I need to program a timer for three relays(controlled by mosfets).
The problem is that I want an offset between triggering the relays, but have the same off and on time for the three timers.

I am stuck, cannot think of an efficient way of doing this, but I am sure some of you know the answer :slight_smile:

What do you mean by an offset considering that the relays have the same off and on time ?

Do you perhaps mean that they have the same off and on periods ?

Does a single event trigger the start of the sequence ?

UKHeliBob:
What do you mean by an offset considering that the relays have the same off and on time ?

Do you perhaps mean that they have the same off and on periods ?

Does a single event trigger the start of the sequence ?

Hi,

The relays has the same off and on time, but I need them to turn on and off with an offset to each other

Like this:
Relay 1:on-off-off-off-on-off-off-off
Relay 2:off-on-off-off-off-on-off-off
Relay 3:off-off-on-off-off-off-on-off

Does that make any sense? As said, the on and off time is the same for all

It sounds like you need some code that changes state at regular intervals (the duration of one of the periods in your diagram) and at each interval a relay gets turned on or off. Perhaps have a counter that starts at 1 and counts up at each interval and goes back to 1 after 3. If the count is 1, then turn relay 1 on. If the count is 2 turn relay 2 on etc.

I suspect this is not exactly what you need, but it should put you on the write right track.

...R

Edited to correct an appalling error - using write when I intended right - apologies to everyone

Robin2:
It sounds like you need some code that changes state at regular intervals (the duration of one of the periods in your diagram) and at each interval a relay gets turned on or off. Perhaps have a counter that starts at 1 and counts up at each interval and goes back to 1 after 3. If the count is 1, then turn relay 1 on. If the count is 2 turn relay 2 on etc.

I suspect this is not exactly what you need, but it should put you on the write track.

...R

Thank you, that was not a bad idea :slight_smile:

I was going to try and describe this but it was easier to write a program

//Relay 1:on-off-off-off-on-off-off-off
//Relay 2:off-on-off-off-off-on-off-off
//Relay 3:off-off-on-off-off-off-on-off

const byte states[]  {
  0b10001000,
  0b01000100, 
  0b00100010
  };

const byte relayPins[] = {10, 11, 12};
int bitIndex;

void setup()
{
  Serial.begin(115200);
  for (int pin = 0; pin < 3; pin++)
  {
    pinMode(relayPins[pin], OUTPUT);
  }
}

void loop()
{
  delay(1000);
  bitIndex = bitIndex - 1;
  if (bitIndex < 0)
  {
    bitIndex = 7;
  }
  for (int relay = 0; relay < 3; relay++)
  {
    digitalWrite(relayPins[relay], bitRead(states[relay], bitIndex));
  }
}

NOTE : I used delay() as an illustration. You may need to use millis() for timing if other things need to happen in loop()

UKHeliBob:
I was going to try and describe this but it was easier to write a program

//Relay 1:on-off-off-off-on-off-off-off

//Relay 2:off-on-off-off-off-on-off-off
//Relay 3:off-off-on-off-off-off-on-off

const byte states  {
  0b10001000,
  0b01000100,
  0b00100010
  };

const byte relayPins = {10, 11, 12};
int bitIndex;

void setup()
{
  Serial.begin(115200);
  for (int pin = 0; pin < 3; pin++)
  {
    pinMode(relayPins[pin], OUTPUT);
  }
}

void loop()
{
  delay(1000);
  bitIndex = bitIndex - 1;
  if (bitIndex < 0)
  {
    bitIndex = 7;
  }
  for (int relay = 0; relay < 3; relay++)
  {
    digitalWrite(relayPins[relay], bitRead(states[relay], bitIndex));
  }
}




NOTE : I used delay() as an illustration. You may need to use millis() for timing if other things need to happen in loop()

Thank you, I will tinker a bit with this when I have the time :slight_smile: Great to get new insight on how codes can be used.