// INCLUDES
#include <Stepper.h>
// CONSTANTS
const int SENSOR_PIN = A0;
const int MOTOR_PIN_1 = 9;
const int MOTOR_PIN_2 = 10;
const int MOTOR_PIN_3 = 11;
const int STEP_PIN = 12;
const int DIR_PIN = 7;
const int STEPS_PER_REVOLUTION = 800;
// VARIABLES
int sensorVal, motorSpeed;
Stepper myStepper = Stepper(STEPS_PER_REVOLUTION, STEP_PIN, DIR_PIN);
void setup() {
}
void loop() {
// read sensor value and set motor speed
sensorVal = analogRead(SENSOR_PIN);
motorSpeed = map(sensorVal, 0, 1023, 600, 0);
myStepper.setSpeed(motorSpeed);
// step the motor forwards at the set speed
myStepper.step(1);
}