#include<Stepper.h>// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepperstepper(STEPS,8,9,10,11);// the previous reading from the analog input
intprevious=0;voidsetup(){// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);}voidloop(){// get the sensor value
intval=analogRead(0);// move a number of steps equal to the change in the
// sensor reading
stepper.step(val-previous);// remember the previous value of the sensor
previous=val;}
#include<Stepper.h>constintstepsPerRevolution=200;// change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
SteppermyStepper(stepsPerRevolution,8,9,10,11);voidsetup(){// set the speed at 60 rpm:
myStepper.setSpeed(60);// initialize the serial port:
Serial.begin(9600);}voidloop(){// step one revolution in one direction:
Serial.println("clockwise");myStepper.step(stepsPerRevolution);delay(500);// step one revolution in the other direction:
Serial.println("counterclockwise");myStepper.step(-stepsPerRevolution);delay(500);}
#include<Stepper.h>constintstepsPerRevolution=200;// change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
SteppermyStepper(stepsPerRevolution,8,9,10,11);intstepCount=0;// number of steps the motor has taken
voidsetup(){// initialize the serial port:
Serial.begin(9600);}voidloop(){// step one step:
myStepper.step(1);Serial.print("steps:");Serial.println(stepCount);stepCount++;delay(500);}
#include<Stepper.h>constintstepsPerRevolution=200;// change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
SteppermyStepper(stepsPerRevolution,8,9,10,11);intstepCount=0;// number of steps the motor has taken
voidsetup(){// nothing to do inside the setup
}voidloop(){// read the sensor value:
intsensorReading=analogRead(A0);// map it to a range from 0 to 100:
intmotorSpeed=map(sensorReading,0,1023,0,100);// set the motor speed:
if(motorSpeed>0){myStepper.setSpeed(motorSpeed);// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution/100);}}