Forward revers relay

Dear Sir;
I am in need of Arduino controlled reverse and forward relay controlled project details.
Following are the steps:-

  1. After power ON, only after pushing ON push button (PB1), after 15 seconds, both relay1 (Motor1) and relay2 (Motor2) will start automatically simultaneously and stopped simultaneously, by pushing OFF push button (PB2) .
  2. Relay3 (Motor3) will remain stopped, unless and until we press direction change push button (PB3).
  3. When we will press PB3, relay2 stops and relay3 will ON after a timing gap of 15 seconds. Both relay2 and relay3 are interlocked. And stopped through PB2.
  4. Along with PB3, there is also provision for a proximity switch (PB3 OR proximity switch) to change direction as per step number 3.
  5. All three relay1, relay2 and relay3 will start with PB1 and stopped with PB2.
  6. Relay1 is controlled with PB1 and PB2 only.
    Thanks in advance for your kind guidance and support.
    Sanjiv Mohbansi



Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

First step is to write that as a State Machine. When power comes on, start in the "Idle" state. What can happen next? If it's only PB1 gets pressed, make a new state to go into when PB1 is pressed.

From each state, figure out what other states the system change to. Eventually, you will have a complete description of what the system does. Then it is easy to turn that list of state changes into code.

Dear Sir;
Attached herewith flow chart for the process above described for your kind perusal please.
Hope you will find it in line with the above described process.
Thank you very much for your kind advise.
With best wishes;

Attached herewith flow chart for the process above described for your kind perusal please.

Nothing was attached.

File was not in as required type!
Attached herewith proper file…
Thank You very much!!! (19.9 KB)


A flow chart isn't quite the same as a state chart. In a state chart, each state is either doing something once and immediately going to the next state or sitting in a state until something happens. I assume the box on the left should go back to the Idle state. Looks like about 12 states to me.

Once you have names for all the states you would use a switch/case statement to code the actions for each state. For example:

enum States {
  Idle, WaitForStart, FirstWait15, WaitForPB2orProx, ...
} State = Idle;

void loop()
  unsigned long currentMillis = millis();
  static unsigned long timerStartMillis = 0;
  PB1_Pushed = digtalRead(PB1_DIPPin) == LOW;   // Active Low
  PB2_Pushed = digtalRead(PB2_DIPPin) == LOW;   // Active Low
  PB3_Pushed = digtalRead(PB3_DIPPin) == LOW;   // Active Low

  switch (State)
  case Idle:
    digitalWrite(RL1_DOPin, RelayOff);
    digitalWrite(RL2_DOPin, RelayOff);
    digitalWrite(RL3_DOPin, RelayOff);
    State = WaitForStart;

  case WaitForStart:
    if (PB1_Pressed)
      timerStartMillis = currentMillis;
      State = FirstWait15;

  case FirstWait15:
    if (currentMillis - timerStartMillis > 15000)
      State = WaitForPB2orProx;
    if (PB3_Pressed)
      State = Idle;

  case WaitForPB2orProx:

Dear Sir;
Thanks for your efforts and guidance.
Will work out!

Also note that while the forum software misleadingly suggests it is an appropriate file type to attach, it is in fact not appropriate to post "zip" files as they are a known vector for malware/ ransomware and competent users will generally have them blocked.

To attach an image, use an image fie type.

Please do not use "PDF"s either as they cannot be viewed in-line on the forum.

Just to save yourself some possible future embarrassment, "Dear Sir" is how you would have introduced a formal letter, before about 30 years ago, when pronouns underwent some scrutiny because of gender bias.