Hello, people I am a DIY addict and an enthusiast (yet new or wanabee) programmer but never really worked with a code this hard. I thought that it will be easy but I think that I am using wrong condition sentences fot this case.
I own an old washer machine and I want to make a program for it to work with two buttons. It has two sensors the one that indicates if it is full or empty and the one that indicates if the cap is closed or open.
With one button I want it to wash (a sequence where it activates a valve until the pres sensor indicates that it is full, then start the washing sequence only if the cap is closed, when it finishes the wash and spin (empty) it turns on the valve again for the sequence of the rinse sequence and then, to finish turn un the buzzer alarm).
And the other button to spin the water out of it juts to dry the hand washed clothes.
My code works for the Bot1 part, but I think I am doing wrong the conditions for the second button Bot2.
Can anyone help me solve that?
const int Lavar = 2;
const int Exprimir = 3;
const int Valvula = 4;
const int Buzz = 5;
const int Relay = 6;
const int Tapa = 10;
const int Pres = 11;
const int Bot1 = 12;
const int Bot2 = 13;
int a = 0;
int b = 0;
int c = 0;
void setup()
{
pinMode(Lavar, OUTPUT); //I made an H brige. This pulse activates the washing mode
pinMode(Exprimir, OUTPUT); //This pulse activates the spin mode
pinMode(Valvula, OUTPUT); //This is the valve to fill the washer
pinMode(Relay, OUTPUT); //this one is to energize the motor (and H bridge)
pinMode(Buzz, OUTPUT); //This one is the buzzer
pinMode(Bot1, INPUT); //button 1
pinMode(Bot2, INPUT); //button 2
pinMode(Tapa, INPUT); //cap sensor
pinMode(Pres, INPUT); //full or empty sensor
}
void loop()
{
if (digitalRead(Bot1) == HIGH && a == 0)
{
a = 1;
digitalWrite(Buzz, LOW); //my relays turn on with LOW pulses
delay(50);
digitalWrite(Buzz, HIGH);
digitalWrite(Lavar, HIGH); //to wash or spin I must turn one mode on and the other one off
digitalWrite(Exprimir, LOW);
digitalWrite(Relay, LOW);
delay(4000);
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, HIGH);
digitalWrite(Relay, HIGH);
digitalWrite(Buzz, LOW);
delay(300);
digitalWrite(Buzz, HIGH);
a = 0;
}
else if ( digitalRead(Bot2) == HIGH && b == 0 && c == 0)
{
b = 1;
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, HIGH);
digitalWrite(Relay, HIGH);
digitalWrite(Buzz, LOW);
delay(150);
digitalWrite(Buzz, HIGH);
if (b == 1 && c == 0)
{
digitalWrite(Valvula, LOW);
c = 1;
if ( b == 1 && c == 1 && digitalRead(Pres) == HIGH)
{
c = 2;
if ( b == 1 && c == 2 && digitalRead(Tapa) == HIGH)
{
digitalWrite(Lavar, LOW);
digitalWrite(Exprimir, HIGH);
digitalWrite(Relay, LOW);
delay(4000);
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, HIGH);
digitalWrite(Relay, HIGH);
c = 3;
if ( b == 1 && c == 3)
{
digitalWrite(Valvula, LOW);
c = 4;
if ( b == 1 && c == 4 && digitalRead(Pres) == HIGH)
{
digitalWrite(Valvula, HIGH);
c = 5;
if ( b == 1 && c == 5 && digitalRead(Tapa) == HIGH)
{
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, LOW);
digitalWrite(Relay, LOW);
delay(4000);
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, HIGH);
digitalWrite(Relay, HIGH);
digitalWrite(Buzz, LOW);
delay(500);
digitalWrite(Buzz, HIGH);
b = 0;
c = 0;
}
}
}
}
}
}
}
else
{
a = 0;
b = 0;
c = 0;
digitalWrite(Lavar, HIGH);
digitalWrite(Exprimir, HIGH);
digitalWrite(Buzz, HIGH);
digitalWrite(Valvula, HIGH);
digitalWrite(Relay, HIGH);
}
}
Thanks a lot to anyone that reads this post and try to help.
I tried a lot but I might not know how to solve this one.
Also, sorry if I do a mistake posting this. It is my first time posting.