This project demonstrates how to control a NEMA 17 stepper motor using an Arduino Uno and an A4988 stepper driver module. A potentiometer is used to control the direction and rotation of the stepper motor in real-time. NEMA 17 stepper motors are widely used in robotics, CNC machines, 3D printers, and automation systems due to their high torque and precise control capabilities.
Project Source: Circuit Digest - Controlling NEMA 17 Stepper Motor
- Features
- Components Required
- NEMA 17 Stepper Motor
- A4988 Stepper Driver Module
- Circuit Diagram
- Pin Connections
- Installation
- Code Explanation
- How It Works
- Usage
- Troubleshooting
- Applications
- License
- ✅ Control NEMA 17 stepper motor with high precision
- ✅ Variable speed control using potentiometer
- ✅ Bidirectional rotation (clockwise and counter-clockwise)
- ✅ Simple 2-pin control interface (STEP and DIRECTION)
- ✅ Microstepping capability with A4988 driver
- ✅ Easy to integrate with Arduino projects
- ✅ Suitable for robotics and automation applications
Component | Quantity | Description |
---|---|---|
Arduino UNO | 1 | Microcontroller board |
NEMA 17 Stepper Motor | 1 | High-torque stepper motor |
A4988 Stepper Driver Module | 1 | Stepper motor driver |
Potentiometer (10kΩ) | 1 | For direction control |
Capacitor (47µF) | 1 | Protection from voltage spikes |
12V Power Supply | 1 | External power for motor |
Jumper Wires | - | For connections |
Breadboard | 1 | Optional, for prototyping |
- Rated Voltage: 12V DC
- Step Angle: 1.8 degrees
- Steps Per Revolution: 200 steps
- Number of Phases: 4
- Motor Length: 1.54 inches
- Wire Configuration: 6-wire unipolar arrangement
- Operating Temperature: -10°C to 40°C
- Unipolar Holding Torque: 22.2 oz-in
Steps per Revolution = 360° / Step Angle
Steps per Revolution = 360° / 1.8° = 200 steps
NEMA 17 has a unipolar six-wire arrangement:
- First Winding: Black (center tap), Yellow (coil end), Green (coil end)
- Second Winding: White (center tap), Red (coil end), Blue (coil end)
Note: Center tap wires are normally left disconnected.
The A4988 is a microstepping driver module with a built-in translator that simplifies stepper motor control using only two pins (STEP and DIRECTION).
- Maximum Operating Voltage: 35V
- Minimum Operating Voltage: 8V
- Maximum Current Per Phase: 2A
- Microstep Resolutions: Full-step, ½ step, ¼ step, 1/8 step, 1/16 step
- Dimensions: 15.5 × 20.5 mm (0.6″ × 0.8″)
MS1 | MS2 | MS3 | Microstep Resolution |
---|---|---|---|
Low | Low | Low | Full Step |
High | Low | Low | ½ Step (Half Step) |
Low | High | Low | ¼ Step (Quarter Step) |
High | High | Low | 1/8 Step (Eighth Step) |
High | High | High | 1/16 Step (Sixteenth Step) |
Note: In this project, MS1, MS2, and MS3 pins are left disconnected, operating in full-step mode.
The circuit consists of:
- Arduino UNO as the main controller
- A4988 driver module for stepper motor control
- NEMA 17 stepper motor
- 12V external power supply for the motor
- Potentiometer for direction control
- 47µF capacitor for voltage spike protection
S.No | A4988 Pin | Connection |
---|---|---|
1 | VMOT | +ve of 12V Battery |
2 | GND | -ve of 12V Battery |
3 | VDD | 5V of Arduino |
4 | GND | GND of Arduino |
5 | STEP | Pin 3 of Arduino |
6 | DIR | Pin 2 of Arduino |
7 | 1A, 1B, 2A, 2B | NEMA 17 Motor Wires |
- Potentiometer: Middle pin → A0, Other pins → 5V and GND
- Capacitor (47µF): Connect across VMOT and GND of A4988
- Connect the A4988 driver module to Arduino as per the pin connection table above
- Connect the NEMA 17 stepper motor wires to the A4988 driver (1A, 1B, 2A, 2B)
- Connect the 12V external power supply to VMOT and GND of A4988
- Add a 47µF capacitor between VMOT and GND for voltage spike protection
- Connect the potentiometer to analog pin A0
- Ensure all ground connections are common
- Download and install the Arduino IDE from arduino.cc
- Download the Stepper Motor Library from GitHub
- Install the library in Arduino IDE:
- Go to Sketch → Include Library → Add .ZIP Library
- Select the downloaded library file
#include <Stepper.h>
#define STEPS 200 // Steps per revolution for NEMA 17
The Stepper library is included, and the number of steps per revolution (200) is defined.
Stepper stepper(STEPS, 2, 3); // Pin 2: DIRECTION, Pin 3: STEP
#define motorInterfaceType 1
A Stepper object is created with 200 steps, connected to pins 2 and 3.
void setup() {
stepper.setSpeed(1000); // Set motor speed in RPM
}
The motor speed is set to 1000 RPM. NEMA 17's maximum speed is 4688 RPM, but torque drops quickly above 1000 RPM.
void loop() {
potVal = map(analogRead(A0), 0, 1024, 0, 500);
if (potVal > Pval)
stepper.step(10); // Move 10 steps clockwise
if (potVal < Pval)
stepper.step(-10); // Move 10 steps counter-clockwise
Pval = potVal;
}
The potentiometer value is read and mapped. If the current value is higher than the previous value, the motor moves clockwise; if lower, it moves counter-clockwise.
-
Initialization: The Arduino initializes the stepper motor with 200 steps per revolution and sets the speed to 1000 RPM.
-
Potentiometer Reading: The Arduino continuously reads the analog value from the potentiometer (0-1023) and maps it to a range of 0-500.
-
Direction Control:
- When you rotate the potentiometer clockwise, the current value increases, and the motor rotates clockwise in 10-step increments.
- When you rotate the potentiometer counter-clockwise, the current value decreases, and the motor rotates counter-clockwise in 10-step increments.
-
Motor Movement: The A4988 driver translates the STEP and DIRECTION signals from Arduino into the appropriate phase currents to drive the stepper motor.
- Open the Arduino IDE
- Copy the complete code into a new sketch
- Select the correct Board (Arduino UNO) from Tools → Board
- Select the correct Port from Tools → Port
- Click the Upload button
- Power on the 12V supply and Arduino
- Rotate the potentiometer clockwise to move the motor clockwise
- Rotate the potentiometer counter-clockwise to move the motor counter-clockwise
- The motor will respond to potentiometer movements in real-time
#include <Stepper.h>
#define STEPS 200
// Define stepper motor connections and motor interface type
// Motor interface type must be set to 1 when using a driver
Stepper stepper(STEPS, 2, 3); // Pin 2: DIRECTION, Pin 3: STEP
#define motorInterfaceType 1
int Pval = 0;
int potVal = 0;
void setup() {
// Set the maximum speed in steps per second:
stepper.setSpeed(1000);
}
void loop() {
potVal = map(analogRead(A0), 0, 1024, 0, 500);
if (potVal > Pval)
stepper.step(10);
if (potVal < Pval)
stepper.step(-10);
Pval = potVal;
}
- Check all power connections (12V supply to VMOT)
- Verify Arduino is powered and code is uploaded
- Ensure all ground connections are common
- Check stepper motor wire connections to A4988
- Add or increase capacitor value (47µF or higher)
- Check for loose connections
- Reduce motor speed in code
- Ensure adequate power supply current (at least 2A)
- Reduce motor speed
- Check if current limiting is set correctly on A4988
- Ensure proper ventilation around motor and driver
- Use a heatsink on the A4988 driver
- Increase supply voltage (up to 12V for NEMA 17)
- Adjust current limiting potentiometer on A4988
- Reduce motor speed
- Check for mechanical obstructions
This project can be used in various applications:
- 3D Printers: Precise axis control
- CNC Machines: Tool positioning
- Robotics: Robotic arm joints
- Camera Sliders: Smooth motion control
- Automated Curtains: Window automation
- Antenna Rotators: HF magnetic loop positioning
- Conveyor Systems: Material handling
- Laboratory Equipment: Sample positioning
To use quarter-step mode for finer control:
// Connect MS1 to Arduino pin 4, MS2 to pin 5
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(4, LOW); // MS1 = Low
digitalWrite(5, HIGH); // MS2 = High
digitalWrite(6, LOW); // MS3 = Low (if connected)
Update steps per revolution:
#define STEPS 800 // 200 steps × 4 (quarter-step) = 800
For slower, more precise movement:
stepper.setSpeed(100); // Slower speed for precision
For smoother control:
if (potVal > Pval)
stepper.step(1); // Move 1 step at a time
- Never disconnect the motor while it's powered
- Ensure proper heat dissipation for A4988 driver
- Use appropriate power supply ratings
- Double-check polarity before powering on
- Keep motor and driver away from moisture
- Use wire gauges appropriate for current ratings
- NEMA 17 Stepper Motor Datasheet
- A4988 Driver Datasheet
- Arduino Stepper Library Documentation
- Stepper Motor Projects
- Arduino Projects
This project is based on the tutorial from Circuit Digest and is intended for educational purposes. Please refer to the original source for licensing information.
Feel free to fork this project and submit pull requests for improvements or additional features. Suggestions and feedback are always welcome!
Based on the tutorial by Circuit Digest Team
For questions, comments, or issues, please refer to the original tutorial or consult the Arduino and stepper motor communities.