Code or Simulation issue?

I am not sure where my problem is occurring whether i have not set up the simulation (TinkerCAD) properly or if there is a mistake/over sight in my code.

When i simulate i am getting nothing on any of the outputs.

My code compiles with no errors so its not a obvious syntax issue.

Admittedly iv only had a short while with Arduino/C++ programming so its entirely possible its a glaringly obvious oversight in the code, my only other programming experience is with Python and Programmable Logic Controllers. So could possibly be an issue in the setup() ?

I have attached a sketch and an IO Logic Table to illustrate what i am trying to achieve.

I have attached an image of the TinkerCAD simulation:

2x Green LED's/2x Switches represent 2x Pump with respective Trip
5x Red LED's represent 5x Alarm outputs
4x Switches represent Float Switched (LoLo, Lo, Hi, HiHi)

Float switches are N/C so when water is level = closed/ true/ high/ =1

I have attached the code.ino file also

Any pointers as to where i am going wrong are appreciated

Code.ino (7.86 KB)

Easy way to test it, don't use a simulator! :wink: Because yes, a lot of times they are crap.

Here as a community service are OP's pix, in-lined according to this.

I assume the 2x sim and 2x untitled 2x io logic table are dupes, but I included them anyway in case.

And here's the code:

/*
  Sump Dual Pump Controller Program
*/
#include <SPI.h>
//.........................................................................................
// Variables

// Set Arduino Pin Numbers:

// Float Switch Pin Numbers:
const int PIN_FLOAT_HI_LIMIT = 2;     // High Level Limit (Hi)
const int PIN_FLOAT_LO_LIMIT = 3;     // Low Level Limit (Lo)
const int PIN_FLOAT_HI_HI_LIMIT = 8;  // Overflow Warning (HiHi)
const int PIN_FLOAT_LO_LO_LIMIT = 9;  // Run Dry Protection (LoLo)

// Pump Pin Numbers
const int PIN_PUMP_1_ACTIVE = 4;  // Pump 1 Run
const int PIN_PUMP_2_ACTIVE = 5;  // Pump 2 Run
const int PIN_PUMP_TRIP = 10;     // Pump Tripped

// Alarm LED Pin Numbers:
const int PIN_ALARM_1 = 6;   // Warning Expected Pump Time Exceeded
const int PIN_ALARM_2 = 7;   // Error General Pump Failure
const int PIN_ALARM_3 = 11;  // Error Pump Tripped
const int PIN_ALARM_4 = 12;  // Error Run Dry Protection Activated
const int PIN_ALARM_5 = 13;  // Error Hi Limit Failure - Potential Overflow

// Input Status
int STATE_FLOAT_HI_LIMIT = 0; // High Level Limit (Hi) Status
int STATE_FLOAT_LO_LIMIT = 0; // Low Level Limit (Lo) Status
int STATE_FLOAT_HI_HI_LIMIT = 0; // Overflow Warning (HiHi) Status
int STATE_FLOAT_LO_LO_LIMIT = 0; // Run Dry Protection (LoLo) Status
int STATE_PUMP_TRIP = 0; // Pump Tripped Status

// Output Status
int STATE_ALARM_1 = 0; // Alarm 1 Status
int STATE_ALARM_2 = 0; // Alarm 2 Status
int STATE_ALARM_3 = 0; // Alarm 3 Status
int STATE_ALARM_4 = 0; // Alarm 4 Status
int STATE_ALARM_5 = 0; // Alarm 5 Status

int STATE_PUMP_1 = 0; // Pump Run Status
int STATE_PUMP_2 = 0; // Pump Run Status

// Pump Duty/Standby Switchover
int STATE_PUMP_DUTY_REQUEST = 0; // Duty Pump Run Request
int STATE_PUMP_STBY_REQUEST = 0; // Standby Pump Run Request
boolean ALTERNATE = true; // Pump 1 Duty = true, Pump 2 Duty = false

// Pump Run Timer Status
int CURRENT_PUMP_RUNTIME = 0; // Pump Run Duration

// Global Variables Used For Timer
unsigned long startMillis; // Reset Timer Reference
unsigned long currentMillis; // Current Timeer Value
const unsigned long period_1 = 30000; // Set Period 1s = 1000ms Set=30s

//.........................................................................................
void setup() {
  // put your setup code here, to run once:
  // Start SPI Libary
  SPI.begin();

  // Initialise Float Switches as Inputs
  pinMode(PIN_FLOAT_HI_LIMIT, INPUT);
  pinMode(PIN_FLOAT_LO_LIMIT, INPUT);
  pinMode(PIN_FLOAT_HI_HI_LIMIT, INPUT);
  pinMode(PIN_FLOAT_LO_LO_LIMIT, INPUT);

  // Initialsie Pumps as Outputs
  pinMode(PIN_PUMP_1_ACTIVE, OUTPUT);
  pinMode(PIN_PUMP_2_ACTIVE, OUTPUT);
  pinMode(PIN_PUMP_TRIP, INPUT);

  // Initialise Alarm LEDs as Outputs
  pinMode(PIN_ALARM_1, OUTPUT);
  pinMode(PIN_ALARM_2, OUTPUT);
  pinMode(PIN_ALARM_3, OUTPUT);
  pinMode(PIN_ALARM_4, OUTPUT);
  pinMode(PIN_ALARM_5, OUTPUT);

}
//.........................................................................................
void loop() {
  // put your main code here, to run repeatedly:

  // IO Read/Write
  // Input Status Check (Read)

  STATE_FLOAT_HI_LIMIT = digitalRead(PIN_FLOAT_HI_LIMIT); // High Level Limit (Hi) Status Check
  STATE_FLOAT_LO_LIMIT = digitalRead(PIN_FLOAT_LO_LIMIT); // Low Level Limit (Lo) Status Check
  STATE_FLOAT_HI_HI_LIMIT = digitalRead(PIN_FLOAT_HI_HI_LIMIT); // Overflow Warning (HiHi) Status Check
  STATE_FLOAT_LO_LO_LIMIT = digitalRead(PIN_FLOAT_LO_LO_LIMIT); // Run Dry Protection (LoLo) Status Check
  STATE_PUMP_TRIP = digitalRead(PIN_PUMP_TRIP); // Pump Tripped Status Check

  // Output Set (Write)

  digitalWrite(PIN_ALARM_1, STATE_ALARM_1); // SET - Warning Expected Pump Time Exceeded
  digitalWrite(PIN_ALARM_2, STATE_ALARM_2); // SET - Error General Pump Failure
  digitalWrite(PIN_ALARM_3, STATE_ALARM_3); // SET - Error Pump Tripped
  digitalWrite(PIN_ALARM_4, STATE_ALARM_4); // SET - Error Run Dry Protection Activated
  digitalWrite(PIN_ALARM_5, STATE_ALARM_5); // SET - Error Hi Limit Failure - Potential Overflow
  digitalWrite(PIN_PUMP_1_ACTIVE, STATE_PUMP_1); // SET - Pump 1 Run
  digitalWrite(PIN_PUMP_2_ACTIVE, STATE_PUMP_2); // SET - Pump 2 Run

  //.........................................................................................

  // Pump Duty/Standby Switchover
  // After each run cycle Duty/Standby default pump priority will alternate

  if (STATE_PUMP_DUTY_REQUEST == HIGH) // If Duty Pump Run is Requested
  {
    if (ALTERNATE == true)
      digitalWrite(STATE_PUMP_1, HIGH); // Pump 1 is Default Duty Run
    else
      digitalWrite(STATE_PUMP_2, HIGH); // Pump 2 is Default Duty Run
  }
  if (STATE_PUMP_STBY_REQUEST == HIGH)  // If Standby Pump Run is Requested
  {
    if (ALTERNATE == true)
      digitalWrite(STATE_PUMP_2, HIGH); // Pump 2 is Default Standby Run
    else
      digitalWrite(STATE_PUMP_1, HIGH); // Pump 1 is Default Standby Run
  }
  else
  {
    ALTERNATE = ! ALTERNATE; // Swap Default Pump
  }

  //.........................................................................................

  // Pump On Logic
  // Normal Operation Hi Limit Activate - Duty Pump Run
  if (STATE_FLOAT_HI_LIMIT == HIGH) //&& STATE_FLOAT_HI_HI_LIMIT == LOW)
  {
    startMillis = millis(); // Initial Pump Run Start Time 0s
    while (STATE_FLOAT_LO_LIMIT == HIGH) // Latch - Pump run until Lo Limit deactivated
    {
      digitalWrite(STATE_PUMP_DUTY_REQUEST, HIGH); //Duty Pump On
    }
  }
  // Over Capacity Both Hi Limits Activate - Duty & Standby Pump Run
  //if (STATE_FLOAT_HI_LIMIT == HIGH && STATE_FLOAT_HI_HI_LIMIT == HIGH)
  {
    //digitalWrite(STATE_PUMP_DUTY_REQUEST, HIGH); //Duty Pump On
    //digitalWrite(STATE_PUMP_STBY_REQUEST, HIGH); //Standby Pump On
    //digitalWrite(STATE_ALARM_5, HIGH); //Set Alarm
  }
  // Hi Limit Failure Hi Hi Limit Activate -  Duty & Standby Pump Run
  //else (STATE_FLOAT_HI_LIMIT == LOW && STATE_FLOAT_HI_HI_LIMIT == HIGH)
  {
    //digitalWrite(STATE_PUMP_DUTY_REQUEST, HIGH); //Duty Pump On
    //digitalWrite(STATE_PUMP_STBY_REQUEST, HIGH); //Standby Pump On
    //digitalWrite(STATE_ALARM_5, HIGH); //Set Alarm
  }

  //.........................................................................................

  // Pump Off Logic
  // Normal Operation Lo Limit Deactivated - Duty & Standby Pump Stop
  if (STATE_FLOAT_LO_LIMIT == LOW) //&& STATE_FLOAT_LO_LO_LIMIT == HIGH)
  {
    startMillis = millis(); // Reset Time 0s
    digitalWrite(STATE_PUMP_DUTY_REQUEST, LOW); //Duty Pump Off
    digitalWrite(STATE_PUMP_STBY_REQUEST, LOW); //Standby Pump Off
  }
  // Sump Empty Both Lo Limits Deactivated
  // Run Dry Protection - Duty & Standby Pump Not Allowed To Start
  //if (STATE_FLOAT_LO_LIMIT == LOW && STATE_FLOAT_LO_LO_LIMIT == LOW)
  {
    //startMillis = millis(); // Reset Time 0s
    //digitalWrite(STATE_PUMP_DUTY_REQUEST, LOW); //Duty Pump Off
    //digitalWrite(STATE_PUMP_STBY_REQUEST, LOW); //Standby Pump Off
    //digitalWrite(STATE_ALARM_4, HIGH); //Set Alarm
  }
  // Lo Limit Failure Lo Lo Limit Activate -  Duty & Standby Pump Stop
  // Run Dry Protection - Duty & Standby Pump Not Allowed To Start
  //else (STATE_FLOAT_LO_LIMIT == HIGH && STATE_FLOAT_LO_LO_LIMIT == LOW)
  {
    //startMillis = millis(); // Reset Time 0s
    //digitalWrite(STATE_PUMP_DUTY_REQUEST, LOW); //Duty Pump Off
    //digitalWrite(STATE_PUMP_STBY_REQUEST, LOW); //Standby Pump Off
    //digitalWrite(STATE_ALARM_4, HIGH); //Set Alarm
  }

  //.........................................................................................

  // Pump Tripped Alarm
  if (STATE_PUMP_TRIP == HIGH) // If Pump 1 and/or Pump 2 TOR Tripped
  {
    digitalWrite(STATE_ALARM_3, HIGH); // SET - Error Pump Tripped
  }

}

Are those black square thingies switches? Real switches?

If so, they need a pull down resistor. Or easier, don't connect them to 5V but to GND and use the internal pull up resistor with pinMode(pin, INPUT_PULLUP); Note, logic now is flipped :slight_smile:

the only way to get real answers is to stop using simulators, they are nothing but burden of crap !

septillion:
Are those black square thingies switches? Real switches?

If so, they need a pull down resistor. Or easier, don't connect them to 5V but to GND and use the internal pull up resistor with pinMode(pin, INPUT_PULLUP); Note, logic now is flipped :slight_smile:

Yes in the simulator 3 Pos switches in real life application float switches. I suspect this is my problem i wasnt aware of this "pullup" il have a play and see if it works.

KASSIMSAMJI:
the only way to get real answers is to stop using simulators, they are nothing but burden of crap !

septillion:
Easy way to test it, don't use a simulator! :wink: Because yes, a lot of times they are crap.

I have an Arduino on order just wanted to check the code i had written in the mean time