Arduino does not carry out commands

Dear All

I have an Arduino circuit using WOKWI and I think the program code I created is correct. However, when I simulated it turned out that PB_LS1, PB_LS2, PB_LS3 or PB_LS4 when pressed were not implemented.

Please provide information on why this might happen.

For the following circuit circuit program code in wokwi please click:

I have also included the program code below.

Thank you for the help.

#include <Arduino.h>
#include <LiquidCrystal.h>

// Initialize pins for buttons
const int PB_EMERGENCY = 39;
const int PB_STOP_ALL = 40;
const int PB_AUTO = 41;
const int PB_DOWN = 42;
const int PB_UP = 43;
const int PB_LS1 = 44;
const int PB_LS2 = 45;
const int PB_LS3 = 46;
const int PB_LS4 = 47;
const int PB_BV_CLOSE = 48;
const int PB_BV_OPEN = 49;
const int PB_EV1_CLOSE = 50;
const int PB_EV1_OPEN = 51;
const int PB_EV2_CLOSE = 52;
const int PB_EV2_OPEN = 53;

// Initialize pins for relays
const int relay_auto = 34;
const int relay_reverse = 35;
const int relay_forward = 36;
const int relay_empty = 37;
const int relay_emergency = 30;
const int relay_stop_all = 31;
const int relay_filling = 32;
const int relay_emptying = 33;
const int relay_EV1_close = 26;
const int relay_EV1_open = 27;
const int relay_EV2_close = 28;
const int relay_EV2_open = 29;
const int relay_BV_close = 24;
const int relay_BV_open = 25;

// Initialize pins for LCD
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

// Variables to track button states
bool isAutoRunning = false;
bool isUpRunning = false;
bool isDownRunning = false;

// Enum for status
enum State {
  AUTO,
  AUTO1,
  AUTO1_1,
  AUTO1_2,
  AUTO1_3,
  AUTO2,
  AUTO3,
  AUTO4
};

State status = AUTO;  // Initial state initialization

void setup() {

  // Initialize the pin as input_PULLUP
  pinMode(PB_AUTO, INPUT_PULLUP);
  pinMode(PB_DOWN, INPUT_PULLUP);
  pinMode(PB_UP, INPUT_PULLUP);
  pinMode(PB_STOP_ALL, INPUT_PULLUP);
  pinMode(PB_EMERGENCY, INPUT_PULLUP);
  pinMode(PB_BV_CLOSE, INPUT_PULLUP);
  pinMode(PB_BV_OPEN, INPUT_PULLUP);
  pinMode(PB_EV1_CLOSE, INPUT_PULLUP);
  pinMode(PB_EV1_OPEN, INPUT_PULLUP);
  pinMode(PB_EV2_CLOSE, INPUT_PULLUP);
  pinMode(PB_EV2_OPEN, INPUT_PULLUP);
  pinMode(PB_LS1, INPUT_PULLUP);
  pinMode(PB_LS2, INPUT_PULLUP);
  pinMode(PB_LS3, INPUT_PULLUP);
  pinMode(PB_LS4, INPUT_PULLUP);

  // Initialize the pin as OUTPUT
  pinMode(relay_auto, OUTPUT);
  pinMode(relay_reverse, OUTPUT);
  pinMode(relay_forward, OUTPUT);
  pinMode(relay_empty, OUTPUT);
  pinMode(relay_emergency, OUTPUT);
  pinMode(relay_stop_all, OUTPUT);
  pinMode(relay_filling, OUTPUT);
  pinMode(relay_emptying, OUTPUT);
  pinMode(relay_EV1_close, OUTPUT);
  pinMode(relay_EV1_open, OUTPUT);
  pinMode(relay_EV2_close, OUTPUT);
  pinMode(relay_EV2_open, OUTPUT);
  pinMode(relay_BV_close, OUTPUT);
  pinMode(relay_BV_open, OUTPUT);
}

void loop() {

  if (digitalRead(PB_AUTO) == LOW && !isUpRunning && !isDownRunning) {
    // Process when the PB_AUTO button is pressed
    isAutoRunning = true;
    // Perform the necessary processes for PB_AUTO

    switch (status) {
      case AUTO:  //0
        if (digitalRead(relay_BV_close) == LOW) {
          digitalWrite(relay_BV_close, LOW);
          digitalWrite(relay_BV_open, HIGH);
          status = AUTO1;
        } else if (digitalRead(relay_BV_open) == LOW) {
          status = AUTO1;
        }
        break;

      case AUTO1:  //1
        digitalWrite(relay_reverse, HIGH);
        delay(7000);
        digitalWrite(relay_reverse, LOW);
        digitalWrite(relay_filling, HIGH);
        delay(2000);
        digitalWrite(relay_forward, HIGH);
        status = AUTO2;
        break;

      case AUTO1_1:  //2
        // Code if required for AUTO1_1
        status = AUTO3;  // Change to next state
        break;

      case AUTO1_2:  //3
        digitalWrite(relay_emptying, HIGH);
        delay(2000);
        digitalWrite(relay_forward, HIGH);
        status = AUTO4;
        break;

      case AUTO1_3:  //4
        if (digitalRead(PB_LS4) == LOW) {
          status = AUTO;
        }
        break;

      case AUTO2:  //5
        if (digitalRead(PB_LS2) == LOW) {
          digitalWrite(relay_BV_open, LOW);
          digitalWrite(relay_BV_close, HIGH);
        }
        if (digitalRead(PB_LS1) == LOW) {
          digitalWrite(relay_forward, LOW);
          status = AUTO1_1;
        }

        break;

      case AUTO3:  //6
        if (digitalRead(PB_LS3) == LOW) {
          digitalWrite(relay_reverse, HIGH);
        }
        if (digitalRead(PB_LS2) == LOW) {
          digitalWrite(relay_reverse, LOW);
          status = AUTO1_2;
        }

        break;

      case AUTO4:  //7
        if (digitalRead(PB_LS2) == LOW) {
          digitalWrite(relay_BV_close, LOW);
          digitalWrite(relay_BV_open, HIGH);
        }
        if (digitalRead(PB_LS1) == LOW) {
          digitalWrite(relay_forward, LOW);
          status = AUTO1_3;
        }

        break;
    }

  } else if (digitalRead(PB_UP) == LOW && !isAutoRunning && !isDownRunning) {
    // Process when the PB_UP button is pressed
    isUpRunning = true;
    // Perform the necessary processes for PB_UP
    digitalWrite(relay_forward, HIGH);  // Turn on the forward relay
    if (digitalRead(PB_LS1) == LOW) {
      // If the PB_LS1 button is pressed, perform the following actions:
      digitalWrite(relay_forward, LOW);    // Mematikan relay_forward
      digitalWrite(relay_BV_open, LOW);    // Mematikan relay_BV_open
      digitalWrite(relay_BV_close, HIGH);  // Menghidupkan relay_BV_close
    }

  } else if (digitalRead(PB_DOWN) == LOW && !isAutoRunning && !isUpRunning) {
    // Process when the PB_DOWN button is pressed
    isDownRunning = true;
    // Perform the necessary processes for PB_DOWN
    digitalWrite(relay_reverse, HIGH);
  }

  if (digitalRead(PB_STOP_ALL) == LOW) {
    // Process when the PB_STOP_ALL button is pressed
    isAutoRunning = false;
    isUpRunning = false;
    isDownRunning = false;
    // Perform the necessary stop process
    digitalWrite(relay_reverse, LOW);
    digitalWrite(relay_forward, LOW);
  }

  if (digitalRead(PB_EMERGENCY) == LOW) {
    // Process when the PB EMERGENCY button is pressed
    isAutoRunning = false;
    isUpRunning = false;
    isDownRunning = false;
    // Carry out necessary emergency processes
    digitalWrite(relay_EV1_open, LOW);
    digitalWrite(relay_EV1_close, HIGH);
    digitalWrite(relay_EV2_open, LOW);
    digitalWrite(relay_EV2_close, HIGH);

    digitalWrite(relay_reverse, LOW);
    digitalWrite(relay_forward, LOW);
  }

  if (!isAutoRunning && !isUpRunning && !isDownRunning) {
    if (digitalRead(PB_BV_CLOSE) == LOW) {
      // Process when the PB_BV_CLOSE button is pressed when no other processes are running
      // Perform the necessary processes for PB_BV_CLOSE
      digitalWrite(relay_BV_open, LOW);
      digitalWrite(relay_BV_close, HIGH);
    }

    if (digitalRead(PB_BV_OPEN) == LOW) {
       // Process when the PB_BV_OPEN button is pressed when no other processes are running
      // Perform the necessary processes for PB_BV_OPEN
      digitalWrite(relay_BV_close, LOW);
      digitalWrite(relay_BV_open, HIGH);
    }
  }

  if (digitalRead(PB_EV1_CLOSE) == LOW) {
   // Process when the PB_EV1_CLOSE button is pressed when no other processes are running
      // Perform the necessary processes for PB_EV1_CLOSE
    digitalWrite(relay_EV1_open, LOW);
    digitalWrite(relay_EV1_close, HIGH);
  }

  if (digitalRead(PB_EV1_OPEN) == LOW) {
   // Process when the PB_EV1_OPEN button is pressed when no other processes are running
      // Perform the necessary processes for PB_EV1_OPEN
    digitalWrite(relay_EV1_close, LOW);
    digitalWrite(relay_EV1_open, HIGH);
  }

  if (digitalRead(PB_EV2_CLOSE) == LOW) {
 // Process when the PB_EV2_CLOSE button is pressed when no other processes are running
      // Perform the necessary processes for PB_EV2_CLOSE
    digitalWrite(relay_EV2_open, LOW);
    digitalWrite(relay_EV2_close, HIGH);
  }

  if (digitalRead(PB_EV2_OPEN) == LOW) {
  // Process when the PB_EV2_OPEN button is pressed when no other processes are running
      // Perform the necessary processes for PB_EV2_OPEN
    digitalWrite(relay_EV2_close, LOW);
    digitalWrite(relay_EV2_open, HIGH);
  }
}

It would be helpful if you could translate your comments into English.

Also, in the simulation, none of the relay modules have power connected.

There's a good deal more to be straightened out, but I'd start there.

Hello harkelumum

What is the task of the sketch in real life?

This is like bailer for water well

Do you also have a description?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.