A stepper motor follows the turns of a potentiometer (or other sensor) on Analog input 0. The unipolar or bipolar stepper is controlled with pins 8, 9, 10, and 11, using one of the circuits on the linked pages.
#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 toStepper stepper(STEPS, 8, 9, 10, 11);// the previous reading from the Analog inputint previous = 0;void setup(){// set the speed of the motor to 30 RPMsstepper.setSpeed(30);}void loop(){// get the sensor valueint val = AnalogRead(0);// move a number of steps equal to the change in the// sensor readingstepper.step(val - previous);// remember the previous value of the sensorprevious = val;}Reference Home
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.