Stepper Motor 1.1
Stepper Motor Library
Stepper motor control library

This library provides services to control unipolar and bipolar stepper motors through appropriate intermediate hardware drivers. It is intended for control of motors used in robotic applications running at modest step frequencies (ie up to low KHz rates).

Motion can be enabled in a polled mode for generic architectures or from an interrupt timer for AVR architectures, using either AVR timer 1 or 2 (selectable at compile time).

Motor Connections

The motor control interface is 4 digital output pins specified in the class constructor. These pins are connected to external motor control hardware to provide the appropriate H-bridge connections for control bipolar motors) or current switching (unipolar motors).

The pins are labeled in pairs A1, A2, B1, B2 for the 2 motor coils as shown in the figure below.

Using 28BYJ-48 with ULN2003 driver

The stepper motor is a unipolar stepper with coil wire pairs BLU/YLW, ORN/PNK and common RED. For the software the I/O pin wiring is INA1 to IND, INA2/INB, INB1/INC, and INB2/INA. This motor can be modified be a bipolar motor - https://ardufocus.com/howto/28byj-48-bipolar-hw-mod/ (verified works).

Important Notes

  • By enabling ENABLE_AUTORUN, this library is limited to AVR architectures and motor stepping functions will be invoked by a timer ISR, effectively driving the motor stepping more consistently and as a background process.
  • With ENABLE_AUTORUN enabled, this library uses AVR TIMER1 or TIMER2 to implement interrupt driven clock timing. TIMER0 is used by the Arduino millis() clock, TIMER1 is commonly used by the Servo library and TIMER2 by the Tone library. Change USE_TIMER (defined at the top of the header file) to select which timer is enabled in the library code.
  • This library has been tested on Arduino Uno and Nano (ie, 328P processor).
  • TIMERn is a global resource, so each concurrent class instance is driven from the same TIMERn interrupt. The constant MAX_INSTANCE is used to limit the global maximum for instances allowed to be processed by the same interrupt.
  • ISR_FREQUENCY is used to set the TIMERn ISR frequency. This affects the max number of steps/s to drive the motor. Higher frequency means more interrupts and less time to do other things (including other interrupts).

See Also