I need an Arduino Uno code, which is controlled by limit switches 2-2 1-1 dc mot

I need an Arduino Uno code, which is controlled by limit switches 2-2 1-1 dc motor. The engine will have to work back and forth. The dc motors receive their energy to a panel l298. The circuit is to simultaneously act both DC motor, but one possibility to stop briefly so that the other is not interrupted.

Show us what you have written so far (in code tags), and we'll try to help you. A schematic would be useful too.

I need an Arduino Uno code, which is controlled by limit switches 2-2 1-1 dc motor.

How much are you willing to pay?

AWOL: Show us what you have written so far (in code tags), and we'll try to help you. A schematic would be useful too.

const int LM1 =2,LM2 = 3,LM3 = 4,LM4 = 5; const int CW = 8,CCW = 9,CW2 = 10,CCW2 = 11;

void setup() { Serial.begin(9600); pinMode(LM1, INPUT); pinMode(LM2, INPUT); pinMode(LM3, INPUT); pinMode(LM4, INPUT); pinMode(CW, OUTPUT); pinMode(CCW, OUTPUT); pinMode(CW2, OUTPUT); pinMode(CCW2, OUTPUT); } void loop() { if(digitalRead(LM2) == LOW) { m1_oda(); }

if (digitalRead(LM1) == LOW) { m1_vissza(); } if(digitalRead(LM3) == LOW) { m2_oda(); } if (digitalRead(LM4) == LOW) { m2_vissza(); } }

void m1_oda( void) { digitalWrite(CW, LOW); digitalWrite(CCW, HIGH); } void m1_vissza( void) { digitalWrite(CCW, LOW); digitalWrite(CW, HIGH); } void m2_oda( void) { digitalWrite(CW2, LOW); digitalWrite(CCW2, HIGH); } void m2_vissza( void) { digitalWrite(CCW2, LOW); digitalWrite(CW2, HIGH); }

So, that (improperly posted) code does something. You expect it to do something. You haven't explain what either thing is.

The task is to stop the engine and the engine 2 can perform one cycle and then start the engine again, one after one cycle 1. Unfortunately, the delay () is not good to him.

Unfortunately, the delay () is not good to him.

Fortunately, there is not a delay() in the code. So, this statement is irrelevant.

PaulS: Fortunately, there is not a delay() in the code. So, this statement is irrelevant.

The downtime between two engines have tried to solve the delay l. Meanwhile, it turned out not to be practical.

Can you post a wiring diagram and explain the operation of your project in more detail?

Ok, you you have a pair of motors. Each motor can be moved clockwise and counter clockwise. You have limit switches. If a motor hits a limit switch, it should go the other direction. Maybe you'd like a short pause so as to give the motor time to stop.

The circuit is to simultaneously act both DC motor, but one possibility to stop briefly so that the other is not interrupted.

WAIT A MOMENT!

So far, your sketch just moves both motors back and fourth between their limit switches independently. I don't see any reason why it wouldn't work. Are you saying that you want the two motors to interact with each other somehow? For one of the motors to do something so that the other motor is "not interrupted"?

That, I don't understand. What do you want these motors to do, exactly?

The task is to stop the engine and the engine 2 can perform one cycle and then start the engine again, one after one cycle 1. Unfortunately, the delay () is not good to him.

Oh, ok. So it is motor 1 - forward, back; then motor 2 - forward, back.

const int LM1 = 2, LM2 = 3, LM3 = 4, LM4 = 5;
const int CW = 8, CCW = 9, CW2 = 10, CCW2 = 11;

enum State {
  oda1, vissza1, oda2, vissza2
} state;

void setup()
{
  Serial.begin(9600);
  pinMode(LM1, INPUT);
  pinMode(LM2, INPUT);
  pinMode(LM3, INPUT);
  pinMode(LM4, INPUT);
  pinMode(CW, OUTPUT);
  pinMode(CCW, OUTPUT);
  pinMode(CW2, OUTPUT);
  pinMode(CCW2, OUTPUT);

  m1_oda(); // start the movement
  m2_stop();
  state = oda1;
}


void loop()
{
  switch (state) {
    case oda1:
      if (digitalRead(LM1) == LOW)
      {
        m1_vissza();
        state = vissza1;
      }
      break;
      
    case vissza1:
      if (digitalRead(LM2) == LOW) {
        m1_stop();
        m2_oda();
        state = oda2;
      }
      break;
      
    case oda2:
      if (digitalRead(LM4) == LOW)
      {
        m2_vissza();
        state = vissza2;
      }
      break;
      
    case vissza2:
      if (digitalRead(LM3) == LOW)
      {
        m2_stop();
        m1_oda();
        state = oda1;
      }
      break;
  }
}

void m1_stop( void)
{
  digitalWrite(CW, LOW);
  digitalWrite(CCW, LOW);
}
void m1_oda( void)
{
  digitalWrite(CW, LOW);
  digitalWrite(CCW, HIGH);
}
void m1_vissza( void)
{
  digitalWrite(CCW, LOW);
  digitalWrite(CW, HIGH);
}
void m2_stop( void)
{
  digitalWrite(CW2, LOW);
  digitalWrite(CCW2, LOW);
}
void m2_oda( void)
{
  digitalWrite(CW2, LOW);
  digitalWrite(CCW2, HIGH);
}
void m2_vissza( void)
{
  digitalWrite(CCW2, LOW);
  digitalWrite(CW2, HIGH);
}

m1_oda() → m1_vissza()–>m1_stop()---->m2_oda()->m2_vissza()->m2_stop()
újra előlről

PaulMurrayCbr:
Ok, you you have a pair of motors.
Each motor can be moved clockwise and counter clockwise.
You have limit switches. If a motor hits a limit switch, it should go the other direction. Maybe you’d like a short pause so as to give the motor time to stop.

WAIT A MOMENT!

So far, your sketch just moves both motors back and fourth between their limit switches independently. I don’t see any reason why it wouldn’t work. Are you saying that you want the two motors to interact with each other somehow? For one of the motors to do something so that the other motor is “not interrupted”?

That, I don’t understand. What do you want these motors to do, exactly?

Oh, ok. So it is motor 1 - forward, back; then motor 2 - forward, back.

const int LM1 = 2, LM2 = 3, LM3 = 4, LM4 = 5;

const int CW = 8, CCW = 9, CW2 = 10, CCW2 = 11;

enum State {
  oda1, vissza1, oda2, vissza2
} state;

void setup()
{
  Serial.begin(9600);
  pinMode(LM1, INPUT);
  pinMode(LM2, INPUT);
  pinMode(LM3, INPUT);
  pinMode(LM4, INPUT);
  pinMode(CW, OUTPUT);
  pinMode(CCW, OUTPUT);
  pinMode(CW2, OUTPUT);
  pinMode(CCW2, OUTPUT);

m1_oda(); // start the movement
  m2_stop();
  state = oda1;
}

void loop()
{
  switch (state) {
    case oda1:
      if (digitalRead(LM1) == LOW)
      {
        m1_vissza();
        state = vissza1;
      }
      break;
     
    case vissza1:
      if (digitalRead(LM2) == LOW) {
        m1_stop();
        m2_oda();
        state = oda2;
      }
      break;
     
    case oda2:
      if (digitalRead(LM4) == LOW)
      {
        m2_vissza();
        state = vissza2;
      }
      break;
     
    case vissza2:
      if (digitalRead(LM3) == LOW)
      {
        m2_stop();
        m1_oda();
        state = oda1;
      }
      break;
  }
}

void m1_stop( void)
{
  digitalWrite(CW, LOW);
  digitalWrite(CCW, LOW);
}
void m1_oda( void)
{
  digitalWrite(CW, LOW);
  digitalWrite(CCW, HIGH);
}
void m1_vissza( void)
{
  digitalWrite(CCW, LOW);
  digitalWrite(CW, HIGH);
}
void m2_stop( void)
{
  digitalWrite(CW2, LOW);
  digitalWrite(CCW2, LOW);
}
void m2_oda( void)
{
  digitalWrite(CW2, LOW);
  digitalWrite(CCW2, HIGH);
}
void m2_vissza( void)
{
  digitalWrite(CCW2, LOW);
  digitalWrite(CW2, HIGH);
}

horgez: m1_oda() --> m1_vissza()-->m1_stop()---->m2_oda()->m2_vissza()->m2_stop() újra előlről

If both the first exchange and good all. Thank you very much.

switch (state) { case oda1: if (digitalRead(LM2) == LOW) { m1_vissza(); state = vissza1; } break;

case vissza1: if (digitalRead(LM1) == LOW) { m1_stop(); m2_oda(); state = oda2; } break;