washing machine ( controlled motor in 2 direction + LCD display) need help code

the washing machine should have 2 modes. 1st is washing mode , 2nd is drying mode. so it should have 2 push buttons one for each mode.
washing mode: motor should rotate clock wise for 2 second then rotate anticlockwise for another 2 seconds with 50% of the full speed with total time 1 minute.
drying mode: motor should rotate contentiously in only one direction ( clockwise) with high speed with total time also 1 minute.
lcd should display at the beginning that that project has 2 mode. then when a mode is selected it should display the running mode and after the minute passed ( end of the operation) it should display the the operation ended successfully. then re-display the 2 available modes as the beginning and loop again.

I've deleted your other cross post @shadyyyelmasryyy.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

shadyyyelmasryyy:
the washing machine should have 2 modes. 1st is washing mode , 2nd is drying mode. so it should have 2 push buttons one for each mode.
washing mode: motor should rotate clock wise for 2 second then rotate anticlockwise for another 2 seconds with 50% of the full speed with total time 1 minute.
drying mode: motor should rotate contentiously in only one direction ( clockwise) with high speed with total time also 1 minute.
lcd should display at the beginning that that project has 2 mode. then when a mode is selected it should display the running mode and after the minute passed ( end of the operation) it should display the the operation ended successfully. then re-display the 2 available modes as the beginning and loop again.

Welcome to the Arduino forum. This looks kind if like a class assignment. Is it?

Do you have all the components to make this project? What about powering the project? Do you have any parameters for this?

Paul

The code below should get you started, but note the following:

  • There are actually 3 states not 2: it needs an idle state where it waits for a button
  • It doesn't use an LCD: everything is to the monitor
  • You didn't specify how you intend to drive the motors: I just used 2 pins for leds off and on to simulate direction. That may or not be how you will reverse the direction with whatever driver you use. POWERING AND DRIVING THE MOTORS IS YOUR BABY
  • I had to use very low PWM values to make my leds go dim to mimic half speed; you will need to experiment with the values if you use PWM
  • Times are shortened for testing: check the variables and put the real values in
  • The built in led pulses delay()-lessly to prove there's no blocking going on
  • Wire the buttons from the pins to ground; internal pullups are enabled
//  washing machine https://forum.arduino.cc/index.php?topic=648782.0
// has bwod pulse on L13

//states
enum {ST_idle, ST_wash, ST_dry} currentState = ST_idle;
bool newlyArrivedInThisState = true;
unsigned long arrivedInThisStateAt;
int washCycleLength = 5000; //short times for testing
int dryCycleLength = 5000; //short times for testing
//
byte reverseState = 0;
int reverseInterval = 250; //short times for testing
unsigned long previousReverse;

//the pulse led
int pulseLedInterval = 500;
unsigned long previousMillisPulse;
bool pulseState = false;

//buttons
const byte washPin = 2;
const byte dryPin = 3;

//direction leds (need to be pwm for speed control)
const byte clockwiseLed = 9;
const byte antiClockwiseLed = 10;

void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  Serial.println("setup() ... ");
  Serial.println(".... washing machine ....");
  Serial.print("Compiler: ");
  Serial.print(__VERSION__);
  Serial.print(", Arduino IDE: ");
  Serial.println(ARDUINO);
  Serial.print("Created: ");
  Serial.print(__TIME__);
  Serial.print(", ");
  Serial.println(__DATE__);
  Serial.println(__FILE__);

  //initialise pulse led
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, pulseState);

  //buttons
  pinMode(washPin, INPUT_PULLUP);
  pinMode(dryPin, INPUT_PULLUP);

  Serial.println("setup() done");
  Serial.println(" ");
}

void loop()
{
  doPulse();
  manageStates();
} //loop

void manageStates()
{
  switch (currentState)
  {
    case ST_idle:
      if (newlyArrivedInThisState)
      {
        Serial.println("Machine is idle");
        Serial.println("Press the Wash or Dry button");
        newlyArrivedInThisState = false;
        digitalWrite(clockwiseLed, LOW);
        digitalWrite(antiClockwiseLed, LOW);
      }

      if (!digitalRead(washPin))
      {
        newlyArrivedInThisState = true;
        Serial.println("  Starting **wash** cycle");
        currentState = ST_wash;
      }

      if (!digitalRead(dryPin))
      {
        newlyArrivedInThisState = true;
        Serial.println("  Starting **dry** cycle");
        currentState = ST_dry;
      }
      break;

    case ST_wash:
      if (newlyArrivedInThisState)
      {
        arrivedInThisStateAt = millis();
        Serial.print("  Wash cycle started");
        newlyArrivedInThisState = false;
      }

      if (millis() - previousReverse >= reverseInterval)
      {
        previousReverse = millis();
        if (reverseState)
        {
          analogWrite(clockwiseLed, 10); //set to correct value for half speed
          analogWrite(antiClockwiseLed, 0);
        }
        else
        {
          analogWrite(clockwiseLed, 0);
          analogWrite(antiClockwiseLed, 10); //set to correct value for half speed
        }
        reverseState = !reverseState;
      }

      if (millis() - arrivedInThisStateAt >= washCycleLength)
      {
        newlyArrivedInThisState = true;
        Serial.println("... finished; returning to idle");
        currentState = ST_idle;
      }

      break;

    case ST_dry:
      if (newlyArrivedInThisState)
      {
        arrivedInThisStateAt = millis();
        Serial.print("  Dry cycle started");
        newlyArrivedInThisState = false;
        digitalWrite(clockwiseLed, HIGH);
        digitalWrite(antiClockwiseLed, LOW);
      }

      if (millis() - arrivedInThisStateAt >= dryCycleLength)
      {
        newlyArrivedInThisState = true;
        Serial.println("... finished; returning to idle");
        currentState = ST_idle;
      }

      break;

  }//switch
}//manageStates

void doPulse()
{
  if (millis() - previousMillisPulse >= pulseLedInterval)
  {
    previousMillisPulse = millis();
    pulseState = !pulseState;
    digitalWrite(LED_BUILTIN, pulseState);
  }
} //doPulse

Is this for a real washing machine btw? I'd expect to see more than just the need to control a single motor: valves, pumps, heaters...

shadyyyelmasryyy:
they just need the code ....

Well the code I gave should get them started, as I said.

waching machine with 3 modes , first mode washing contains 3 programs in which the total time and water temp to be set like program 1 will be 30 sec and 30 C program 2 will be 30 sec and 50 C program 3 will be set manually using keypad
second mode is washing and spinning in which total time and water temp and spinning time will be set like program 1 will be 30 sec and 30 C and spinning time=15 sec program 2 will be 30 sec and 50 C and spinning time=25 sec program 3 will be set manually using keypad
last mode is spinning in which spinning time will be set like program 1 will be 30 sec progrm 2 will be 50 sec program 3 set manually using keypad
so i will be using 3 motors ( washing and spinnig motor will rotate in both direction)
(diffusion motor will rotate 1 direction and at 1 speed)
(water inlet water will rotate 1 direction and 1 speed)
at first mode and program must be chosen using keypad and then press start button
then running motor 3 for like 3 secs to check for water entering tank using current , flow and water sensor
then running motor 2 for like 3 secs to check for water leaving tank using current, flow and water sensor
iam using arduino uno ,LCD , keypad, temp sensor, heater ,3 motors, current sensor, flow sensor,water sensor

One mode more than your other thread?
Cross-posting is against forum rules.

We could help you fix YOUR code, but don't expect us to do your homework for you.
Start with the examples that come with the IDE.
Experiment with temp sensors and relays.
You soon will get the hang of it.
Leo..

Once again, I have had to deal with your cross-posting @shadyyyelmasryyy. I warned you last time that repeated cross-posting would result in a suspension of your account. So I'm giving you a 3 day ban from the forum. Upon your return, I hope you will comply with the forum rules.