Arduino Projects

Control 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.

Thank You NextPCB:

This project is successfully completed because of the help and support from NextPCB. Guys if you have a PCB project, please visit their website and get exciting discounts and coupons.

  • Why NextPCB
  • Most Efficient, Economic, Innovative PCB Solutions
  • Higher Quality
  • Lower Cost
  • Faster Delivery

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 board

● A4988 stepper motor driver

● NEMA17 stepper motor

● 100uF electrolytic capacitor

● 12V, 2A DC power supply

● 5V DC power supply

● Connect jumpers

● 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 is applied and tested: 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

Main features

  • Maximum working voltage: 35V
  • Minimum operating voltage: 8V
  • Maximum current per phase: 2A
  • Microstep resolution: full step, ½ step, ¼ step, 1/8 and 1/16 step
  • Reverse voltage protection: none
  • Dimensions: 15.5 × 20.5 mm (0.6 in × 0.8 in)
  • Short circuit to ground and load short circuit protection
  • Low RDS(ON) output

A4988 motor driver Pinout

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

A4988 motor driver pinout

A compact quick-reference for the A4988 stepper motor driver. Figure

  • Power pin: This pin includes VDD & VMOT and a pair of GND pins. Thus, make sure that the positive and negative power sources are connected on separate pins when powering the IC. VDD is used to drive the internal logic and can be compatible with a supply of 3V to 5V, while VMOT powers the motor with a supply range of 8V to 35V.
  • Microstep selection pins: The A4988 driver has three-step resolution selector inputs, MS1, MS2, and MS3. The magnetic field in a stepper motor will be varied by the change of current flowing through each coil, but the steps will be repeated (except in the full-step drive mode) because of the offset between the switch. Thus, there will be more than a change in magnetic field for one step at high resolution; for a 200-step motor, the 200 full steps become 400 in the half-stepping drive mode (one step requires 2 changes), and becomes 1600 for 1/8-stepping drive mode (one step requires 4 changes).
  • Control input pins: STEP and DIR are 2 control input pins. The STEP input controls the micro-stepping of the motor, while the DIR input controls the direction of rotation of the motor. – To send the motor clockwise, we will pull the DIR pin to HIGH and make the STEP pin goes HIGH and then turns back to LOW. – To send the motor counter-clockwise, we will pull the DIR pin to LOW, then make the STEP pin goes HIGH and turns BACK to LOW. The address pin (ENT) is used to select the driver you want to send a signal to if you are using more than one driver.
  • Power state control pins: The A4988 has three different inputs to control its power state, namely EN, RST, and SLP. During operation, the EN pin is an active low input that enables the A4988 driver when pulled low. The SLP pin is an active low input. Pulling this pin low will put the driver into sleep mode, minimizing device consumption, while pulling it high will turn off sleep mode. While in sleep mode, the VDD supply will be disconnected from the VMOT pin, so the VMOT still needs its own power supply. The RST pin is an active low input, which disables and resets the driver when pulled to LOW, then advances the motor to a known reference position.
  • Output pins: There are 4 output pins, namely 2B, 2A, 1B, and 1A. We can connect any bipolar stepper motor with a voltage between 8V to 35V to these pins.

A4988 Pin Definition


Set current limit

A4988 Current

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 related 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.


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.

Circuit Schematics – Stepper Motor with Arduino Using A4988 Driver

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

The VMOT pin is powered by a 12V supply, while VDD is powered by a 5V supply. Remember to place a large 100µF decoupling electrolytic capacitor on the motor power pins close to the board.

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

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.

Potentiometer to Control NEMA17 Stepper Motor

Stepper motors can also be controlled using potentiometers. This article uses a 10K potentiometer and connects it to the analog pin A0 of the Arduino.

The voltage fed into the Arduino analog pins can be used as a reference voltage to control the speed of the stepper motor. The connection diagram is as follows.

diagram 2

Code – Potentiometer to Control Stepper Motor

Copy the code below and upload it to the Arduino Nano board.


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.

The above is the process of using the A4988 driver module and the Arduino development board to control the stepper motor. If you have any queries, feel free to reply to this post.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker