// Include the necessary library
#include <Stepper.h>
// Define the stepper motor connections
#define STEPS_PER_REV 200
#define DIR_PIN 5
#define STEP_PIN 2
// Create a Stepper object
Stepper stepper(STEPS_PER_REV, DIR_PIN, STEP_PIN);
// Define the potentiometer input pin
#define POT_PIN A0
void setup() {
// Set up the serial communication
Serial.begin(9600);
// Set the initial speed
stepper.setSpeed(500);
}
void loop() {
// Read the potentiometer value
int potValue = analogRead(POT_PIN);
// Map the potentiometer value to the speed range
float speed = map(potValue, 0, 1023, 0, 1000);
// Set the stepper motor speed
stepper.setSpeed(speed);
// Step the motor one step
stepper.step(1);
// Print the potentiometer value and stepper speed for debugging
Serial.print("Potentiometer: ");
Serial.print(potValue);
Serial.print(" Speed: ");
Serial.println(speed);
// You can add a delay if needed to control the loop rate
delay(10);
}