arduino nano r3 2 relay module and a switch

Hi

I need help with programming if anyone can help me

I use an arduino nano r 3 a switch and a module with 2 relays
I am interested in pressing the button to start the first relay and after 10 seconds to switch on the second relay,the button must be maintained during the process,after switching off the relay, the relay switching must be reversed, that is to say relay relay 2 and after 5 seconds relay 1
this cycle must work at every push of a button

thank you and a beautiful day

the button must be maintained during the process,

Just to clarify: does "button must be maintained" mean it must stay pressed?

So the sequence is:

  • Press and hold button, relay1 activates immediately
  • 10 seconds later (button still pressed) relay2 activates
  • Release button, relay2 deactivates immediately
  • 5 seconds later, relay1 deactivates
  • Rinse and repeat

... ?

(And if that's right, what happens if the button is released before relay2 kicks in at 10 seconds?

Meantime, and assuming if the button is let go early it must go back to "standby" mode with relay1 off, I wrote a state machine sketch that does what you want. Here's the serial output from a session where first the button was released early, and then held long enough:

In STANDBY phase; relays are off
   Press **and hold** the button to start the sequence
Button newly pressed, going to ON phase
   In ON phase: relay1 is on
      Hold button >10s to activate relay2
         (Premature release will cause return to STANDBY with relays off)
Button released after 150, premature return to STANDBY phase
In STANDBY phase; relays are off
   Press **and hold** the button to start the sequence
Button newly pressed, going to ON phase
   In ON phase: relay1 is on
      Hold button >10s to activate relay2
         (Premature release will cause return to STANDBY with relays off)
            Relay2 now on
Button released after 11486, going to OFF phase
   In OFF phase: relay2 is off. Relay1 will follow
         Relay1 now off
In STANDBY phase; relays are off
   Press **and hold** the button to start the sequence

Say if you want the code :wink:

zoltandorian:
Hi

I need help with programming if anyone can help me

I use an arduino nano r 3 a switch and a module with 2 relays
I am interested in pressing the button to start the first relay and after 10 seconds to switch on the second relay,the button must be maintained during the process,after switching off the relay, the relay switching must be reversed, that is to say relay relay 2 and after 5 seconds relay 1
this cycle must work at every push of a button

thank you and a beautiful day

You won't get the solution of your complete project here. Take it step by step.

First test the input example and test your switch then try relay and delays etc.

You can use Proteus software for testing your code.

jackthom41:
You won't get the solution of your complete project here.

Yes, he will...

anthonyHope:
I wrote a state machine sketch that does what you want.

Say if you want the code :wink:

... if he wants it.

anthonyHope:
Just to clarify: does "button must be maintained" mean it must stay pressed?

So the sequence is:

  • Press and hold button, relay1 activates immediately
  • 10 seconds later (button still pressed) relay2 activates
  • Release button, relay2 deactivates immediately
  • 5 seconds later, relay1 deactivates
  • Rinse and repeat

... ?

(And if that's right, what happens if the button is released before relay2 kicks in at 10 seconds?

than the sistem must auto restart ot to give an output to an red led