Arduino Nano ESP32 - DRV8825 Stepper Motor Driver

In this guide, we will explore the DRV8825 Stepper Motor Driver and discover how to operate it with Arduino Nano ESP32 to manage the stepper motor. Specifically, we will cover:

Arduino Nano ESP32 DRV8825 module

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×Stepper Motor Nema 17
1×DRV8825 Stepper Motor Driver
1×Expansion Board for DRV8825 Motor Driver
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano
1×(Recommended) Power Splitter For Arduino Nano ESP32

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DRV8825 Stepper Motor Driver

The DRV8825 is a popular module used to control bipolar stepper motors, commonly found in CNC machines, 3D printers, and robots. It has an adjustable current limit, protection against overheating, and options for different stepping modes, from full-step to tiny 1/32 steps. It can manage up to 2.2A for each motor coil with adequate cooling and works within a voltage range of 8.2V to 45V, accommodating various stepper motors.

To understand stepper motor ideas such as: full-step, microstepping, unipolar stepper, and bipolar stepper, check out the Arduino Nano ESP32 - Stepper Motor guide.

Using just two pins on an Arduino Nano ESP32, you can easily manage the speed and direction of a NEMA 17 bipolar stepper motor.

DRV8825 Stepper Motor Driver Pinout

DRV8825 module Pinout

The DRV8825 Stepper Motor Driver features 16 pins. Here's a common layout for the pins on the DRV8825 module. Keep in mind that some versions might name the pins a little differently, but their roles stay the same.

Pin Name Description
VMOT Motor power supply (8.2 V to 45 V). This powers the stepper motor.
GND (for Motor) Ground reference for the motor power supply. Connect this pin to the GND of the motor power supply
2B, 2A Outputs to Coil B of the stepper motor.
1A, 1B Outputs to Coil A of the stepper motor.
FAULT Fault Detection Pin. This is an output pin that drives LOW whenever the H-bridge FETs are disabled as the result of over-current protection or thermal shutdown.
GND (for Logic) Ground reference for the logic signals. Connect this pin to the GND of Arduino Nano ESP32
ENABLE Active-Low pin to enable/disable the motor outputs. LOW = Enabled, HIGH = Disabled.
M1, M2, M3 Microstepping resolution selector pins (see table below).
RESET Active-Low reset pin - pulling this pin LOW resets the driver.
SLEEP Active-Low sleep pin - pulling this pin LOW puts the driver into low-power sleep mode.
STEP Step input - a rising edge on this pin advances the motor by one step (or one microstep, depending on microstepping setting).
DIR Direction input - sets the rotation direction of the stepper motor.

There is also a little adjustable knob included that lets you set the current limit to stop the stepper motor and driver from getting too hot.

In summary, these 16 pins are grouped into the following categories based on their function:

  • Wires linked to the stepper motor: 1A, 1B, 2A, 2B.
  • Wires linked to Arduino Nano ESP32 for controlling the driver: ENABLE, M1, M2, M3, RESET, SLEEP.
  • Wires linked to Arduino Nano ESP32 for controlling motor direction and speed: DIR, STEP.
  • Wire for sending error signals to Arduino Nano ESP32: FAULT.
  • Wires linked to the motor’s power source: VMOT, GND (motor power ground).
  • Wire linked to the Arduino Nano ESP32’s ground: GND (logic ground).

The DRV8825 module doesn't need power from the Arduino Nano ESP32 board for its logic because it uses power from the motor's supply through its built-in 3.3V voltage regulator. Still, you must connect the Arduino Nano ESP32's ground to the DRV8825's GND (logic) pin to make sure it works correctly and shares a common ground.

Microstep Configuration

The DRV8825 driver allows for microstepping by breaking each step into smaller parts. This is done by applying different levels of current to the motor coils.

For instance, NEMA 17 motor with a 1.8-degree step angle (200 steps per revolution):

  • Full-step mode: 200 steps per rotation
  • Half-step mode: 400 steps per rotation
  • Quarter-step mode: 800 steps per rotation
  • Eighth-step mode: 1600 steps per rotation
  • Sixteenth-step mode: 3200 steps per rotation
  • Thirty-second-step mode: 6400 steps per rotation

When you set the microstepping higher, the motor runs smoother and more accurately, but it needs more steps for each full turn. If you keep the step pulse rate the same, each complete turn will take more time, making the motor slower.

If your microcontroller can send out pulses fast enough for the higher step count, you can keep or even boost speed. The real limit is based on how quickly both the driver and your microcontroller can handle these pulses without missing steps.

DRV8825 Microstep Selection Pins

The DRV8825 includes three inputs for choosing microstep resolution: M0, M1, and M2 pins. By setting these pins to certain logic levels, you can select from six microstepping resolutions:

M0 Pin M1 Pi M2 Pi Microstep Resolution
Low Low Low Full step
High Low Low Half step
Low High Low 1/4 step
High High Low 1/8 step
Low Low High 1/16 step
High Low High 1/32 step
Low High High 1/32 step
High High High 1/32 step

These small step choice pins come with built-in pull-down resistors that naturally keep them in a LOW state. If you don't connect them, the motor will run in full-step mode.

How it Works

To operate a stepper motor with the DRV8825 module, you require at least two Arduino Nano ESP32 pins: one for the DIR pin and another for the STEP pin. The DRV8825 decodes these signals from the Arduino Nano ESP32 to accurately move the stepper motor.

  • STEP Pin: Every pulse on the STEP pin moves the motor by one tiny step (or a whole step, depending on the microstepping setting).
  • DIR Pin: Sets which way the motor spins.

The driver uses these signals and its own settings to send control outputs to the motor through the 1A, 1B, 2A, and 2B pins.

You can also set up extra pins on the DRV8825 module (ENABLE, M1, M2, M3, RESET, SLEEP) in one of three ways:

  • Don't connect them so the driver uses default settings.
  • Connect them directly to GND or VCC for a steady mode.
  • Link them to Arduino Nano ESP32 pins to control their functions with your code.

Wiring Diagram between Arduino Nano ESP32, DRV8825 module and Stepper Motor

The diagram below displays the basic connections required between the Arduino Nano ESP32, DRV8825 module, and the stepper motor. In this configuration, the DRV8825 driver works in its standard mode (full-step).

The wiring diagram between Arduino Nano ESP32 and DRV8825 stepper motor driver

This image is created using Fritzing. Click to enlarge image

In detail:

  • VMOT: Hook up to the motor power source (like 12V).
  • GND (for Motor): Link to the motor power source's ground.
  • 1A, 1B, 2A, 2B: Connect to the stepper motor coils.
  • STEP: Connect to Arduino Nano ESP32 digital pin D4.
  • DIR: Connect to Arduino Nano ESP32 digital pin D3.
  • GND (for Logic): Connect to Arduino Nano ESP32 GND pin.
  • Other pins: leave unconnected.

Arduino Nano ESP32 Code

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-drv8825-stepper-motor-driver */ #include <AccelStepper.h> #define DIR_PIN D3 // The Arduino Nano ESP32 pin connected to DIR pin of DRV8825 module #define STEP_PIN D4 // The Arduino Nano ESP32 pin connected to STEP pin of DRV8825 module // Creates an instance AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); void setup() { // set the maximum speed, acceleration factor stepper.setMaxSpeed(1000); stepper.setAcceleration(200); // set speed and the target position stepper.setSpeed(200); stepper.moveTo(200); } void loop() { // Change direction once the motor reaches target position if (stepper.distanceToGo() == 0) stepper.moveTo(-stepper.currentPosition()); stepper.run(); // Move the motor one step }

Detailed Instructions

To get started with Arduino Nano ESP32, follow these steps:

  • If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Connect the Arduino Nano ESP32 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano ESP32 board and its corresponding COM port.
  • Copy the code and open it in Arduino IDE.
  • Go to the Libraries icon on the left side of Arduino IDE.
  • Type “AccelStepper” to search, then locate the AccelStepper library by Mike McCauley.
  • Press the Install button to add the AccelStepper library.
Arduino Nano ESP32 AccelStepper library
  • Copy the code and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano ESP32.
  • You will see the motor spin back and forth.

When using the motor in full-step mode, its movement might not be very smooth, which is usual. To achieve smoother movement, turn on microstepping by setting up the M1, M2, and M3 pins.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!