1 Sensor - 2 Relays. How to switch them on / off independently?

Dear specialists!

I`m a new Arduino User, and this is my first posting. May I ask you a question regarding my project?

I need to start 2 Motors depending on the signal of PIR sensor.

I have all the hardware and everything works fine.
For example, if I make my sketch just to turn on both of the relays "together" , "hand in hand", say, 3 seconds after the Sensor switched on and hold both of the relays for 7 seconds On, it is working, because it is simple, using the delay() function.

But what I need is something like that: after the Sensor is sending the HIGH signal, I need the First relay to start, say, 2 seconds after the Sensor and keep on for 10 seconds only, but the Second relay to start only 15 secs after the initial signal from Sensor and keep the second motor on for, lets say 30 seconds, after that to switch off. And NOT to continue to do it further in a loop, until the new signal from Sensor arrives.

I mean - I need individual starting time and duration time for each of my relays / motors, but the starting point - the signal from the Sensor - is the same for both relays.

And when - after some longer pause programmed trough delay() Arduino - the signal from Sensor is coming again, I need my relays to behave exactly as the previous time:
one earlier, other later; one for shorter time, other for longer time.

How something like that could be done? One sensor and 2 timewise differently behaving actuators?

I discovered the Metro library a bit, but I was not too talented to implement it in my sketch.

I would appreciate any advice indeed.

thanks! And sorry about my english.

Gj

But what I need is something like that: after the Sensor is sending the HIGH signal, I need the First relay to start, say, 2 seconds after the Sensor and keep on for 10 seconds only, but the Second relay to start only 15 secs after the initial signal from Sensor and keep the second motor on for, lets say 30 seconds, after that to switch off. And NOT to continue to do it further in a loop, until the new signal from Sensor arrives.

You'll need to detect when the signal from the sensor is not the same as the last signal from the sensor. This is a transition (from no one around to someone around or from someone around to no one around).

Doing something only at the transition solves your second problem.

Using millis() as in the blink without delay example, instead of delay() is how you address your first problem.

When the sensor goes high, set a flag that says that the relays need to be toggled.

After that, check if the flag is true. If it is, see if it is time to change a relay state, based on now and then (then being the last time the relay state was changed) and the interval between changes.

When the last change has occurred (the second relay turned off) clear the flag that said that the relays needed toggling.

You'll need to detect when the signal from the sensor is not the same as the last signal from the sensor. This is a transition (from no one around to someone around or from someone around to no one around).

Thanks a lot Paul!

The thing is, that I need the signal from the Sensor to be "recognized" by Arduino only once in say 9 minutes. If something happens in the middle, nothing should be switched on at all. So, I guess, during 9 minutes lots of such transitions can happen... And during those 9 minutes I need the "reaction" of relais only once, no more, and at exact time and for an exact duration. And at the beginning of the "next" series of 9 minutes, the timing has to be reset for relays and for sampler.

I will study the blink without delay example as you suggested! But seems that this Metro library rather wouldn't be your suggestion, am I right?

thanks

Gj

The thing is, that I need the signal from the Sensor to be "recognized" by Arduino only once in say 9 minutes. If something happens in the middle, nothing should be switched on at all.

You mean that if another HIGH occurs during that 9 minutes, the previous switching cycle should continue, don't you?

While the 9 minute cycle is running, you can ignore the PIR.

But seems that this Metro library rather wouldn't be your suggestion, am I right?

No, it wouldn't. But that just might be because I understand how to make things happen at specific intervals without it.