This script operates 2 stepper motors using 2 potentiometers. playing with the values allows you to calibrate the sensitivity of the motors.
#include <Stepper.h>
#define STEPS 100 // no. of steps on motor
Stepper stepper(STEPS, 8, 9, 10, 11); // stepper, number of steps, pins
Stepper stepper1(STEPS, 4, 5, 6, 7);
int potval0 = 0; //incoming potentiometer values
int potval1 = 1;
int previous = 0;
int previous1 = 0;
int potmin = 1023;// pot minimum and maximum for re-mapping the values
int potmax = 0;
void setup()
{
// set the speed of the motor (RPMs)
stepper.setSpeed(50);
stepper1.setSpeed(50);
}
void loop()
{
// get the sensor value
potval0 = analogRead(0);
potval0 = map(potval0, potmin, potmax, 0, 100);//re-map sensor value to no. of steps
potval1 = analogRead(1);
potval1 = map(potval1, potmin, potmax, 0, 100);
int val = potval0;
int val1 = potval1;
stepper.step(val – previous); //number of steps sent to sensor
stepper1.step(val1 – previous1); // remember the previous value of the sensor
previous = val;
previous1 = val1;
}