2 stepper motor control without using library

Hi, So the project I want to do is control 2 stepper motors to move in x and y axis without using arduino library.

I want to move my motor in x axis for 100 steps from left to right and at 100th step move my motor in y axis one step up and again move x axis motor from right to left (from 101 to 200) and repeat till 600 steps.

I'm not sure where to incorporate the y axis movement in the algorithm.
Sorry if this isn't enough information, I'm a beginner in Arduino challenging myself to learn as much as I can. Any help will be appreciated.
Also: I do not want to use any arduino library. The motor driver: l293d and stepper motor just a basic bipolar, I don't have any datasheet for it.

#define A        8                    
#define A_bar    9                    
#define B        10                     
#define B_bar    11                    
#define y        100                   

int xdir= 1;  //initial direction-->Forward
int xdir1;    //direction change variable-->Reverse
int count = 1; //Starting step

void setup() {
  Serial.begin(9600);
  // put your setup code here, to run once:
  pinMode(A, OUTPUT);
  pinMode(A_bar, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(B_bar, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  //finding end point
  
 if (count%100 == 0) {
  //change direction
  xdir1 = xdir*(-1);
  //y-axis move one step

    digitalWrite(A, HIGH);
    digitalWrite(A_bar, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(B_bar, LOW);
    delay (y);
    Serial.println(xdir1);
 }

  //direction control
for (count =1; count<=600;count++) 
if (xdir == 1)
{
    digitalWrite(A, HIGH);
    digitalWrite(A_bar, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(B_bar, LOW);
    delay (y);
    Serial.println(count);
    
}
 
if (xdir == -1)
   
  {
    digitalWrite(A, HIGH);
    digitalWrite(A_bar, LOW);
    digitalWrite(B, LOW);
    digitalWrite(B_bar, HIGH);
    delay (y);
    //Serial.println (count);
}
 count++;
 Serial.println (count);
 delay (1000);
}

I used this to check initially in the serial monitor. It prints from 1 to 600 but I'm not sure how to see that change in direction.
Any help would be appreciated. Thank you

found this link that pretty much provides a code(example 1) for the forward and reverse movement of a bipolar stepper motor using a L293d.
https://42bots.com/tutorials/bipolar-stepper-motor-control-with-arduino-and-an-h-bridge/

that's for 1 motor. simply duplicate that code changing the pin numbers to add a second one! :wink:
(tip: there are more sensible ways to code that though; it's a learning curve! :smiley: )

hope that helps...

It would be useful to know which stepper motors , some , like the car instrument type are harder to make work

rename loop() as a new sub-function with A, A_bar, B and B_bar as arguments, along with a dir and # of steps argument

not sure you're for loops are correct. they set the pins to the same values each iteration (where is A set LOW)

see stepper motor sequences

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