/* 218540787 KF KHANYA*/
const int DIR = 7; // Define the digital pin for controlling the direction of the motor.
const int STEP = 6; // Define the digital pin for sending step pulses to the motor.
const int steps_per_rev = 200; // Define the number of steps per revolution of the stepper motor.
void setup()
{
Serial.begin(115200); // Initialize serial communication for debugging purposes.
pinMode(STEP, OUTPUT); // Set the STEP pin as an output.
pinMode(DIR, OUTPUT); // Set the DIR pin as an output.
}
void loop()
{
// To control the direction of the motor (Clockwise)
digitalWrite(DIR, HIGH); // Set the DIR pin to HIGH to indicate clockwise rotation.
Serial.println("Spinning Clockwise...");
for(int i = 0; i < steps_per_rev; i++) // Iterate through steps for one full revolution.
{
digitalWrite(STEP, HIGH); // Set the STEP pin to HIGH.
delay(20); // Delay for controlling the speed of the motor (clockwise).
digitalWrite(STEP, LOW); // Set the STEP pin to LOW.
delay(20); // Delay to complete the step cycle.
}
// To control the direction of the motor (Anti-Clockwise)
digitalWrite(DIR, LOW); // Set the DIR pin to LOW to indicate counterclockwise (anti-clockwise) rotation.
Serial.println("Spinning Anti-Clockwise...");
for(int i = 0; i < steps_per_rev; i++) // Iterate through steps for one full revolution.
{
digitalWrite(STEP, HIGH); // Set the STEP pin to HIGH.
delay(10); // Delay for controlling the speed of the motor (anti-clockwise).
digitalWrite(STEP, LOW); // Set the STEP pin to LOW.
delay(10); // Delay to complete the step cycle.
}
delay(1000); // Delay for 1 second before repeating the loop to change the motor's rotation direction.
}