Introduction: Controlling a Stepper Motor

This tutorial is valid both if we use the Arduino and both using the Drivemall Board
below the link to build the Drivemall.

The advantage of prefering the Drivemall over the classic Arduino board is that of reducing the complexity of the connections leading to a more tidy setup. However, this is optional: all the results are still valid with the arduino board, a breadboard and enough dupont jumpers for connections.

Let's control a stepper motor with an arduino board.

Step 1: What We Need

- Arduino microcontroller or Drivemall

- Wire(s)

- Stepper Motor

- A Driver A4988 or DRV8825 or L298N or ULN2003 (There are a lot of driver for)

Step 2: How a Stepper Motor Works and Why We Use a Driver

A stepper motor essentially consists of two coils which must be suitably powered ( picture 1), if the motor is fed in wrong motion it can cause a short to GND.

At each step the engine turns at a well-known angle which is usually indicated by the manufacturer as 1.8 °, so 200 steps are required to make a full circle

Let's clarify why we need a driver instead of connecting the stepper directly to the microcontroller.

The drivers allow you to scan the steps because a microcontroller is unable to load the coils inside the stepper motor.

There are two types of drivers for stepper motors on the market:

  • classic drivers L298 or ULN2003 a double H-bridge in which the logic to power the single phases resides in the code;

  • Modern drivers A4988 or drv8825 where some of the logic resides in the drive.

The A4988 to function in input provides an enable and two pins, one for the direction and the other for the number of steps,as well as power supply.

Step 3: Connections

As a first approach to stepper motors we have chosen to use the driver ULN2003.

Three buttons for engine control are connected to the Arduino with a resistor connected to GND.

We connect the motor to the ULN according to the scheme in figure 2, The Arduino is connected to the driver with pins 8 9 10 and 11.

Step 4: Firmware and Controlling

Here you find a basic firmware for controlling the stepper motor. In this special case
The bottom on

  • pin A0 is used for positive direction and stop
  • pin A1 is used for negative direction and stop
  • pin A2 is used to confirm and set it in motion according to the direction of the button previously presse

the number of steps per cycle is set to 20 this means that the program will perform 10 cycles to make one complete revolution of the motor

Step 5: Disclaim

This tutorial has been produced as part of the Makerspace for Inclusion project, co-financed by the Erasmus + Programme of the European commission.

The project aims to promote an informal form of education as a means to foster the social inclusion of young people, informal education as can be found within makerspaces.

This tutorial reflects the views only of the authors, and the European Commission cannot be held responsible for any use which may be made of the information contained therein.