#include <LiquidCrystal.h>
enum State_enum
{
Normal_condition,
Emergency_Condition,
};
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // pin 3 of LCD should be connected to GND
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int relay1 = 6; // VCC Pin attached to Digital Pin 13, Glycol Pump
const int relay2 = 7; // VCC Pin attached to Digital Pin 12, Water Pump
const int relay3 = 8; // VCC Pin attached to Digital Pin 11, Glycol Intake Solenoid Valve
const int relay4 = 9; // VCC Pin attached to Digital Pin 10, Water Intake Solenoid Valve
const int relay5 = 10; // VCC Pin attached to Digital Pin 9, Glycol Output Solenoid Valve
const int relay6 = 23; // VCC Pin attached to Digital Pin 8, Water Output Solenoid Valve
const int relay7 = 25; // VCC Pin attached to Digital Pin 7, Electric Motor Agitator
const int relay8 = 27; //VCC Pin attached to Digital Pin 6, Mixed Output Solenoid Valve
const int Last_Valve = 53; // Arduino pin 4 connected to button's pin
const int e_stop = 52; // pushbutton connected to pin 1 of aurdino board
const int emergency_LED = 51;
int lastButtonState = 0; // for estop
int last_Button_State_1 = 1; // for pushbutton connected to realy 8
int buttonState = 0; // for estop
int button_State_1 = 0; // for pushbutton connected to realy 8
const int motor_button = 50;
int motor_button_state = 0;
boolean isPressed = true;
int Glyclol_max_sensor = 0;
int Glyclol_min_sensor = 1;
int Water_max_sensor = 14;
int Water_min_sensor = 15;
int counter;
void setup() {
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(Last_Valve, INPUT); // set arduino pin to input mode
pinMode(relay8, OUTPUT);
pinMode(e_stop, INPUT); // set arduino pin to input mode
pinMode(emergency_LED, OUTPUT); // set arduino pin to input mode
pinMode(Glyclol_max_sensor, OUTPUT);
pinMode(Glyclol_min_sensor, OUTPUT);
pinMode(Water_max_sensor, OUTPUT);
pinMode(Water_min_sensor, OUTPUT);
Serial.begin(115200);
}
void loop()
{
power_on();
buttonState = digitalRead(e_stop); // read new state of estop pushbutton
if (buttonState == LOW)
{
digitalWrite(emergency_LED, LOW);
Serial.println("emergency stop button is not pressed");
Serial.println("\n");
switch (counter)
{
case 0: { startup();
counter = 1;
delay(100);
break;}
case 1: { Intake_Valve();
counter = 2;
delay(100);
break;}
case 2: { Output_Valve();
counter = 3;
delay(100);
break;}
case 3: { Electric_Motor();
counter = 4;
delay(100);
break;}
case 4: { Last_Output_Valve();
counter = 0;
delay(100);
break;}
}
/* startup();
delay(100);
Intake_Valve();
delay(100);
Output_Valve();
delay(100);
Electric_Motor();
delay(100);
Last_Output_Valve();
delay(100);
exit (0);*/
}
if(buttonState == HIGH)
{
lcd.clear();
lcd.print("Emergency");
lcd.setCursor(0, 1);
lcd.print("Button Pressed");
counter = 0;
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8, LOW);
//buttonState = LOW;
button_State_1 = LOW;
delay(100);
//exit (0);
}
}
void power_on()
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8, LOW);
buttonState = LOW;
button_State_1 = LOW;
}
void startup()
{
digitalWrite(emergency_LED, LOW);
lcd.clear();
lcd.print("Starting UP");
delay(1000);
lcd.clear();
delay(100);
digitalWrite(relay1, HIGH); // Turn the relay1/ motor1 ON
digitalWrite(relay2, HIGH); // Turn the relay2/ motor1 ON
lcd.print("Glycol Pump ");
lcd.setCursor(0, 1); // display the second word in the next row
lcd.print("ON");
delay(1000);
lcd.clear();
delay(100);
lcd.print("Water Pump ");
lcd.setCursor(0, 1); // display the second word in the next row
lcd.print("ON");
delay(1000);
lcd.clear();
delay(100);
}
void Intake_Valve()
{
digitalWrite(relay1, LOW); // Turn the relay1 Off
digitalWrite(relay2, LOW); // Turn the relay2 Off
lcd.print("Glycol Pump ");
lcd.setCursor(0, 1); // display the second word in the next row
lcd.print("OFF");
delay(1000);
lcd.clear();
delay(100);
lcd.print("Water Pump ");
lcd.setCursor(0, 1); // display the second word in the next row
lcd.print("OFF");
delay(1000);
lcd.clear();
delay(100);
digitalWrite(relay3, HIGH); // Turn the relay3 ON
digitalWrite(relay4, HIGH); // Turn the relay4 ON
lcd.print("Glycol Intake");
lcd.setCursor(0, 1);
lcd.print("Valve ON");
delay(1000);
lcd.clear();
delay(100);
lcd.print("Water Intake");
lcd.setCursor(0, 1);
lcd.print("Valve ON");
delay(1000);
lcd.clear();
delay(100);
}
void Output_Valve()
{
digitalWrite(relay3, LOW); // Turn the relay3 Off
digitalWrite(relay4, LOW); // Turn the relay4 Off
lcd.print("Glycol Intake");
lcd.setCursor(0, 1);
lcd.print("Valve OFF");
delay(1000);
lcd.clear();
delay(100);
lcd.print("Water Intake");
lcd.setCursor(0, 1);
lcd.print("Valve OFF");
delay(1000);
lcd.clear();
delay(100);
digitalWrite(relay5, HIGH); // Turn the relay5 ON
digitalWrite(relay6, HIGH); // Turn the relay6 ON
lcd.print("Glycol Output");
lcd.setCursor(0, 1);
lcd.print("Valve ON");
delay(1000);
lcd.clear();
delay(100);
lcd.print("Water Output");
lcd.setCursor(0, 1);
lcd.print("Valve ON");
delay(1000);
lcd.clear();
delay(100);
}
void Electric_Motor()
{
digitalWrite(relay5, LOW); // Turn the relay5 Off
digitalWrite(relay6, LOW); // Turn the relay6 Off
lcd.print("Glycol Output");
lcd.setCursor(0, 1);
lcd.print("Valve OFF");
delay(100);
lcd.clear();
delay(100);
lcd.print("Water Output");
lcd.setCursor(0, 1);
lcd.print("Valve OFF");
delay(100);
lcd.clear();
delay(1000);
motor_button_state = digitalRead (motor_button);
if(motor_button_state == HIGH)
{
digitalWrite(relay7, HIGH); // Turn the relay7 ON
Serial.println("Electric Motor ON");
Serial.println("\n");
lcd.print("Electric Motor");
lcd.setCursor(0, 1);
lcd.print("Agitator ON");
delay(100);
lcd.clear();
delay(100);
}
if(motor_button_state == LOW)
{
digitalWrite(relay7, LOW); // Turn the relay7 Off
Serial.println("Electric Motor OFF");
Serial.println("\n");
lcd.print("Electric Motor");
lcd.setCursor(0, 1);
lcd.print("Agitator OFF");
delay(100);
lcd.clear();
delay(100);
}
lcd.print("Wheel Probe");
lcd.setCursor(0, 1);
lcd.print("Fluid is Ready");
delay(100);
lcd.clear();
delay(100);
lcd.print("Would you like");
lcd.setCursor(0, 1);
lcd.print("to proceed?");
delay(100);;
lcd.clear();
delay(100);
}
void Last_Output_Valve()
{
button_State_1 = digitalRead(Last_Valve); // read new state of pushbutton connected to realy 8
if (button_State_1 != last_Button_State_1)
{
if (button_State_1 == HIGH) {
digitalWrite(relay8, HIGH);
lcd.print("Mix Output");
lcd.setCursor(0, 1);
lcd.print("Valve ON");
delay(100);
lcd.clear();
delay(100);
lcd.print("Operation");
lcd.setCursor(0, 1);
lcd.print("Done");
}
if (button_State_1 == LOW)
{
digitalWrite(relay8, LOW);
lcd.print("Mix Output");
lcd.setCursor(0, 1);
lcd.print("Valve is OFF");
delay(100);
}
}
}