Stepper motor wont spin

I apologize if my questions are basic knowledge , I am new to Arduino Projects.
I am making a college project , the stepper motor wont spin despite using the simple "clockwise and counter clockwise" rotate code. I triple checked the connections.
The parts in use are : Arduino Nano , A4988 , NEMA 17 motor , 12V power supply
Any tips are much appreciated.
Again I apologize for the shabby connections.
This is my connection :


Got the code from GPT (mine wasn't working either)

// Include the required libraries
#include <AccelStepper.h>

// Define the motor connections
#define STEP_PIN 2
#define DIR_PIN 3

// Create an instance of the AccelStepper class
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

void setup() {
  // Set the maximum speed and acceleration for the stepper motor
  stepper.setMaxSpeed(1000.0);
  stepper.setAcceleration(500.0);
  
  // Set the motor to run in the clockwise direction
  stepper.setSpeed(1000);
}

void loop() {
  // Rotate one full revolution clockwise
  stepper.move(200 * 16); // 200 steps per revolution (1.8 degrees per step), multiplied by 16 microsteps
  
  // Run the motor until it reaches the target position
  while (stepper.distanceToGo() != 0) {
    stepper.run();
  }
  
  delay(1000); // Wait for 1 second
  
  // Rotate one full revolution counterclockwise
  stepper.move(-200 * 16); // Negative value for counterclockwise rotation
  
  // Run the motor until it reaches the target position
  while (stepper.distanceToGo() != 0) {
    stepper.run();
  }
  
  delay(1000); // Wait for 1 second
}

Arduino GND not connected

Hello @legend_cat - The best place to find example sketches for every device is to look in the devices' "repository"... for example, you are using "AccelStepper.h"... and when you downloaded the library, you also downloaded an "examples" folder (this is a link to the on-line repository) where you will find an "examples" folder with at least one sketch written by the author of the library.

Bad idea. You have to set the current limit appropriately on the A4988, which requires you to know the value of the current sense resistors on the A4988 driver board. And, you need an adequate motor power supply, as well as know that breadboards are not designed for motor currents -- it might work for a short while, but the tracks tend to burn out.

Pololu offers good advice for their A4988 boards (yours may not have the same sense resistors), and they produced a good video on setting the current limit.

The A4988 driver requires a minimum of 8V for the stepper motor power supply. That means an external supply. The driver will not work with 5V to Vmot.

Chinese clone A4988 drivers usually have 0.1 Ohm sense resistors, marked R100 or R10. Verify the value on your A4988 modules.

Instructions for setting coil current on various stepper drivers including A4988.

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