Understanding Stepper Motors

I’m trying to learn as much as I can about stepper motors. I’ve been reading tutorials and watching youtube videos and I’m just stuck. I’ve gotten to that tipping point where I know enough to be dangerous but not enough to understand. So before I let the smoke out of something or burn down my house I figured I would ask as many questions as I can get answered. I’m just trying to get the basics of moving a stepper motor left and right.

I’ve got an arduino mega running a xy-160d motor controller. I’m running 18v to the motor controller. I’m running this code:

const int IN1=5;
const int IN2=4;
const int ENA=6;
const int IN3=8;
const int IN4=7;
const int ENB=9;
void setup() {
 pinMode(IN1, OUTPUT);
 pinMode(IN2, OUTPUT);
 pinMode(ENA, OUTPUT);
 
 pinMode(IN4, OUTPUT);
 pinMode(IN3, OUTPUT);
 pinMode(ENB, OUTPUT);
}
void loop() {
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Forward(200);
Motor2_Forward(200);
delay(1000);
Motor1_Brake();
Motor2_Brake();
delay(100);
Motor1_Backward(200);
Motor2_Backward(200);
delay(1000);
}
void Motor1_Forward(int Speed)
{
 digitalWrite(IN1,HIGH);
 digitalWrite(IN2,LOW); 
 analogWrite(ENA,Speed);
}
 
void Motor1_Backward(int Speed)
{ 
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,HIGH); 
 analogWrite(ENA,Speed);
}
void Motor1_Brake() 
{
 digitalWrite(IN1,LOW);
 digitalWrite(IN2,LOW);
} 
void Motor2_Forward(int Speed)
{
 digitalWrite(IN3,HIGH);
 digitalWrite(IN4,LOW); 
 analogWrite(ENB,Speed);
}
 
void Motor2_Backward(int Speed)
{ 
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,HIGH); 
 analogWrite(ENB,Speed);
}
void Motor2_Brake()
{
 digitalWrite(IN3,LOW);
 digitalWrite(IN4,LOW);
}

I’ve got everything wired correctly and I can get the motor to buzz and vibrate. Of course the problem is I want to rotate it. The motors I’m using are 2BYJ-48 and PK244-02AA-C8.

I have also used this code:

/* Example sketch to control a stepper motor with L298N motor driver, Arduino UNO and Stepper.h library. More info: https://www.makerguides.com */ // Include the Stepper library:
include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
// Initialize the stepper library on pins 8 through 11:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {   // Set the motor speed (RPMs):
myStepper.setSpeed(100); }
void loop() {   // Step one revolution in one direction:
myStepper.step(stepsPerRevolution);    delay(2000);
// Step on revolution in the other direction:
myStepper.step(-stepsPerRevolution);    delay(2000); }

Both of them create the same situation with the motor.

What am I missing to get these motors to go through a full rotation?

Here is how it is wired. When trying either of the above programs I do edit the pins and I just copied the codes above off the websites I found them at. There are two wires missing from the photo because the second program is the one I was trying when I took the picture.

It sound like you might be running into power issues - are you supplying the motor driver separately? If not, try that (separate power for the MCU/driver)

Maybe take a couple photos of your setup and share them here as well

You should design a simulation in Proteus and then attach Logic Probes with signal pins of Stepper motor, and then make them HIGH one by one and the motor will start rotating, that’s the best way to understand stepper motor.