I'm new to arduino programming so I can't figure out few things so kindly help me to complete this project.
I have written the code by referring Aruduino tutorials and projects found in the internet. The algorithm works as follows.
(Fill>Wash>Drain>Dry)>(Fill>Rinse>Drain>Dry)>(Fill>Rinse>Drain>Dry)>(Fill>Rinse>Drain)>Spindry
The code I have written skips the "Fill" part in every cycle. First it checks for the water level sensor reading. If the reading is LOW, it starts to fill the tub until the sensor reading becomes HIGH. The water level sensor is the one that came with the washing machine.
As I have read it is nothing but a pressure actuated switch so I used a push button and a 100k resistor to replicate the sensor when testing the program.
It seems like the arduino does not wait for the sensor reading. It simply jumps to the wash phase.
Also I need the program to check for the door sensor and level sensor (these sensors are also similar to push buttons) in each phase.
Hers's the code.
#define waterInlet 5
#define drainValve 4
#define forMotor 3
#define revMotor 2
#define goButton A1
#define wlSensor 7
#define goLight 0
#define stopLight 1
#define stopButton A3
#define doorSensor A0
void setup () {
pinMode(waterInlet, OUTPUT);
pinMode(drainValve, OUTPUT);
pinMode(forMotor, OUTPUT);
pinMode(revMotor, OUTPUT);
pinMode(goButton, INPUT);
pinMode(stopButton, INPUT);
digitalWrite(stopButton, HIGH);
pinMode(wlSensor, INPUT_PULLUP);
pinMode(doorSensor, INPUT);
digitalWrite(doorSensor, HIGH);
pinMode(goLight, OUTPUT);
pinMode(stopLight, OUTPUT);
}
void fillItUp() {
if (digitalRead(wlSensor) == LOW)
{
digitalWrite(waterInlet, HIGH);
delay (1000);
}
else {
digitalWrite(waterInlet, LOW);
delay(1000);
}
}
void drainItOut() {
unsigned long drainTime = millis();
digitalWrite(drainValve, HIGH);
delay(500);
while ((millis() - drainTime) < 100000) { // Assuming that the water drains within 100 seconds.
delay(100);
}
digitalWrite(drainValve, LOW);
delay(100);
}
void washPhase() {
for (int i=0; i < 20; i++){
digitalWrite(forMotor, HIGH);
delay(5000);
digitalWrite(forMotor, LOW);
delay(1000);
digitalWrite(revMotor, HIGH);
delay(5000);
digitalWrite(revMotor, LOW);
delay(1000);
}
}
void ppreDry() {
digitalWrite(drainValve, HIGH);
delay(1000);
digitalWrite(forMotor, HIGH);
delay(5000);
digitalWrite(forMotor, LOW);
delay(2000);
digitalWrite(forMotor, HIGH);
delay(7000);
digitalWrite(forMotor, LOW);
delay(2000);
digitalWrite(forMotor, HIGH);
delay(10000);
digitalWrite(forMotor, LOW);
delay(2000);
}
void preDry() {
unsigned long dryTime = millis();
digitalWrite(forMotor, HIGH);
delay(500);
while ((millis() - dryTime) < 120000) { // pre dry for 120 seconds
delay(500);
}
digitalWrite(forMotor, LOW);
digitalWrite(drainValve, LOW);
delay(500);
}
void finalDry() {
unsigned long fdryTime = millis();
digitalWrite(forMotor, HIGH);
delay(500);
while ((millis() - fdryTime) < 300000) { // final dry for 300 seconds
delay(500);
}
digitalWrite(forMotor, LOW);
digitalWrite(drainValve, LOW);
delay(500);
}
void loop() {
// Go button was pressed, run through the cycles
digitalWrite(goLight, HIGH);
digitalWrite(stopLight, HIGH);
// Washing
fillItUp();
delay(1000);
washPhase();
delay(1000);
drainItOut();
delay(1000);
ppreDry();
delay(1000);
preDry();
delay(1000);
// Rinsing 1
fillItUp();
delay(1000);
washPhase();
delay(1000);
drainItOut();
delay(1000);
ppreDry();
delay(1000);
preDry();
delay(1000);
// Rinsing 2
fillItUp();
delay(1000);
washPhase();
delay(1000);
drainItOut();
delay(1000);
//Spin dry
ppreDry();
delay(1000);
preDry();
delay(1000);
finalDry();
digitalWrite(goLight, LOW);
digitalWrite(stopLight, HIGH);
}
Thanks in advance.