Hello
I am new to Arduino, having worked with BASIC Stamp products, I am not starting from Zero, but the few projects I have done seem to have been more tedious than they needed to be. I am sure this code will get chuckles from experienced coders, but it does do what I wanted it to do, it has been debugged and tested with real hardware...I would love it if someone could let me know how to make it more streamlined. I know the many GOTO's are not very tidy, but not sure where to start cleaning it up.
I added comments, so it should be readable.
Goal: Control a water filtration pumping skid-
Holding the Low Pressure pump switch starts a pump, and once the pressure in the pipe comes up and makes the switch (PS_1), it latches and can then start the High Pressure pump with a button press. At any time, if the E-stop is pushed, or the pressure switch (PS_1) opens, everything shuts down.
My code below
Thanks for any suggestions, I was just happy to make it work, but always room to learn and improve.
Dave
// constants
const int LP_start = 3; // Feedwater Pump pushbutton
const int All_Stop = 4; // E-Stop pushbutton
const int PS_1 = 5; // Pressure Switch
const int HP_start = 6; // High Pressure Pump pushbutton
const int FWP_ON = 10; // FW Pump relay
const int All_OFF = 12; // Red Panel Lamp
const int HPP_ON = 11; // HP Pump Relay
// variables set to initial safe value
int STOP_State = 1;
int x = 0;
int y = 0;
void setup() {
pinMode(All_Stop, INPUT); // initialize the pushbutton pin as an input:
pinMode(LP_start, INPUT); // initialize the pushbutton pin as an input:
pinMode(PS_1, INPUT); // initialize the pressure switch pin as an input:
pinMode(HP_start, INPUT); // initialize the pushbutton as an input:
pinMode(FWP_ON, OUTPUT); // this will be a relay to start FW pump
pinMode(All_OFF, OUTPUT); // this will be a panel light
pinMode(HPP_ON, OUTPUT); // this will be a relay to start HP pump
digitalWrite(All_OFF, LOW); //sets EMO to OFF
digitalWrite(FWP_ON, LOW); // sets LP pump OFF
digitalWrite(HPP_ON, LOW); // sets HP pump OFF
}
void loop() {
Begin:
x =digitalRead(LP_start); // check the FW Pump switch
STOP_State = digitalRead(All_Stop); //check the E-Stop switch
if ((STOP_State== HIGH)&&(x > 0)) // If E-Stop and FW Pump request = TRUE, Turn ON the pump, turn OFF the Red lamp
{
delay(100);
digitalWrite(FWP_ON, HIGH);
digitalWrite(All_OFF, LOW);
delay (100);
}
else
{
digitalWrite(FWP_ON, LOW); // turn LP pump off:
digitalWrite(All_OFF, HIGH); // Turn "OFF" light ON
digitalWrite(HPP_ON, LOW); // turn HP pump off:
goto Begin;
}
if (digitalRead (PS_1)==HIGH) //Now check to see if pressure switch is made
{
goto Proved;
}
else
{
goto Begin;
}
Proved:
x = digitalRead(PS_1); //Reads pressure switch
y = digitalRead(HP_start); //Reads HP Pump switch
STOP_State = digitalRead(All_Stop); //Read the E-Stop switch
if ((STOP_State== HIGH)&& (x > 0)&& (y > 0)) //If all 3 are TRUE, GOTO Pump Request
{
goto PumpRequest;
}
else
if ((STOP_State== HIGH)&& (x > 0)) //Check to see if E-Stop pushed OR PS-1 opens
{
goto Proved; //Loop waiting for HP Pump switch
}
{
goto Begin; //E-Stop or PS-1 opened...must Re-Start
}
PumpRequest:
x = digitalRead(PS_1); //Reads pressure switch
STOP_State = digitalRead(All_Stop); //Read the E-Stop switch
if ((STOP_State== HIGH)&& (x > 0))
{
digitalWrite(HPP_ON, HIGH); //Turn on HP Pump
delay (500);
goto PumpRequest; //Loop back to check for E-Stop or PS-1 opened
}
else
{
digitalWrite(HPP_ON, LOW); //E-Stop or PS-1 opened...must Re-Start
goto Begin;
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.