water tank controller

dear all,
I have a problem with arduino. I never use Arduino before.
maybe some one can help me.

int RELE1 = 11; //osmosis pump
int RELE2 = 10; //return pump H2O
int GALLEG1 = 7; //floating button 1 osmosis
int GALLEG2 = 6; //floating button 2 osmosis
int GALLEG3 = 5; //floating button 3 over full main tank
int PULS1 = 4; //button for switch off the return pump H2O
int VAL1;
int VAL2;
int VAL3;
int VAL4;
int vec_VAL4;
int stato;

void setup() {
pinMode(GALLEG1, INPUT);
pinMode(GALLEG2, INPUT);
pinMode(GALLEG3, INPUT);
pinMode(PULS1, INPUT);
pinMode(RELE1, OUTPUT);
pinMode(RELE2, OUTPUT);

}

void loop(){
VAL1 = digitalRead(GALLEG1);
VAL2 = digitalRead(GALLEG2);
VAL3 = digitalRead(GALLEG3);
VAL4 = digitalRead(PULS1);

if ((VAL1==HIGH) && (VAL2 == HIGH)){
digitalWrite(RELE1, HIGH);
}
else{
digitalWrite(RELE1, LOW);
}
if (VAL3==LOW){
digitalWrite(RELE2, HIGH);
}
else{
digitalWrite(RELE2, LOW);
} //till here program work
//from here I have copy the program for switch off the returning pump
//It doesn't work. RELE2 never off
if ((VAL4 == HIGH) && (vec_VAL4 == LOW)) {
stato = 1 - stato;
}

vec_VAL4= VAL4;

if (stato == 1) {
digitalWrite(RELE2 , HIGH);
}
else {
digitalWrite(RELE2, LOW);
}
}

for a better understanding see the video here attached

awaiting your reply
ciao ciao

You have to explain you're problem.

Hi, just looking at your code quickly.
vec_VAL4 has no value until after it is tested in the if statement.
What is its initial value?
You may need to set it in setup.

Also post your code in # code tags and it will look better, also in the IDE select TOOLS then AutoFormat to set the layout up.

Tom...... :slight_smile:

//It doesn't work. RELE2 never off

How do you know? It may well be working, but if VAL3 is LOW, RELE2 will immediately be set high again.

Put some Serial.prints in there so you can see what's going on.

Please consider that switches (when used real contacts) bounce and therefore you probably have to debounce them.

dear all,
i wanna highlight that this is my first time with arduino and I'm not understanding what you saying. I'M STILL LEARNING...
after that, what I wanna do is very easy.
when I press the button named PULS1 the power on relay ''RELE2'' will be off until when I press again the same button, but at the same time regardless of the button (PULS1) if the button ''GALLEG3'' is excited the power on the relay ''RELE2'' will be immediately off until I takeoff my finger from the button.
can some one help me?
pleeeaseee

Up