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
}