I am working on a project that was started by someone else who went out of business. My customer has a washer that opens multiple valves (electronically) and then closes them after a period of time. It seems there is no issue in opening the valves on call - but I can't quite figure out how to close them.
My sketch is:
int valvePins[] = {12,11,10,9,8,7,6,5};
int pinCount = 8; // Number of pins being used to relay controller
// Variables for cleaning method
int pushButton; // Delaring 1 pin as push button pin
const int rinsePeriod = 15000; // 15 Seconds
const int surgePush = 15000; // 15 Seconds
const int drainPeriod = 10000; // Drain Between Surges
const int waitBetweenPhases = 2000; // 2 Seconds
const int gas = 2000; // 5 Seconds
const int purge = 10000; // 10 Seconds
void setup() {
for (int i = 0; i < pinCount; i++) {
pinMode(valvePins[i], OUTPUT);
}
pushButton = 2;
pinMode(pushButton, INPUT_PULLUP);
}
void loop() {
// Check to see if button has been pressed
if(digitalRead(pushButton) == LOW)
{
// RINSE STAGE
phaseOne();
delay(waitBetweenPhases);
// CLEANING STAGE
for (int i=0; i < 2; i++) { // Runs stage 2 times
phaseTwo();
delay(waitBetweenPhases);
}
//RINSE STAGE (2nd Pass)
phaseOne();
// SANI STAGE
for (int i=0; i < 2; i++) { // Runs stage 2 times
phaseThree();
delay(waitBetweenPhases);
}
// GAS PURGE STAGE
phaseFour();
delay(waitBetweenPhases);
}
}
/*============================================================================================*/
void phaseOne() {
// Uses pins 5,6 & 12: PIN5[7], PIN6[6], PIN12[0]
digitalWrite(valvePins[0], HIGH);
digitalWrite(valvePins[5], HIGH);
digitalWrite(valvePins[6], HIGH);
digitalWrite(valvePins[7], HIGH); //PUMP
delay(rinsePeriod);
digitalWrite(valvePins[7], LOW); //PUMP
delay(drainPeriod);
digitalWrite(valvePins[0], LOW);
digitalWrite(valvePins[6], LOW);
digitalWrite(valvePins[5], LOW);
}
void phaseTwo() {
// Uses pins 5 & 7-9: PIN7[5] - CO2, PIN8[4] - BOTTOM CAUSTIC, PIN9[3] - TOP CAUSTIC
digitalWrite(valvePins[3], HIGH);
digitalWrite(valvePins[4], HIGH);
digitalWrite(valvePins[5], HIGH);
digitalWrite(valvePins[7], HIGH);
delay(surgePush);
digitalWrite(valvePins[7], LOW);
delay(drainPeriod);
digitalWrite(valvePins[3], LOW);
digitalWrite(valvePins[4], LOW);
digitalWrite(valvePins[5], LOW);
}
void phaseThree() {
// Uses pins 7,10, & 11: PIN7[5] - CO2, PIN10[2] - BOTTOM SANI, PIN11[1] - TOP SANI
digitalWrite(valvePins[1], HIGH);
digitalWrite(valvePins[2], HIGH);
digitalWrite(valvePins[5], HIGH);
digitalWrite(valvePins[7], HIGH);
delay(surgePush);
digitalWrite(valvePins[7], LOW);
delay(drainPeriod);
digitalWrite(valvePins[1], LOW);
digitalWrite(valvePins[2], LOW);
digitalWrite(valvePins[5], LOW);
}
void phaseFour() {
// Uses pin 7: PIN7[5] - CO2
digitalWrite(valvePins[5], HIGH);
delay(co2Purge);
digitalWrite(valvePins[5], LOW);
}
When I push the button the pins pull high and the process starts fine - the valves can be heard opening. I think from my understanding of these valves, changing the digitalWrite to LOW doesn't make them go the other way but simply tells the relay to stop with the HIGH. I am using 8 pins on the Arduino for control and 7 of them go to an 8 module relay to open the 7 valves. The other turns the pump on and off. Would I need to have the polarity from the relay to reverse the valves? Or can this be done with 1 wire controlling the switch from the code? I am not extremely new to Arduino, but controlling this many valves at one time is new for me.
I can add a drawing of my setup if needed.
Thanks for any push in the right direction! You guys on this forum rock.
