ESP32 S3 UNO - Stepper Motor A4988 Driver

Seen from above, a small robot arm looks like a clock hand. The base turns and the gripper sweeps over the table: above the parts tray, above the box, and back to the middle. The base has to find these three spots again and again, and it must start and stop softly, or the whole arm begins to wobble. Here a NEMA 17 stepper motor turns that base in counted steps. The ESP32 S3 Uno gives the orders, and a DIYables A4988 module feeds the motor.

The stops on this page:

  1. Sort the A4988 pins into five small groups, and see why VDD gets 3.3V and never 5V on this board
  2. Decide how strong the base may push, with a tiny screwdriver and a multimeter
  3. Connect STEP to D3 and DIR to D2, once through a carrier board and once straight to the module
  4. Swing the base one full circle and back, with no library
  5. Send the base to PICK, PLACE and HOME with AccelStepper, with a gentle start and a gentle stop
ESP32 S3 Uno and A4988 driver turn a NEMA 17 robot arm base

The first program uses only built-in functions. For the second one you install a single library, and its Quick Steps show how.

Hardware Preparation

1×ESP32 S3 Uno-form Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Stepper Motor Nema 17
1×A4988 Stepper Motor Driver
1×Expansion Board for A4988
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for ESP32 S3 Uno
1×Recommended: Sensors/Servo Expansion Shield for ESP32 S3 Uno
1×Recommended: Breadboard Shield for ESP32 S3 Uno
1×Recommended: Enclosure for ESP32 S3 Uno
1×Recommended: Power Splitter for ESP32 S3 Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for ESP32 S3 Uno

Or you can buy the following kits:

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 .

One part of this list is optional: the expansion board. With it, a capacitor, a motor plug, the RST-SLP link and the step size switches come ready-made. Without it, you do these few jobs yourself. Further down you find drawings for both.

Overview of A4988 Stepper Motor Driver

If the NEMA 17 is the muscle of the arm base, the A4988 is the nerve that tells the muscle what to do. DIYables puts this chip on a red 20 x 15 mm board in the well-known "StepStick" shape. The board comes with two strips of eight pins, soldered at the factory, plus a little stick-on heat sink. One board serves one joint of the arm: a single bipolar stepper motor with four wires. A six-wire motor can play that part too, with two of its wires left unused.

A4988 stepper motor driver module pinout - command pins EN to DIR on the left, motor power, coil and logic power pins on the right

Sixteen pins sound like a lot, but they fall into five groups:

  • The orders (STEP, DIR): every pulse on STEP is one step of the base. DIR says to which side. They are the only two signals from the ESP32 S3 Uno: STEP from D3 (GPIO17), DIR from D2 (GPIO18).
  • The step size (MS1, MS2, MS3): three inputs that split a step into smaller ones. With nothing connected they read LOW, and the motor makes full steps.
  • Awake or asleep (EN, RST, SLP): EN works upside down. HIGH releases the motor, LOW keeps it under power, and the module itself holds EN at LOW. RST and SLP both stop the driver at LOW. SLP has a pull-up, but RST floats, so one short link from RST to SLP keeps the two of them HIGH.
  • The coils (2B, 2A, 1A, 1B): 2B and 2A are for one coil of the motor, 1A and 1B for the second coil. Do not let the print confuse you: seen from above the labels are B2, A2, A1, B1, seen from below they are 2B, 2A, 1A, 1B.
  • The supplies (VMOT, VDD, two times GND): 12V enters at VMOT and the GND beside it. 3.3V enters at VDD and the GND beside it. The module connects its two GND pins to each other.
DIYables A4988 Stepper Motor Driver Module
Made for one bipolar stepper motor
VMOT range 8V to 35V DC, here 12V
VDD range 3V to 5.5V, here 3.3V
Current per coil with a bare chip about 1A
Current per coil with heat sink and good cooling up to 2A
Step sizes full, 1/2, 1/4, 1/8, 1/16
Protection over-temperature shutdown, under-voltage lockout, crossover-current protection
FAULT pin no

What one pulse does

A pulse is a short HIGH on STEP. The moment the level rises, the base moves by one step (or one microstep). Stay HIGH for at least 1 microsecond, and then LOW for at least 1 microsecond, and the chip never misses a pulse. Which coil has to be switched for that step? You do not need to know. A block in the chip, called the translator, has the coil pattern of all steps, so the sketch has only one job: counting.

The chip also looks after the current. When a coil reaches its limit, the chip switches it off for a moment, then on again, and so on. People call this chopping. Thanks to it, 12V does no harm to a motor whose label says 2V to 4V.

The bar that VDD sets

Unlike the DRV8825, the A4988 cannot power its own logic, so VDD is a wire you may not forget. VDD also works like the bar in a high jump. A signal counts as HIGH only if it jumps over 70% of VDD, and a pulse from the ESP32 S3 Uno jumps to 3.3V:

VDD comes from Height of the bar Result for a 3.3V pulse
3V3 about 2.3V over the bar, always HIGH
5V 3.5V under the bar, not a safe HIGH

For this board there is one answer only: VDD goes to 3V3 and never to 5V.

From 1.8° down to 0.1125°

In full steps the base jumps by 1.8° per pulse. Close to the motor that is tiny, but at the end of a long arm you can see it. Microsteps cut the jump into 2, 4, 8 or 16 parts. The 3-way DIP switch of the expansion board does the cutting (ON means HIGH). Its numbers run backward: MS1 has switch 3, MS2 has switch 2, MS3 has switch 1. On the bare module, a wire from an MS pin to 3V3 is HIGH and a free pin is LOW.

Base angle per pulse Step size Switch 3 (MS1) Switch 2 (MS2) Switch 1 (MS3) Steps per turn
1.8° full OFF, LOW OFF, LOW OFF, LOW 200
0.9° 1/2 ON, HIGH OFF, LOW OFF, LOW 400
0.45° 1/4 OFF, LOW ON, HIGH OFF, LOW 800
0.225° 1/8 ON, HIGH ON, HIGH OFF, LOW 1600
0.1125° 1/16 ON, HIGH ON, HIGH ON, HIGH 3200

With fine steps the gripper glides more quietly, but a quarter turn then takes 200 pulses (1/4), 400 (1/8) or 800 (1/16) and not 50. The sketch cannot see the switches. It has the constant MICROSTEPS for this, and the number there must fit the table row you chose.

How strong may the base push?

The small trimmer answers this question. It sets a voltage, VREF, and VREF sets the highest coil current. DIYables uses two sense resistors of 0.1 ohm (you can read R100 on them), and with these the math is short:

VREF = 0.8 × coil current

Coil current VREF
0.5A 0.40V
0.7A 0.56V
1A 0.80V

This is how you adjust it:

  1. USB in, 12V out. The 3.3V on VDD is all that the trimmer needs.
  2. Find the test point. It is the metal head of the trimmer itself. Measure from there to GND, with the multimeter on its DC voltage range.
  3. Make very small turns. Read the display after each one. Keep the screwdriver tip on the trimmer, because a slip to the next part can make a short circuit.
  4. Begin at the low end. A weak base that skips steps may get a bit more. The motor datasheet tells you where to stop.

Is there another number on your sense resistors? A4988 boards of other brands can carry R050, and then VREF = 0.4 × coil current. Both rules come from current = VREF / (8 × Rs).

※ NOTE THAT:

Between two moves the motor grips the base with that same current. A warm driver and a warm motor are therefore normal, even if the arm has not moved for minutes. If the driver gets very hot, lower VREF and add the heat sink.

Overview of Stepper Motor

A bipolar stepper motor like our NEMA 17 hides two separate coils in its body. Each coil ends in two wires, which makes four. One full step is worth 1.8° of shaft angle, and 360 divided by 1.8 makes 200 steps for a round trip.

Two coils of a bipolar stepper motor - coil A C with black and green wires, coil B D with red and blue wires
Motor wire Also called Colour on our example motor Driver pin
A A+ or A black 2B
C A- or A with a bar green 2A
B B+ or B red 1A
D B- or B with a bar blue 1B

Colours are not a standard. If your datasheet says something else, the datasheet is right. And if there is no datasheet, ask the wires:

  • With a multimeter: between the two ends of one coil it shows a few ohms. Between ends of different coils it shows no connection.
  • With your fingers: hold two wire ends against each other and spin the shaft. Does it suddenly drag? Then both ends belong to one coil.

A coil that is connected the wrong way round is no problem, because it just makes the base rotate to the other side. Trouble starts when one wire of each coil shares a pair of pins. The motor then buzzes and shivers but goes nowhere.

ESP32 S3 Uno Pinout

Four spots on the ESP32 S3 Uno matter here: 3V3 and GND for the logic side of the driver, D3 (GPIO17) for STEP and D2 (GPIO18) for DIR. In the drawings below, these two header holes carry their GPIO names, IO17 and IO18.

ESP32 S3 Uno pinout diagram

※ NOTE THAT:

Why not D4 and D5, right beside them? On this board they are GPIO19 and GPIO20, and those two carry the USB data of the chip. D6 (GPIO3) and D9 (GPIO46) have a second life as strapping pins: the chip reads them while it boots. D2 and D3 have no such side job.

Wiring Diagram

With the expansion board

The black 42 x 42 mm expansion board is a seat for the driver module, with two sockets of eight holes. It accepts the A4988 and the DRV8825. From there, two signal wires, one 3.3V wire and one ground wire lead to the ESP32 S3 Uno.

The wiring diagram between ESP32 S3 Uno stepper motor A4988 driver

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Look twice before you press the module into its sockets. The board has a small arrow with the word "VIN": the VMOT corner of the module belongs there. The row with EN at one end and DIR at the other then faces the G V S header. The wrong way round can kill the module.

ESP32 S3 Uno / Other Part Expansion Board
D3 (GPIO17) STEP row, S pin
D2 (GPIO18) DIR row, S pin
3V3 a V pin
GND a G pin
12V adapter, + screw of the DC power jack VIN
12V adapter, - screw of the DC power jack GND (next to VIN)
Motor wires A (black) and C (green) motor plug 2B and 2A
Motor wires B (red) and D (blue) motor plug 1A and 1B
nothing EN row (free means on)

It makes no difference which V pin and which G pin you take, since the three of each kind are connected. But do connect the V wire. A DRV8825 in this seat would run without it, an A4988 gets its VDD from it. All DIP switches stay OFF for now. The link from RST to SLP and a 100uF / 35V capacitor are part of the board.

Do not search for a brown, a yellow, a pink or a purple wire on your motor. The drawing just paints its four motor lines that way.

A turning arm shakes the table a little with every move, and after a while jumper wires creep out of their holes. Screws do not. Two shields turn the header of the ESP32 S3 Uno into screw terminals, the Screw Shield V2 and the Proto Screw Terminal Block Shield. Here is the first one with our four wires, where the terminals for STEP and DIR have the marks 3 and 2:

The wiring diagram between ESP32 S3 Uno stepper motor A4988 driver Screw Shield

This image is created using Fritzing. Click to enlarge image

WARNING

  • 12V has one address: VIN on the expansion board, or VMOT on the bare module. On a pin of the ESP32 S3 Uno it ends the life of the board.
  • 3.3V for the logic: V and VDD come from 3V3. The 5V pin is right next to it on the header, so check it twice.
  • One common ground: adapter minus, driver and ESP32 S3 Uno share the same GND.
  • Leave the motor plug alone under power. Taking the motor off a live A4988, or adding it, gives a spike of voltage, and the chip can die from it.
  • 12V comes last: all other wires first, a second look at them, then the adapter.

Without the expansion board

Straight to the module, the plan is the same: two signals, 3.3V, ground and 12V. A short RST-SLP link is added.

The wiring diagram between ESP32 S3 Uno stepper motor A4988 driver module

This image is created using Fritzing. Click to enlarge image

A4988 Module ESP32 S3 Uno / Other Part
STEP D3 (GPIO17)
DIR D2 (GPIO18)
VDD 3V3
GND beside VDD GND
VMOT 12V adapter, + screw of the DC power jack
GND beside VMOT 12V adapter, - screw of the DC power jack
2B and 2A motor wires A (black) and C (green)
1A and 1B motor wires B (red) and D (blue)
RST SLP (a short wire from pin to pin)
EN, MS1, MS2, MS3 free

※ NOTE THAT:

  • Orange jumper: this is the RST-SLP link in the drawing. A driver without it stays in reset, and the base never turns.
  • Missing in the drawing: a 100uF capacitor between VMOT (+ leg) and the GND beside it, right at the module. Best is one rated for 35V or more. It catches voltage peaks on the 12V side.

Screw terminals work for the bare module as well:

The wiring diagram between ESP32 S3 Uno stepper motor A4988 driver module Screw Shield

This image is created using Fritzing. Click to enlarge image

How To Program For A4988 Stepper Motor Driver

Everything comes down to one question: how many pulses, to which side, and how fast?

  1. Give the two pins a name. The ESP32 core wants GPIO numbers, so header D3 is 17 and header D2 is 18:
#define STEP_PIN 17 // D3 #define DIR_PIN 18 // D2
  1. Work out the pulses for one turn. 200 full steps, multiplied by the microstep number of your DIP switches:
#define MICROSTEPS 1 #define STEPS_PER_TURN (200 * MICROSTEPS)
  1. Make one pulse. 2000 microseconds HIGH and 2000 LOW is 4 ms per step, so 250 steps per second. In full step that is 75 turns per minute, slow enough for a NEMA 17 to start without a run-up:
digitalWrite(STEP_PIN, HIGH); // the motor moves at this edge delayMicroseconds(PULSE_HALF); digitalWrite(STEP_PIN, LOW); delayMicroseconds(PULSE_HALF);
  1. Choose the side before you send pulses. Set DIR, give it a few microseconds, then start:
digitalWrite(DIR_PIN, side); delayMicroseconds(5);
  1. Think in angles. A robot arm talks in degrees, and the driver counts steps. The formula between the two is steps = angle × steps per turn / 360:
long angleToSteps(float angle) { return lround(angle * STEPS_PER_TURN / 360.0); }

lround() rounds to the nearest whole step. In full step, 72° is exactly 40 steps. An angle like 50° is 27.8 steps, so the base stops at step 28, which is 50.4°. With 1/8 steps the same 50° is 222 steps, or 49.95°.

  1. Let a library shape the speed. AccelStepper is told that a STEP / DIR driver is connected, then it gets a target. run() makes a step whenever one is due, and it speeds up and slows down by itself:
AccelStepper armBase(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); armBase.moveTo(angleToSteps(72.0)); // a new target for the base armBase.run(); // in loop(): again and again

ESP32 S3 Uno Code - Stepper Motor A4988 Driver

This sketch is the first health check of your wiring. The base goes all the way around, waits 1.2 seconds, goes back the same way, waits again, and repeats this until you pull the plug. It needs no library.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-stepper-motor-a4988-driver */ #define STEP_PIN 17 // The ESP32 S3 Uno pin D3 (GPIO17) connected to the STEP pin of the A4988 #define DIR_PIN 18 // The ESP32 S3 Uno pin D2 (GPIO18) connected to the DIR pin of the A4988 #define MICROSTEPS 1 // 1 = full step (all DIP switches OFF), or 2, 4, 8, 16 #define STEPS_PER_TURN (200 * MICROSTEPS) // a 1.8 degree motor needs 200 full steps for one turn #define PULSE_HALF 2000 // microseconds STEP stays HIGH, and then stays LOW #define REST_TIME 1200 // milliseconds of rest after each turn // one pulse on STEP: the A4988 moves the motor when STEP goes from LOW to HIGH void oneStep() { digitalWrite(STEP_PIN, HIGH); delayMicroseconds(PULSE_HALF); digitalWrite(STEP_PIN, LOW); delayMicroseconds(PULSE_HALF); } // swing the arm base: side is HIGH or LOW, steps is the number of pulses void swingBase(int side, int steps) { digitalWrite(DIR_PIN, side); delayMicroseconds(5); // DIR must be stable before the first pulse for (int i = 0; i < steps; i++) { oneStep(); } } void setup() { Serial.begin(9600); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); digitalWrite(STEP_PIN, LOW); // start from LOW, so the first HIGH is a real edge Serial.println("ESP32 S3 Uno + A4988: arm base, one turn out and one turn back"); } void loop() { Serial.print("Swing out (DIR HIGH), "); Serial.print(STEPS_PER_TURN); Serial.print(" steps ... "); swingBase(HIGH, STEPS_PER_TURN); Serial.println("full circle"); delay(REST_TIME); Serial.print("Swing back (DIR LOW), "); Serial.print(STEPS_PER_TURN); Serial.print(" steps ... "); swingBase(LOW, STEPS_PER_TURN); Serial.println("back at the start"); delay(REST_TIME); }

Detailed Instructions

  1. Arduino IDE not ready yet? Follow ESP32 S3 Uno - Getting Started to add the ESP32 core.
  2. Give the motor a paper arm. The real arm stays off for now. A strip of paper, fixed to the shaft with tape, shows every move and breaks nothing.
  3. Do the wiring and check that the DIP switches are OFF. The 12V adapter is still lying on the table.
  4. Plug the USB Type-C cable into the computer and the ESP32 S3 Uno. The driver logic now has power, so this is the moment to adjust VREF.
  5. In Arduino IDE, set the board to ESP32S3 Dev Module and choose its COM port.
  6. Put the code above into an empty sketch and send it to the board with Upload.
Arduino IDE - How to Upload Code
  1. Give the motor its 12V. Remember where the paper arm points.
  2. Start the Serial Monitor, pick 9600 baud and press RESET. The text runs in step with the motor:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
ESP32 S3 Uno + A4988: arm base, one turn out and one turn back Swing out (DIR HIGH), 200 steps ... full circle Swing back (DIR LOW), 200 steps ... back at the start Swing out (DIR HIGH), 200 steps ... full circle Swing back (DIR LOW), 200 steps ... back at the start Swing out (DIR HIGH), 200 steps ... full circle
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Judge the paper arm, not the text. After each line it has to point exactly where it pointed before. If it does not, the DIP switches and MICROSTEPS disagree, or the motor skips steps.

ESP32 S3 Uno Code - PICK, PLACE and HOME with AccelStepper

Now the base gets a job. It goes to PICK, then to PLACE on the other side, then HOME, with a pause of 1.5 seconds at each stop. The speed grows step by step at the start of a move and shrinks step by step before the end, so the arm does not swing.

Stop Angle from HOME Target in full steps Way to go
PICK 72° 40 40 steps
PLACE -126° -70 110 steps
HOME 0° 0 70 steps
/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-stepper-motor-a4988-driver */ #include <AccelStepper.h> #define STEP_PIN 17 // The ESP32 S3 Uno pin D3 (GPIO17) connected to the STEP pin of the A4988 #define DIR_PIN 18 // The ESP32 S3 Uno pin D2 (GPIO18) connected to the DIR pin of the A4988 #define MICROSTEPS 1 // 1 = full step (all DIP switches OFF), or 2, 4, 8, 16 #define STEPS_PER_TURN (200L * MICROSTEPS) // a 1.8 degree motor needs 200 full steps for one turn #define TOP_SPEED (600.0 * MICROSTEPS) // steps per second, never faster than this #define SPEED_GAIN (320.0 * MICROSTEPS) // how many steps per second the speed grows in one second #define REST_TIME 1500 // milliseconds the base waits at each stop // one stop of the arm base: a name and an angle, counted from HOME struct Stop { const char* name; float angle; // in degrees, a minus sign means the other side of HOME }; // the base visits these stops from top to bottom, then starts again Stop route[] = { { "PICK", 72.0 }, { "PLACE", -126.0 }, { "HOME", 0.0 } }; const int STOP_COUNT = sizeof(route) / sizeof(route[0]); // DRIVER = a driver board with a STEP pin and a DIR pin AccelStepper armBase(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); int stopIndex = 0; // the stop the base is heading for bool resting = false; // true while the base waits at a stop unsigned long restStart = 0; // when the wait began // turn an angle into the nearest whole number of steps long angleToSteps(float angle) { return lround(angle * STEPS_PER_TURN / 360.0); } // give the library a new target, the motor does not move yet void headFor(int index) { long target = angleToSteps(route[index].angle); Serial.print("Heading for "); Serial.print(route[index].name); Serial.print(" at "); Serial.print(route[index].angle, 1); Serial.print(" degrees (step "); Serial.print(target); Serial.println(")"); armBase.moveTo(target); } void setup() { Serial.begin(9600); armBase.setMaxSpeed(TOP_SPEED); armBase.setAcceleration(SPEED_GAIN); armBase.setMinPulseWidth(3); // keep STEP HIGH for 3 microseconds (the A4988 needs at least 1) Serial.println("Arm base ready: this position is HOME (step 0)"); headFor(stopIndex); } void loop() { armBase.run(); // makes one step if its time has come, so call it as often as possible if (armBase.distanceToGo() != 0) { return; // the base is still turning } if (!resting) { // the base has just arrived: start the waiting time, no delay() needed resting = true; restStart = millis(); Serial.print(" arrived, the counter shows step "); Serial.println(armBase.currentPosition()); } else if (millis() - restStart >= REST_TIME) { // the waiting time is over: choose the next stop resting = false; stopIndex = (stopIndex + 1) % STOP_COUNT; headFor(stopIndex); } }

Detailed Instructions

  1. Go to the Library Manager in Arduino IDE (the Libraries icon at the side).
  2. Enter "AccelStepper" as the search word. You want the entry by Mike McCauley.
  3. Add it with Install:
  • Search for AccelStepper created by Mike McCauley and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
AccelStepper by Mike McCauley
Provides an object-oriented interface for 2, 3 or 4 pin stepper motors and motor drivers. More info
1.64
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Swap the sketches: pull the 12V plug, clear the editor, paste the new code, Upload.
  2. Set HOME by hand. Turn the paper arm until it points straight ahead.
  3. Start the motor and the counter together. Keep RESET pressed, bring the 12V back, then let RESET go.
  4. Read the route in the Serial Monitor, still with 9600 baud:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Arm base ready: this position is HOME (step 0) Heading for PICK at 72.0 degrees (step 40) arrived, the counter shows step 40 Heading for PLACE at -126.0 degrees (step -70) arrived, the counter shows step -70 Heading for HOME at 0.0 degrees (step 0) arrived, the counter shows step 0 Heading for PICK at 72.0 degrees (step 40) arrived, the counter shows step 40
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. Follow one long move with your eyes. On the way from PICK to PLACE, the base gets faster for 55 steps and slower for 55 steps. It never reaches TOP_SPEED (600 steps per second), because the way is too short for that. To make the arm livelier or calmer, change SPEED_GAIN.
  2. Try it with 1/8 steps. Switches 3 and 2 go ON, switch 1 stays OFF, and the sketch gets MICROSTEPS 8. The stops are at the same angles as before, with a finer motion in between.

※ NOTE THAT:

loop() must come round very often, because armBase.run() makes at most one step per call. This is why the pause uses millis(). A delay() while the base is moving would stop the pulses in the middle of the move.

Video Tutorial

Additional Knowledge

A4988 or DRV8825?

Both drivers plug into the same seat and listen to the same two signals, so in full step the sketches of this page run with either of them. What is different is the power they can handle:

A4988 (on this page) DRV8825
Motor supply 8V to 35V 8.2V to 45V
Coil current without cooling about 1A about 1.5A
Coil current with cooling 2A 2.2A
Finest step 1/16 1/32
VDD wire required, 3V3 on this board none

The base of a light arm is easy work, so the A4988 is enough. If a heavier arm asks for more current, look at the DRV8825. And if your base has a plain DC motor with two wires, neither of them fits: take an H-bridge such as the one in ESP32 S3 Uno - BTS7960 Motor Driver.

HOME is only a number

The ESP32 S3 Uno counts the pulses it sends. It cannot feel the shaft. If somebody holds the arm, or if you move it while the power is off, the counter and the real angle no longer agree, and nothing tells the sketch. The usual cure is a homing run: turn slowly toward a switch, stop at the click and call that place step 0.

Ideas for the arm base

  1. Homing run: mount a lever switch beside the base and read it as in ESP32 S3 Uno - Limit Switch. At the click, call armBase.setCurrentPosition(0).
  2. Steer by hand: turn the stick of ESP32 S3 Uno - Joystick into a target angle for moveTo().
  3. Add a gripper: open it at PLACE and close it at PICK with a small servo, see ESP32 S3 Uno - Servo Motor.
  4. Teach new stops: dial the base to a spot with ESP32 S3 Uno - Rotary Encoder and store the step number when you press the knob.
  5. Buttons on the phone: make PICK, PLACE and HOME three links of a small site, with the code of ESP32 S3 Uno - Web Server.

FAQ

VDD accepts up to 5.5V. What is wrong with the 5V pin?

The A4988 would be fine with it, but your signals would not. The bar for a HIGH moves up to 3.5V, and a pin of the ESP32 S3 Uno ends at 3.3V. Some pulses may count and others may not, so the base would stop at the wrong angle.

Where do the numbers 17 and 18 in the code come from?

They are the GPIO numbers behind the header names: D3 is GPIO17 and D2 is GPIO18. If you write 3 and 2 in the sketch, the pulses come out of other pins of the chip, and the motor stays still.

Why can I not move the arm by hand while the program rests?

The driver keeps the coils under current and holds the base. To let go of it, wire the EN row to D8 (GPIO21) and write HIGH to 21. LOW grips again. A hand that moves the arm in between is invisible to the step counter, so do a new homing run after that.

Can the same ESP32 S3 Uno run the shoulder motor too?

Yes. Each motor needs its own A4988 with its own STEP and DIR pins, for example D8 (GPIO21) for STEP and D7 (GPIO14) for DIR. The 3V3, GND and 12V wires are shared, as long as the adapter can feed both motors. In the second program, create one more AccelStepper object and call its run() in loop() as well.

Is the USB cable not enough to power the motor?

No. VMOT starts at 8V, and USB brings 5V. The cable feeds the ESP32 S3 Uno, and over its 3V3 pin the logic half of the driver. The muscle power always comes from the adapter.

Troubleshooting

Problem Possible Cause Solution
Text scrolls in the Serial Monitor, but the shaft does not move VDD gets no 3.3V, or the driver is held in reset Check the wire from 3V3 to V (or VDD). On the bare module, look at the RST-SLP link
The shaft is easy to turn by hand with the 12V adapter plugged in No motor power, or EN is HIGH Check VIN and GND, the DC power jack and that the EN row is free
Motor buzzes and shivers on the spot The coil pairs are mixed up, or VREF is too low Unplug 12V, search for the wire pairs again, then raise VREF a little
Short moves work, quick long ones stall Speed or acceleration is too high Make SPEED_GAIN and TOP_SPEED smaller, or PULSE_HALF bigger in the first sketch
PICK and PLACE are on the wrong sides One coil is connected the other way round Unplug 12V and exchange the two wires of one coil, for example on 1A and 1B
The base stops at half or twice the angle The DIP switches do not fit the MICROSTEPS number Compare with the step size table, and remember that MS1 has switch 3
The driver is too hot, or it pauses and starts again VREF is set too high Lower VREF, glue on the heat sink, let air reach it
The stops wander away after some minutes The motor skips steps under the load Use a smaller SPEED_GAIN, raise VREF within the motor rating, add a homing run
Arduino IDE shows no port for the board The cable carries only power, or the USB chip has no driver on the computer Try another cable, install the CH340 or CP210x driver, or press RESET with BOOT held down
The Serial Monitor shows only symbols It listens at another speed than 9600 Choose 9600 baud at the top right of the Serial Monitor

Learn More

※ 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!