// Define pin numbers for stepper motor control
const int Aplus = 8; // A+
const int Aminus = 9; // A-
const int Bplus = 10; // B+
const int Bminus = 11; // B-
// Step sequence for driving the stepper motor
int stepSequence[4][4] = {
{1, 0, 1, 0}, // Step 1: A+ and B+
{0, 1, 1, 0}, // Step 2: A- and B+
{0, 1, 0, 1}, // Step 3: A- and B-
{1, 0, 0, 1} // Step 4: A+ and B-
};
void setup() {
// Set motor control pins as outputs
pinMode(Aplus, OUTPUT);
pinMode(Aminus, OUTPUT);
pinMode(Bplus, OUTPUT);
pinMode(Bminus, OUTPUT);
}
void loop() {
// Complete a full rotation (200 steps for 1.8° step angle motor)
for (int i = 0; i < 200; i++) {
stepMotor(i % 4); // modulo to loop through the 4-step sequence
delay(10); // Adjust delay for speed control
}
delay(1000); // Pause before the next rotation
}
// Function to send signals to the stepper motor
void stepMotor(int step) {
digitalWrite(Aplus, stepSequence[step][0]);
digitalWrite(Aminus, stepSequence[step][1]);
digitalWrite(Bplus, stepSequence[step][2]);
digitalWrite(Bminus, stepSequence[step][3]);
}