create new tag
view all tags

Stepping Motor Exercises


A stepping motor is a device which is often used when a precise amount of movement is required: an exact angle of a an exact position on a linear scale. While DC motors move while they a powered a stepping motor requires a sequence of impulses to move step by step as its name suggests.

In this exercise we will learn how to program different step sequences for full step of half step movement and how to move the motor forward and backward.

This is a photo of the motor itself and its driver module featuring an ULN2803 driver chip.


Exercise 1: Make sure the connections are correct

The stepping motor is has 5 connections which are provided by the cable from the driver module to the motor itself. The 2 coils must be energized in the right order.


To do this we have 6 connections from the driver board to the Raspberry Pi:

  • 5V (check for 5V + and - on the board)

  • Gnd

  • 4 phases denominated In0..In3

If you want to be compatible with my solutions then you should hook up the phases as follows:
  • phase 1 on pin 27
  • phase 2 on pin 22
  • phase 3 on pin 18
  • phase 4 on pin 17

The state of each of the In lines is shown on its corresponding LED. We will have to provide a sequence of pulses

to make the motor move by 4 full steps. This is what we call single phase stepping where only 1 coil is energized at a time. In this case we have

We can also drive the motor by energizing both coils as follows:

This way of driving the motor is called double phase stepping. It needs more power since we always have both windings energized but it will also provide a higher torque.

Last not least we can use a combination of single and double phase stepping to produce half steps. In this case the angular resolution is better by a factor of 2. The polarization table looks like this: