Sie sind auf Seite 1von 5

Search the Arduino Website

TUTORIALS (/EN/TUTORIAL/HOMEPAGE) > Examples from Libraries (/en/Tutorial/LibraryExamples) > Stepper > MotorKnob

Stepper Motor Knob


Stepper motors, due to their unique design, can be controlled to a high degree of accuracy without any feedback mechanisms. The
shaft of a stepper, mounted with a series of magnets, is controlled by a series of electromagnetic coils that are charged positively and
negatively in a specic sequence, precisely moving it forward or backward in small "steps".
There are two types of steppers, Unipolars and Bipolars, and it is very important to know which type you are working with. For each of
the motors, there is a different circuit. The example code will control both kinds of motors. See the unipolar
(//www.arduino.cc/en/Reference/StepperUnipolarCircuit) and bipolar (//www.arduino.cc/en/Reference/StepperBipolarCircuit) motor
schematics for information on how to wire up your motor.
In this example, a potentiometer (or other sensor) on analog input 0 is used to control the movement of a stepper motor using the
Arduino Stepper Library (//www.arduino.cc/en/Reference/Stepper). The stepper is controlled by with digital pins 8, 9, 10, and 11 for
either unipolar or bipolar motors.
The Arduino or Genuino board will connect to a U2004 Darlington Array (http://octopart.com/uln2004a-stmicroelectronics-4798) if
you're using a unipolar stepper or a SN754410NE H-Bridge (http://octopart.com/sn754410ne-texas+instruments-1320) if you have a
bipolar motor.

For more information about the differences of the two types, please take a look at Tom Igoe's page on stepper motors
(http://www.tigoe.net/pcomp/code/circuits/motors/stepper-motors).

Hardware Required
-

Arduino or Genuino Board

10k ohm potentiometer

stepper motor

U2004 Darlington Array (if using a unipolar stepper)

SN754410ne H-Bridge (if using a bipolar stepper)

power supply appropriate for your particular stepper

hook-up wires

breadboard

Circuits
Below you'll nd circuits for both unipolar and bipolar steppers. In either case, it is best to power your stepper motors from an external
supply, as they draw too much to be powered directly from your Arduino board.
In both circuits, connect a 10k pot to power and ground, with it's wiper outputting to analog pin 0.

Note: Both circuits below are four wire congurations. Two wire congurations will not work with the code provided.
Unipolar Stepper Circuit and schematic

Bipolar Stepper Circuit and schematic

Code
For both unipolar and bipolar steppers
/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/
#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
Stepper stepper(STEPS, 8, 9, 10, 11);
// the previous reading from the analog input
int previous = 0;
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}
void loop() {
// get the sensor value
int val = 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;
}
[GetCode](//www.arduino.cc/en/Tutorial/MotorKnob?action=sourceblock&num=1)

See also
-

Stepper myStepper = Stepper (//www.arduino.cc/en/Reference/StepperConstructor)(steps, pin1, pin2, pin3, pin4)

stepper.setSpeed (//www.arduino.cc/en/Reference/StepperSetSpeed)()

stepper.step (//www.arduino.cc/en/Reference/StepperStep)()

Stepper library reference (//www.arduino.cc/en/Reference/Stepper)

StepperOneRevolution (//www.arduino.cc/en/Tutorial/StepperOneRevolution) - Turn the shaft one revolution clockwise and one
counterclockwise.

StepperOneStepAtATime (//www.arduino.cc/en/Tutorial/StepperOneStepAtATime) - Single stepping to check the proper wiring of


the motor.

StepperSpeedControl (//www.arduino.cc/en/Tutorial/StepperSpeedControl) - The stepping speed is controlled by a


potentiometer.

Last revision 2015/08/18 by SM

Share

NEWSLETTER

Enter your email to sign up

2016 Arduino

Copyright Notice (//www.arduino.cc/en/Main/CopyrightNotice)

About us (//www.arduino.cc/en/Main/AboutUs)

(https://twitter.com/arduino)

Contact us (//www.arduino.cc/en/Main/ContactUs)

Careers (//www.arduino.cc/Careers)

(https://www.facebook.com/ocial.arduino)

(https://www.ickr.com/photos/arduino_cc)

(https://youtube.com/arduinoteam)

(https://plus.google.com/+Arduino)