Skip to content

Circuit-Digest/NEMA-17-Stepper-Motor-with-Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Controlling NEMA 17 Stepper Motor with Arduino and A4988 Stepper Driver Module

NEMA 17 Stepper Motor Control

Project Overview

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

Table of Contents

Features

  • ✅ 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

Components Required

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

NEMA 17 Stepper Motor

Specifications

  • 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 Calculation

Steps per Revolution = 360° / Step Angle
Steps per Revolution = 360° / 1.8° = 200 steps

Wire Configuration

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.

A4988 Stepper Driver Module

The A4988 is a microstepping driver module with a built-in translator that simplifies stepper motor control using only two pins (STEP and DIRECTION).

Specifications

  • 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″)

Microstepping Resolution Table

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.

Circuit Diagram

Connection Overview

The circuit consists of:

  1. Arduino UNO as the main controller
  2. A4988 driver module for stepper motor control
  3. NEMA 17 stepper motor
  4. 12V external power supply for the motor
  5. Potentiometer for direction control
  6. 47µF capacitor for voltage spike protection

Pin Connections

A4988 to Arduino Connections

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

Additional Connections

  • Potentiometer: Middle pin → A0, Other pins → 5V and GND
  • Capacitor (47µF): Connect across VMOT and GND of A4988

Installation

Hardware Setup

  1. Connect the A4988 driver module to Arduino as per the pin connection table above
  2. Connect the NEMA 17 stepper motor wires to the A4988 driver (1A, 1B, 2A, 2B)
  3. Connect the 12V external power supply to VMOT and GND of A4988
  4. Add a 47µF capacitor between VMOT and GND for voltage spike protection
  5. Connect the potentiometer to analog pin A0
  6. Ensure all ground connections are common

Software Setup

  1. Download and install the Arduino IDE from arduino.cc
  2. Download the Stepper Motor Library from GitHub
  3. Install the library in Arduino IDE:
    • Go to Sketch → Include Library → Add .ZIP Library
    • Select the downloaded library file

Code Explanation

Library Inclusion and Constants

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

Motor Initialization

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.

Setup Function

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.

Main Loop

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.

How It Works

  1. Initialization: The Arduino initializes the stepper motor with 200 steps per revolution and sets the speed to 1000 RPM.

  2. Potentiometer Reading: The Arduino continuously reads the analog value from the potentiometer (0-1023) and maps it to a range of 0-500.

  3. 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.
  4. Motor Movement: The A4988 driver translates the STEP and DIRECTION signals from Arduino into the appropriate phase currents to drive the stepper motor.

Usage

Uploading the Code

  1. Open the Arduino IDE
  2. Copy the complete code into a new sketch
  3. Select the correct Board (Arduino UNO) from Tools → Board
  4. Select the correct Port from Tools → Port
  5. Click the Upload button

Operating the System

  1. Power on the 12V supply and Arduino
  2. Rotate the potentiometer clockwise to move the motor clockwise
  3. Rotate the potentiometer counter-clockwise to move the motor counter-clockwise
  4. The motor will respond to potentiometer movements in real-time

Complete Arduino Code

#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;
}

Troubleshooting

Motor Not Moving

  • 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

Motor Moving Erratically

  • 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)

Motor Getting Hot

  • 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

Weak Torque

  • Increase supply voltage (up to 12V for NEMA 17)
  • Adjust current limiting potentiometer on A4988
  • Reduce motor speed
  • Check for mechanical obstructions

Applications

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

Customization Options

Changing Microstepping Resolution

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

Adjusting Speed

For slower, more precise movement:

stepper.setSpeed(100);  // Slower speed for precision

Changing Step Increment

For smoother control:

if (potVal > Pval)
  stepper.step(1);  // Move 1 step at a time

Safety Precautions

⚠️ Important Safety Notes:

  • 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

Additional Resources

License

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.

Contributing

Feel free to fork this project and submit pull requests for improvements or additional features. Suggestions and feedback are always welcome!

Author

Based on the tutorial by Circuit Digest Team


Project Link: https://circuitdigest.com/microcontroller-projects/controlling-nema-17-stepper-motor-with-arduino-and-a4988-stepper-driver-module


For questions, comments, or issues, please refer to the original tutorial or consult the Arduino and stepper motor communities.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages