Washing machine

Hello guys,
I'm doing a project to automate a washing machine. The electrical part is done, I just have problems writing the right program. The timeline of the wasing machine in in the attachment. Check out the project on TINKERCAD under the link: Tinkercad | From mind to design in minutes. Thanks for your help.

Časovni potek.pdf (179 KB)

Most modern washing machines have many different possible wash cycles built-in, with their own microcontroller.

1/ Are you trying to build your own? - that's quite a job. Cheaper to buy one.

2/ Do you work for a firm designing washing machines ? - ask a colleague.

The main problems, I suspect, are with the various drivers, particularly the main motor which both needs to reverse and to be variable speed. Not trivial.

Allan

Majcen:
Hello guys,
I'm doing a project to automate a washing machine. The electrical part is done, I just have problems writing the right program. The timeline of the wasing machine in in the attachment. Check out the project on TINKERCAD under the link: https://www.tinkercad.com/things/dJAxJmEhHLO. Thanks for your help.

I see your timing diagram, can this be done by turning pins on and off then the action of each pin can be described as a series of time intervals between changing the pin for each pin.

Arduino time is kept in unsigned long variables, both the millis() and micros() functions return unsigned long. When we subtract a start time from and end time we always get the difference, when we subtract a start time from "now" we can compare how long that has been with a desired elapsed time and act IF the interval is over.

The pins have different numbers of on-off times, each pin will need an array of time intervals, an index and how many intervals for variables.

How far along with Arduino and/or C?

Do you want the machine to respond to user input at any time?

The Arduino is connected to a board with optocouplers. Three pins (4, 5 and 6) in the Arduino are used to controll these octocouplers, which give then 24V to the Siemens Sinamics V20 Inverter which then controls a three phase motor.

I know that everything in this program is build on multitasking, but I don't know how to do it correctly, especially because I have trouble understanding the millis() function and putting it to my program.

Majcen:
I know that everything in this program is build on multitasking, but I don't know how to do it correctly, especially because I have trouble understanding the millis() function and putting it to my program.

Have a look at the demo Several Things at a Time - all will be revealed. :slight_smile:

See also Planning and Implementing a Program

...R

Check this out:

It doesn't just teach how to time with Arduino, it teaches why.

Let's look at an analogy. Say you want to cook breakfast. You need to cook:

Coffee - takes 1 minute
Bacon - takes 2 minutes
Eggs - takes 3 minutes

Now a seasoned cook would NOT do this:

Put coffee on. Stare at watch until 1 minute has elapsed. Pour coffee.
Cook bacon. Stare at watch until 2 minutes have elapsed. Serve bacon.
Fry eggs. Stare at watch until 3 minutes have elapsed. Serve eggs.

The flaw in this is that whichever way you do it, something is going to be cooked too early (and get cold).

In computer terminology this is blocking. That is, you don't do anything else until the one task at hand is over.

What you are likely to do is this:

Start frying eggs. Look at watch and note the time.
Glance at watch from time to time. When one minute is up then ...
Start cooking bacon. Look at watch and note the time.
Glance at watch from time to time. When another minute is up then ...
Put coffee on. Look at watch and note the time.
When 3 minutes are up, everything is cooked. Serve it all up.

In computer terminology this is non-blocking. That is, keep doing other things while you wait for time to be up.

Something he doesn't say; cooking 1 at a time takes 6 minutes, cooking together takes 3.

And then he goes into the how of the code, the techniques of time on Arduino.

That is link 1 of the 3 in my signature space below. Part 2 has a section on State Machines. State machines let you break a job into steps and run each in turn, and more. You already know how to read pins so add timers and state machines, you have power in your toolbox. Think about learning C pointers in the near future, they're extremely useful.

digitalWrite(motor_levo,HIGH);
delay (7000);
digitalWrite(motor_levo,LOW);
delay (5000);
digitalWrite(motor_desno,HIGH);
delay (7000);
digitalWrite(motor_desno,LOW);
delay (5000);

How do i change this part by using millis ()?

Majcen:
How do i change this part by using millis ()?

Have you studied the link I gave you in Reply #4 ?

Also see Using millis() for timing. A beginners guide if you need more explanation.

...R

Write the code please so I will understand.

Majcen:
Write the code please so I will understand.

If you're too lazy to even read and try to understand a tutorial (including code examples that demonstrate the technique nicely) you won't get anywhere with your project. Especially as a washing machine's software is quite simple and straightforward, in contrast to the hardware (high power, high voltage, waterproofed motor and heater controls plus a good number of sensors).

Majcen:
Write the code please so I will understand.

I can do that for you. I accept Paypal.

Let's move this thread over to Gigs and Collaborations, where people who do not have the time, desire or ability pay other people to write code for them.

We can negotiate the amount of money you will pay.

OR, you can stay here. You can follow the suggestions being made here, read the sources provided and write some code. See how it works.
If you get stock, there are a lot of people who will help.

Majcen:
Write the code please so I will understand.

The code is in the tutorial I gave you the address to.

You learn that simple lesson and you will know how to do without delay(). It's right there already typed up, explanation and code.

DO IT FOR YOU means that you can't do it for yourself and part of the doing is learning what is reasonable or being taken for a dud.

unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long ONperiod = 1000;  //the value is a number of milliseconds
const unsigned long OFFperiod = 500;  //the value is a number of milliseconds
const byte ledPin = 13;    //using the built in LED

void setup()
{
  pinMode(ledPin, OUTPUT);
  startMillis = millis();  //initial start time
}

void loop()
{
  currentMillis = millis();  //get the current "time" (actually the number of milliseconds since the program started)
  digitalWrite(ledPin,HIGH);
  if (currentMillis - startMillis >= ONperiod)  //test whether the period has elapsed
  {
    digitalWrite(ledPin, !digitalRead(ledPin));  //if so, change the state of the LED.  Uses a neat trick to change the state
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
  if (currentMillis - startMillis >= OFFperiod)  //test whether the period has elapsed
  {
    digitalWrite(ledPin, !digitalRead(ledPin));  //if so, change the state of the LED.  Uses a neat trick to change the state
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
}

I want to start with the diode on HIGH potential, but then the program doesn't work. Help!

Majcen:
but then the program doesn't work. Help!

"Program doesn't work" does not provide any useful information from which to help you.

You need to tell us in as much detail as possible exactly what the program does and what you want it to do that is different.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R

Okay, thanks for the advice. So what I am trying to do is, that when te program strarts, I want that the LED is on and is then ON for T1, after that it toogles and is OFF for T2. Doing it with millis().

Majcen:
So what I am trying to do is, that when te program strarts, I want that the LED is on and is then ON for T1, after that it toogles and is OFF for T2. Doing it with millis().

And what does your program ACTUALLY do?

...R

The LED turns on and stays this way all the time.

Hi,
The timing diagram.


Tom... :slight_smile:

Hi,
Please note you do not go wash left then wash right..
You go wash left, stop, wash right, stop, wash left stop etc...

Tom... :slight_smile:

Yes I know Tom, did you look at my program on TINKERCAD? If not check it out and tell me, where am i doing it wrong. Thanks.