I need help with motors, arduino, and sensor. Could you help me?

Hello Everyone I'm new to arduino, but now I need to make a project, and unfortunately I don't understand how yet, so I'm asking for help on the forum.

The essence of the task:

  1. When the button is turned on, two stepper motors start spinning at the same speed and in the same direction (the button is pressed and released - that is, the arduino should wait for a signal from the button, but do not change it after the button is released)

  2. If something starts to pass through the sensor, then the first engine should turn off.

  3. After something has passed through the sensor, the second motor should turn off.

  4. That's the whole task :slight_smile:

  5. When the button is turned on again, the cycle should repeat.

At the same time, I have no idea how it would be more logical to connect the sensor, drivers, and stepper motors to the drivers, well, uh
and to the arduino.

What I am using:
microstep driver cw230
microstep driver dm556
arduino mega
DRA120-24A - DC power supplies
QMRD/0P-0F - Sensor
and two basic stepper motors

Sounds like a good place to use a State Machine:

enum States {Idle, BothRunning, OneRunning} State = Idle;

void loop()
{
  switch (State)
  {
  case Idle:
    if (digitalRead(ButtonPin) == HIGH)
      State = BothRuning;
    break;

  case BothRunning:
    digitalWrite(Stepper1StepPin, HIGH);
    digitalWrite(Stepper2StepPin, HIGH);
    digitalWrite(Stepper1StepPin, LOW);
    digitalWrite(Stepper2StepPin, LOW);
    delay(StepperRate);
    if (digitalRead(SensorPin) == HIGH)
      State = OneRuning;
    break;

  case OneRunning:
    digitalWrite(Stepper2StepPin, HIGH);
    digitalWrite(Stepper2StepPin, LOW);
    delay(StepperRate);
    if (digitalRead(SensorPin) == LOW)
      State = Idle;
    break;
  }
}
1 Like

Start by using an example code for buttons and make that work.
Then do the same for stepper motors and make one run.
Get hold of example code for the sensor and make that work.
Then You can start making two things run in the same code.
Add the remaining things, one at the time.

1 Like

Thank you for your responses. I'll try to implement them for now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.