Arduino Projects

How to Interface Stepper Motor With Arduino Tutorial

In this tutorial, we will be exploring how to use a Stepper Motor With Arduino. In this project, we will be using an Arduino to control a stepper motor. We will go over the basic principles of how stepper motors work, how to connect a stepper motor to an Arduino, and how to write code to control a stepper motor. We’ll first create a simple sketch to move the motor one step at a time. Then, we’ll add a potentiometer to our circuit so that we can control the motor’s speed

A stepper motor is a brushless DC electric motor that converts electrical pulses into discrete mechanical movements. The motor’s position can then be controlled very precisely, without any feedback mechanism. Stepper motors are used in a variety of applications, including 3D printers, CNC mills and lathes, and robotics.

This project is a great introduction to using Arduino with motors. By the end of this project, you will be able to control a stepper motor with your Arduino!

You will need the following components to complete this project:

  • Arduino UNO
  • Stepper motor
  • Stepper motor driver
  • Jumper wires
  • Breadboard

First, let’s take a look at the stepper motor driver. This is the component that will actually control the stepper motor.

What is a Stepper motor?

Stepper Motor With Arduino 


A stepper motor is an electromechanical device which converts electrical pulses into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in discrete steps as electrical command pulses are applied to the motor winding coils. The size of the steps is determined by the motor design and is generally between five and thirty degrees. Stepper motors are used in a variety of applications where precise positioning is required such as 3D printers, CNC machines and scanners.

Specifications of Bipolar Stepper Motor:

  • Origin: China
  • Model: 42HD04
  • Low cost, small size
  • Bipolar
  • 4 lead wire
  • 1.8 deg/ step
  • Torque:
  • Size: 33mm x 42mm x 42mm
  • Voltage being applied and test: 6V to 12V

There are many different types of stepper motor drivers, but for this project, we will be using the A4988 driver. This driver has built-in current limiting and over-temperature protection, making it ideal for use with Arduino. Next, connect the Arduino to the driver. The A4988 driver has four input pins: two for power, one for ground, and one for the step signal.


Types of stepper motors

Stepper motors can be bipolar, requiring two power supplies or one polarity-switching power supply, or unipolar, requiring only one power supply. They are driven by a direct current source and require digital circuitry to create coil energizing orderings for motor rotation.

  • Bipolar.
  • Unipolar.

Bipolar and unipolar stepper motor diffrence

Bipolar Unipolar
It has a higher torque. It has less torque.
It is smaller in size. It is larger in size.
It is cheaper. It is less economical.
Its control is more complicated, it requires a card with power and spin control stages. Its control is simpler as it only requires a power supply circuit.
Greater anchorage due to the windings. Less anchor.

How does a Stepper Motor work?

A stepper motor consists of a rotor (the circular part that turns) and a stator (the stationary part that houses the electromagnets). The stator is made up of a series of electromagnets arranged around the rotor. When electricity is applied to the electromagnets, they create a magnetic field that interacts with the rotor to move it. The strength of the magnetic field, and therefore the amount of torque the motor can generate, is proportional to the amount of current flowing through the electromagnets. Stepper motors are controlled by sending electrical pulses to the electromagnets. The timing and sequence of the pulses determine the rotation speed and direction of the motor. By changing the pulse pattern, the motor can be made to rotate in very precise increments, or “steps.” That’s why stepper motors are often used in applications where precise positioning is required, such as printers and 3D printers.

A4988 motor driverStepper Motor With Arduino 

The A4988 is a popular stepper motor driver chip. It is used to control bipolar stepper motors in a wide range of applications. The A4988 provides two primary advantages over other stepper motor driver chips. First, it is very easy to use. The chip has all of the necessary circuitry to control a stepper motor, so all that is required is to connect the appropriate power and control signals. Second, the A4988 offers adjustable current limiting, which allows the user to control the amount of torque that the motor can produce.

For more information, you can check out the datasheet here. A4988 Datasheet

A4988 motor driver Pinout

The A4988 driver has a total of 16 pins that connect it to the outside world. The connections are as follows:


A4988 Pin Definition

Circuit Schematics Stepper Motor With Arduino and Connections

We will first need to connect the stepper motor to the Arduino. The connections are as follows:

Circuit Schematics Stepper Motor With Arduino and Connections

A4988 Connections

A4988 Connection
VMOT 8-35V
GND Motor ground
GND Logic ground
STP Pin 7
DIR Pin 8
1A, 1B, 2A, 2B Stepper motor

Here is the pin mapping

  • VDD –> Arduino 5V
  • GND –> Arduino GND
  • VMOT –> Positive terminal motor power  supply
  • GND –> Negative terminal motor power  supply
  • Direction –> Arduino Pin 8
  • Step —> Arduino Pin 7
  • 2B –> Stepper motor red wire
  • 2A –> Stepper motor green wire
  • 1A –> Stepper motor yellow wire
  • 1B –> Stepper Motor blue wire

With the stepper motor connected, we can now write the code to control it. We will be using the Arduino Stepper Library. The Arduino Stepper Library makes it easy to control a stepper motor. We just need to include the library and create a Stepper object:’


Sample Source Code

int dirPin =8;
int stepperPin = 7;

void setup()
 pinMode(dirPin, OUTPUT);
 pinMode(stepperPin, OUTPUT);

void step(boolean dir,int steps)

 for(int i=0;i<steps;i++)
   digitalWrite(stepperPin, HIGH);
   delayMicroseconds(600);//Adjust the speed of motor. Increase the value, motor speed become slower.
   digitalWrite(stepperPin, LOW);

void loop()
 //steps per revolution for 200 pulses = 360 degree full cycle rotation
 step(true,1000);//(direction ,steps per revolution). This is clockwise rotation.
 step(false,1000);//Turn (direction ,steps per revolution). This is anticlockwise rotation.


Download Code from Here
This sample is done by moving the 42 Step Stepper Motor device using the Arduino UNO with A4988 Stepper Motor Driver Module. Before connecting the motor power supply to the module, the sample source code must be uploaded first into the Arduino UNO.


Next, adjust the current limiting of the driver by using the potentiometer on board. This is to make sure that the current is within the current limits of the motor ranges from 0mA to 2000mA (2A).

In order to prevent damage to both the motor and driver module, the current must actively be limited to under 1A. In full step mode, the current through the coils is limited to 70% of the current limit, so to get a full-step coil current of 1 A, the current limit should be 1 A/0.7=1.4 A, which corresponds to a Vref of 1.4 A/2.5=0.56 V. Please refer to the A4988 datasheet for more information. The current limit relates to the reference voltage is as follows:

Current Limit = Vref / (8 x Rs)

Rs = Sense Resistor
Vref = input voltage on the REF pin.

In this example, the Vref (voltage references) is set to about 0.4 V, so the current limit is 1 A. You can measure the Vref of the module by attaching the multimeter probes between the centre of the potentiometer and the ground pin that is connected to the Arduino board.

Procedure (2)

The USB cable that is used to upload the reference code can now be detached. Next, connect the motor power supply (Li-on Battery, 7.4 V, 1200mAh) to the module via the power jack. The stepper motor will start to rotate clockwise and anticlockwise according to the assigned example reference code.


The Stepper Motor With Arduino text explains how to wire a stepper motor to an Arduino so that the Arduino can control the motor. The text also explains how to write a sketch to control the motor. The conclusion is that the Arduino can be used to control a stepper motor.

Leave a Reply

Your email address will not be published.

Related Articles

Back to top button