Arduino WM Controller

Hello everybody!

I would like to use an Arduino as a washing machine controller. I have already written the procedure for the motor direction reversal, but I need, at the same time, to also run another procedure to heat up the water to a certain temperature. I currently don't have any problemas ith the two functions, but what can I do in order to actually heat the water while it's also tumbling? Here you can find my sketch:

#define sinistra 3 //left
#define destra 8 //right

byte flagstato = 0;
bool giraaDestra=false;//disable the motor from rotating right
const long lavoro = 5000; //working time for the motor
const long pausa = 3000; //pause time for the motor


unsigned long tempoCorrente = 0;//current time

void setup()
{
  pinMode(destra, OUTPUT);
  pinMode(sinistra, OUTPUT);
}

void loop()
{
  if (flagstato == 0)                           //if state equals 0 
  {
      if(giraaDestra==false)                    //and rotations to the right are not enabled
      {
        digitalWrite(sinistra, HIGH);           //rotate to the left
      }
      else
      {
        digitalWrite(destra, HIGH);             //if rotations to the right are enabled, turn right
      }
    if (millis() - tempoCorrente >= lavoro)     //if the working time is already over
    {
      if(giraaDestra==false)                    //and we have to turn off the motor 
      {
        digitalWrite(sinistra, LOW);            //if it was turning to the left, turn off left
       
      }
      else
      {
        digitalWrite(destra, LOW);              //else, turn off right
      }                
      flagstato = 1;                            //set state to 1
      tempoCorrente = millis();                 //reset time
    }
  }
  else if (flagstato == 1)                      //if state equals 1
  {
    if (millis() - tempoCorrente >= pausa)      //and pause time is already over
    {
      tempoCorrente = millis();                 //reset timer
      flagstato = 0;                            //set state to 0
      if(giraaDestra==false)                    //if the motor was previously turning to the right
      {
        giraaDestra=true;                       //enable giraaDestra to make it rotate to the right next time
      }
      else
      {
        giraaDestra=false;                      //if it was turning to the right, disable giraaDestra to make it rotate to the left
      }
    }
  }
}

Hope you'll be able to help me. Thanks in advance.

but what can I do in order to actually heat the water while it's also tumbling?

Put the code for tumbling in a function. Call it from loop().

What you have is, then:

void loop()
{
   tumble();
}

void tumble()
{
   // ALL of the code that was in loop()
}

Now, it should be easy to see how to make loop() heat() at the same time.

void loop()
{
   tumble();
   heat();
}

Since tumble() is not a blocking function, heat() will get equal opportunity. Just make sure that it is not a blocking function.

Hi, Washing machine, top loader or front loader?

Thanks.... Tom.. :)

The machine is a European front loader. Thanks for the code, but what if I wanted to start to heat the water after an amount of time X AND also tumble? Would this work?

const long currentTime=millis();
const long X=300000;//should be 5 minutes

void loop()
{
   tumble();
if(millis()-currentTime>=X)
{
   heat();
}
}

Would this work?

Yes, although I'd be inclined to determine, in the heat() function, whether it needed to actuallu do anything.

It has to turn on the heater, read an input fom the LM35, if the input is higher or equal to the set temperatura, turn off the heater.

Maybe you should draw a little diagram (eg a flow chart), that shows what you actually want to do. It makes it easier for us to help and for you to code.

lg, couka

It has to: -Tumble for 5 minutes in cold water -Tumble while heating -Tumble another 15 minutes once the water has been heated