Hey everyone
I'm working on a project that reads data from three switches and a selector and outputs based on the inputs to three relays controlling some valves and an LCD. The program worked correctly until all of the outputs to the relays (pins 6, 7, & 8 ) are set to "HIGH" at the same time using digitalWrite. During this case, the outputs to the relays alternate quickly opening and closing the valves at a fast pace until the switches are changed so that two out of the three outputs are "HIGH."
My question: is using 10 output pins causing those three pins to alternate incorrectly? The LCD isn't affected when pins 6, 7, & 8 are high. I am using a Uno from Radioshack. Should I upgrade to a board with more output pins? Or could it be the code? The code loaded to the Arduino is below (feel free to leave feedback if you see anything that can be cleaned up).
Thanks for the help in advance
Beal
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int analogPressurize = A0;
int analogDepressurize = A1;
int analogCycle = A2;
int analogClose = A3;
int analogTestDepressurize = A4;
int pressurizeVal = 0;
int depressurizeVal = 0;
int cycleVal = 0;
int closeVal = 0;
int testDepressurizeVal = 0;
byte pressurize = B0;
byte depressurize = B0;
byte cycle = B0;
byte closeValve = B0;
byte testDepressurize = B0;
int actuatorPin = 8;
int downstreamPin = 7;
int upstreamPin = 6;
int backLight = 13;
int totalCount = 0;
int count = 0;
void setup(){
lcd.begin(20,4);
showCount();
pinMode(actuatorPin,OUTPUT);
pinMode(downstreamPin,OUTPUT);
pinMode(upstreamPin,OUTPUT);
pinMode(backLight,OUTPUT);
digitalWrite(backLight, HIGH);
}
void loop(){
pressurizeVal = analogRead(analogPressurize);
depressurizeVal = analogRead(analogDepressurize);
cycleVal = analogRead(analogCycle);
closeVal = analogRead(analogClose);
testDepressurizeVal = analogRead(analogTestDepressurize);
if(pressurizeVal > 900) pressurize = B1;
else pressurize = B0;
if(depressurizeVal > 900) depressurize = B1;
else depressurize = B0;
if(cycleVal > 900) cycle = B1;
else cycle = B0;
if(closeVal > 900) closeValve = B1;
else closeValve = B0;
if(testDepressurizeVal > 900) testDepressurize = B1;
else testDepressurize = B0;
if(cycle == 1){
digitalWrite(actuatorPin, HIGH);
count = count + 1;
totalCount = totalCount + 1;
showCount();
delay(1500);
digitalWrite(actuatorPin,LOW);
delay(2500);
}
else count = 0;
if(closeValve == 1) digitalWrite(actuatorPin,HIGH);
else digitalWrite(actuatorPin,LOW);
if(pressurize == 1){
digitalWrite(upstreamPin, HIGH);
if(testDepressurize == 1){
digitalWrite(downstreamPin, LOW);}
else{
digitalWrite(downstreamPin, HIGH);}
}
else{
digitalWrite(upstreamPin, LOW);
digitalWrite(downstreamPin, LOW);}
}
void showCount(){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Count:");
lcd.setCursor(0,1);
lcd.print(count);
lcd.setCursor(0,2);
lcd.print("Total Count:");
lcd.setCursor(0,3);
lcd.print(totalCount);}