ESP32 - Stepper Motor

WARNING

This tutorial is currently updating.

Hardware Required

1×ESP-WROOM-32 Dev Module
1×Micro USB Cable
1×Stepper Motor
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

About Stepper Motor

There are two types of step motors: bipolar stepper motor and unipolar stepper motor. They differ from each other in the internal structure and the working principle.

With the naked eyes, they look similar to each other. However, we can distinguish them by the number of wires. The bipolar motor usually has four wires. The unipolar motor usually has six wires.

Controlling the bipolar stepper motor and the unipolar stepper motor is different. Fortunately, we can control the unipolar stepper as if it is a bipolar stepper motor by using four of six wires.

Pinout

https://esp32io.com/images/tutorial/stepper-motor-pinout.jpg

How To Control Stepper Motor with ESP32

The stepper motor requires more power than ESP32 board can give it, so you’ll need another power supply for it. Ideally, Stepper motor's datasheet or manual lets you know the voltage of the power supply.

We CANNOT connect the stepper motor directly to ESP32. We MUST connect via a motor driver or motor controller.

The motor driver and motor controller can be:

  • Chip (e.g. SN754410)
  • Module (e.g. A4988)

Using ESP32 Motor Shield Rev3

Wiring Diagram

  • Stack ESP32 Motor Shield Rev3 on ESP32
  • Connect stepper motor to ESP32 Motor Shield Rev3
  • https://esp32io.com/images/tutorial/esp32-stepper-motor-wiring-diagram.jpg

Code

Quick Steps

  • If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE
  • Download or copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to compile and upload code to ESP32 board
  • Open Serial Monitor to see result:
  • COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

Additional Knowledge

1. Stepper motor vibrates while moving

Do NOT worry if the stepper motor vibrates while moving. This is a characteristic of the stepper motor. We can reduce vibration by using the micro-stepping control method.

Also, because of this characteristic, if we control properly, the stepper motor can produce musical sounds as if it is a musical instrument. You can see this project on ESP32 Project Hub.

2. Method of controlling stepper motors

  • Full-step: The unit of moving is one step, which is equivalent a value of degree specified in stepper motor's datasheet or manual.
  • Half-step: divides each full step into two smaller steps. The unit of moving is half of the full step. This method allows the motor move with double resolution.
  • Micro-step: divides each full step into many smaller steps. The unit of moving is a fraction of the full step. The fraction can be 1/4, 1/8, 1/16, 1/32 or even more. This method allows the motor move with higher resolution. It also make motor move smoother at low speeds. The bigger dividend is, the higher resolution and the smoother motion is.

For example, If the motor's datasheet specifies 1.8 degree/step:

  • Full-step: The motor can move with 1.8 degree/step <⇒ 200 steps/ revolution
  • Half-step: The motor can move with 0.9 degree/step <⇒ 400 steps/ revolution
  • Micro-step: The motor can move with 0.45, 0.225, 1125‬, 0.05625 degree/step <⇒ 800, 1600, 3200, 6400... steps/ revolution

The above code used the full-step control method.

3. Resonance Issue

This is the advanced usages. The beginners do NOT need to pay attention to it. This happens in a speed range, in which the step rate equals the motor’s natural frequency. There may be an audible change in noise made by the motor, as well as an increase in vibration. In real applications, the developer SHOULD pay attention to this issue.

※ NOTE THAT:

Note that this tutorial is incomplete. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.

※ NOTICES

  • We are AVAILABLE for HIRE. See how to hire us to do your project
  • If this tutorial is useful for you, please support us to make more tutorials.
  • We spent a lot of time and effort to create the content for this tutorial, please respect our work! Please do not copy the content to share on other websites. Howerver, please feel free to share the link of this tutorial anywhere