int relay1 = 2;
int relay2 = 3;
int Limit1 = 4;
int Limit2 = 5;

const int triggerType = LOW;  // your relay type

int relayOFF, relayON;  // relay ON and OFF values for LOW and HIGH Trigger relays



void setup() {

  pinMode(relay1, OUTPUT);  // set pin as output for relay 1
  pinMode(relay2, OUTPUT);  // set pin as output for relay 2
  pinMode(Limit1, INPUT);   // set pin as input for Limit switch 1
  pinMode(Limit2, INPUT);   // set pin as input for Limit switch 2


  if (triggerType == LOW) {
    relayON = LOW;
    relayOFF = HIGH;
    digitalWrite(relay1, relayOFF);  //keep both relay OFF so motor is stopped
    digitalWrite(relay2, relayOFF);  //keep both relay OFF so motor is stopped
  } else {
    relayON = HIGH;
    relayOFF = LOW;
    digitalWrite(relay1, relayOFF);  //keep both relay OFF so motor is stopped
    digitalWrite(relay2, relayOFF);  //keep both relay OFF so motor is stopped
  }


  Serial.begin(9600);  // initialize serial monitor with 9600 baud
  Serial.println("Robojax Motor Direction of Rotation");
  Serial.println("Using 2 Relays");
  delay(2000);
}

void loop() {

  // Rotate in CCW direction
  motorCCW();
  while (1)
  {
    int state1 = digitalRead(Limit1);
    while (state1 == HIGH && digitalRead(Limit2) == LOW) {
      motorCCW();
      // delay(3000);  // wait for 3 seconds
      if (digitalRead(Limit2) == LOW) {
        continue;
      } else {
        motorStop();
        break;
        // delay(2000);
      }
    }
    int state2 = digitalRead(Limit2);
    while (state2 == HIGH && digitalRead(Limit1) == LOW) {
      // Rotate in CW direction
      motorCW();
      // delay(3000);  // wait for 3 seconds
      if (digitalRead(Limit1) == LOW) {
        continue;
      } else {
        motorStop();
        break;
        // delay(2000);
      }
    }

    Serial.println("===============");
  }
  Serial.println("OUT");
}  // loop end

/*
   motorCCW()
   controls the relay so the motor rotates in CCW
*/
void motorCCW() {
  digitalWrite(relay1, relayON);   // turn relay 1 ON
  digitalWrite(relay2, relayOFF);  // turn relay 2 OFF
  Serial.println("Rotating in CCW");
}  // motorCCW()


/*
   motorCW()
   controls the relay so the motor rotates in CW
*/
void motorCW() {
  digitalWrite(relay1, relayOFF);  // turn relay 1 OFF
  digitalWrite(relay2, relayON);   // turn relay 2 ON
  Serial.println("Rotating in CW");
}  //motorCW()


/*
   motorStop()
   controls the relay so the motor is stopped
*/
void motorStop() {
  digitalWrite(relay1, relayOFF);  // turn relay 1 OFF
  digitalWrite(relay2, relayOFF);  // turn relay 2 OFf
  Serial.println("Stopped");
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay2:VCC
relay2:GND
relay2:IN
relay2:NC
relay2:COM
relay2:NO
led1:A
led1:C
led2:A
led2:C
vcc3:VCC
gnd2:GND
vcc4:VCC
gnd3:GND
vcc5:VCC
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
led3:A
led3:C
gnd1:GND
led4:A
led4:C