
Stepper Motion Profiles with ESP32 and TB6600 - Proteus Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the Stepper Motion Profiles with ESP32 and TB6600 - Proteus Simulation, the seventy-fifth project of our IoT Projects series. If you have searched for stepper motor acceleration, trapezoidal and S-curve motion profiles, why a stepper loses steps, or an ESP32 driving a NEMA 23 through a TB6600 in a Proteus simulation, here is a complete one. A stepper motor is the heart of every 3D printer, CNC router and laser cutter because it moves an exact distance for every pulse it gets, with no sensor at all. But that promise holds only while the motor can keep up. Ask it for too much speed too soon and it falls behind, loses steps, and the controller never finds out.
This ESP32 drives a NEMA 23 through a TB6600 microstepping driver and makes the same 10-turn move four ways: with no ramp at all, with a gentle trapezoid, with a steep trapezoid and with an S-curve. In this tutorial, we will go through the circuit, microstepping and the pulse rate, why a stepper cannot start at full speed, the trapezoidal profile and its formula, the S-curve and jerk, and how an ESP32 times thousands of pulses a second with micros(). Then we run all four in the simulation, plus one more with a load on the shaft, and let the motor's own pop-up count the steps the ESP32 cannot see. At the end, you can download the project with the sketch and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the stepper motion profiles with ESP32 and TB6600 in Proteus simulation:
What Does This Stepper Project Do?
- Drives a NEMA 23 through a TB6600: step, direction and enable signals from the ESP32, 1/8 microsteps, 1600 pulses a turn, 2.8 A in the coils from 24 V.
- Makes the same move four ways: 10 turns at up to 300 RPM, with no ramp, a trapezoid, a steep trapezoid and an S-curve.
- Times every pulse: up to 8000 pulses a second, against an ideal schedule with micros(), and measures how late the worst one came.
- Draws each move: its speed against time on the OLED and on the dashboard.
- Shows the open loop: the ESP32 counts the pulses it sent; only the motor's pop-up knows how many steps really arrived.
- Adds a load: a torque on the shaft, to see how much margin the ramp leaves.
It is a great project for learning stepper motors, motion control and real-time pulse timing in one go. In the simulation, the NEMA 23 is a physical model, with its coil torque, its detent torque, its rotor's inertia, friction and a load. Its pop-up shows the shaft's angle, the speed, the position and the lost steps, and the TB6600's pop-up counts every pulse it receives. Between them, they judge every move independently of the ESP32.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| ESP32 DevKit V1 | ESP32 DEVKIT V1 | ESP32 DevKit V1 Library for Proteus | U1, ESP32_Stepper_Profiles.hex, TEP-WiFi 192.168.1.101 |
| TB6600 stepper driver | TB6600TEP | TB6600 Stepper Motor Driver Library for Proteus | DRV1: PUL+ D25, DIR+ D26, ENA+ D27, VCC +24V, 1/8, 2.8 A |
| NEMA 23 stepper motor | NEMA23STEPPERTEP | NEMA 23 Stepper Motor Library for Proteus | M1 on A+ A- B+ B- |
| SSD1306 OLED 0.96" 128x64 | OLED12864WHITEADVTEP | OLED SSD1306 Library for Proteus | OLED1, I2C at 0x3C |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the Stepper Profiles: the Circuit
| TB6600 pin | Connection | Meaning |
|---|---|---|
| PUL+ / PUL- | D25 / GND | one pulse = one microstep |
| DIR+ / DIR- | D26 / GND | the direction, set before the pulses |
| ENA+ / ENA- | D27 / GND | LOW = enabled (the motor held) |
| VCC / GND | +24V / GND | the motor supply |
| A+ A- B+ B- | the NEMA 23's wires | the two coils |
The TB6600's inputs are optocouplers, so the ESP32 never touches the motor's 24 V. This project wires them common cathode: every minus pin on ground, the ESP32's pins on the plus pins. A pulse on PUL+ moves the motor one microstep; DIR+ sets the direction; ENA+ held low keeps the driver enabled and the motor held in place. The driver's outputs go straight to the motor's four wires, in the same order. On the driver, three DIP switches set 1/8 microsteps and three more set 2.8 A, the motor's rated current. The OLED shares the ESP32's I2C bus.
How Stepper Motion Profiles Work
Steps, Microsteps and the Pulse Rate
A NEMA 23 like this one moves 1.8 degrees per full step, 200 steps a turn. With 1/8 microstepping, the TB6600 splits each step into eight smaller ones by setting the two coil currents to the sine and cosine of the angle, so the motor needs 1600 pulses a turn and runs much more smoothly. Speed is simply the pulse rate. Worked example: 300 RPM is 5 turns a second, so 5 x 1600 = 8000 pulses a second, one every 125 microseconds. Ten turns is 16,000 pulses.
Why a Stepper Cannot Start at Full Speed
Each pulse moves the magnetic field one microstep ahead, and the rotor follows it, pulled by the coils' torque. But the rotor has inertia: it needs time to speed up. If the field jumps ahead faster than the rotor can follow, the rotor falls more than two full steps behind, the pull reverses, and the rotor slips back a whole cycle of the coil currents, four full steps. With a light load it may catch the field again and run on, but the slipped steps are gone for good; with more load or speed it never catches up, and it just vibrates while the pulses run away from it. Worked example: starting at 300 RPM from standstill means reaching 31.4 radians a second within the first pulse, 125 microseconds, an acceleration of about 250,000 rad/s squared. No motor can do that with its rotor, let alone with a load. And the motor's torque falls as it speeds up, because the 24 V supply can push less and less current into the coils against the voltage the spinning rotor itself generates (the back-EMF). So the speed must rise gradually, and the torque the ramp needs, the rotor's inertia times the acceleration plus the load, must stay inside the torque the motor has at each speed.
The Trapezoidal Profile
The classic answer is a constant acceleration up to the top speed, a cruise, and the same deceleration down: a speed curve shaped like a trapezoid. For a constant acceleration a, the speed after a distance s is v = sqrt(v0 x v0 + 2 x a x s), so the sketch can compute the speed for every single pulse. Worked example for the TRAP move: a = 10 turns per second squared, 16,000 pulses/s squared, starting from v0 = 200 pulses a second. The ramp to 8000 pulses a second takes (8000 - 200) / 16,000 = 0.49 s and covers (8000 x 8000 - 200 x 200) / (2 x 16,000) = 1999 pulses, 1.25 turns. The cruise is 16,000 - 2 x 1999 = 12,002 pulses, 1.5 s, and the whole move takes about 2.5 s. The STEEP move uses 200 turns per second squared: its ramp is only 25 ms and 100 pulses long.
The S-Curve and Jerk
A trapezoid has a weakness at its corners: the acceleration jumps from zero to its full value in an instant. A sudden change of acceleration is called jerk, and it is what makes machines ring, belts slap and parts wobble. An S-curve rounds those corners, so the acceleration rises smoothly from zero, peaks in the middle of the ramp and falls back to zero before the cruise. This sketch shapes the square of the speed along a smooth step of the ramp distance, 3x squared - 2x cubed, whose slope is zero at both ends. Its peak acceleration is 1.5 times its average, so to keep the same peak as the trapezoid, the S-curve ramp is 1.5 times longer: 2998 pulses, 1.87 turns. And because its acceleration starts from zero, it creeps at first. The price of smoothness is time: 3.58 s planned for the same 10 turns, against 2.47 s for the trapezoid.
Timing Thousands of Pulses
At 8000 pulses a second there are only 125 microseconds between pulses, and the ESP32 must work out each pulse's speed in that time. The sketch keeps an ideal schedule: each pulse has a due time, the next one is due one period later, and the loop waits with micros() until it arrives. A pulse that comes a little late does not push the rest of the schedule back. But if one comes more than two periods late, the schedule starts again from now, because catching up would mean a burst of pulses faster than the rotor can follow. To stay inside the budget, the cruise needs no maths at all (its period is fixed), and the bookkeeping, the peak and the curve for the display, happens only every 16 pulses. The whole move holds the loop, so the web server answers again only when the motor has stopped.
The Arduino Code Explained
The sketch is ESP32_Stepper_Profiles.ino, written in the Arduino IDE for the ESP32 DevKit V1. It uses Adafruit SSD1306 for the OLED and WiFi and WebServer for the dashboard; the pulses need no library. The pulse rate and the accelerations:
const float V_MAX = 300.0 / 60 * PER_TURN; // 300 RPM = 8000 pulses a second
const float A_TRAP = 10.0 * PER_TURN, A_STEEP = 200.0 * PER_TURN; // pulses/s2 (10 and 200 turns/s2)
The trapezoid, from the distance to the nearer end of the move:
float s = min(i + 1, MOVE - i); // the distance from the nearer end of the move
return sqrt(V0 * V0 + 2 * a * s); // the trapezoid: v^2 = v0^2 + 2 a s
The S-curve's smooth step, and its longer ramp:
float x = s / sr, k = x * x * (3 - 2 * x); // the smooth step: slope 0 at both ends
return p == SCURVE ? s * 1.5 : s; // (the S-curve's peak acceleration = 1.5 x its average)
The direction first, then the pulses on their schedule:
delayMicroseconds(10); // (the TB6600 wants DIR 5 us before PUL)
while ((long)(micros() - due) < 0) {}
digitalWrite(PUL, HIGH); delayMicroseconds(5); digitalWrite(PUL, LOW);
due += period;
And when the loop falls far behind, it does not try to catch up:
if (late > (long)(2 * period)) due = micros(); // (far behind: start the schedule again from now - catching up
// in a burst of pulses would be too fast for the rotor: lost steps)
The ESP32 keeps its own count, and that is all it knows:
position += dir * MOVE;
After each move, the OLED shows the profile, its peak speed, the time and the position, and below them the move's speed against time, 64 columns. A report line goes to the serial monitor. The dashboard's links start the moves: TRAP, JUMP, STEEP, S-CURVE and BACK (TRAP the other way). The pages are / (the dashboard), /profile.bmp (the OLED's curve, twice as big) and /data (JSON).
How to Run the Proteus Simulation
- Download the project zip below and install the library files (the steps are under the download button).
- Open ESP32-Stepper-Profiles.pdsprj from the Proteus Simulation folder. Keep the HEX file and the DLL files next to it.
- Press Play. The TB6600 holds the motor.
- Open the Laptop or the Mobile WiFi Monitor, press Go, then click TRAP, JUMP, STEEP and S-CURVE one after another, watching the NEMA 23's pop-up (M1).
- On M1's pop-up press 80 N.cm and click TRAP again.
Simulation Results: the Stepper Profiles in Proteus
We ran all five moves in one simulation, each 10 turns forward from the dashboard on the Laptop WiFi Monitor, and after every move we read the NEMA 23's own pop-up. The ESP32 only knows the pulses it sent; the motor's pop-up knows where the shaft really is.
1. TRAP: the Gentle Trapezoid
1. TRAP forward 10 turns: ramp 1.25 turns, peak 300 RPM, 2.469 s (planned 2.469 s), worst pulse 239 us late; the ESP32 is at 10.00 turns
The move took exactly the planned 2.469 s: 0.49 s of ramp, 1.5 s of cruise at 300 RPM and the same ramp down, as worked out above. The worst pulse came 239 microseconds late, near the top of the ramp, where the pulses are close together and each one still needs its square root; the schedule absorbed it, and the cruise, which needs no maths at all, caught up the time.
The motor agrees with the ESP32 to the step: 10.00 turns, holding at 360.0 degrees, 2000 full steps, and 0 lost steps. (The minus sign on its turns is only the pop-up's sense of direction.) Both coils carry 2.05 A, which is 2.9 A times 0.707: the motor stopped half-way between two full steps, at 45 electrical degrees, exactly as 1/8 microstepping puts it.
The TB6600's pop-up counted all 16,000 pulses, 1600 a turn at 1/8 step, and now holds the motor with 0.55 A from the 24 V supply. Its DIP switch table shows the setting: 1/8 microsteps and 2.8 A (2.9 A peak).
The OLED and the dashboard draw the same curve: the speed against time, a clean trapezoid. The dashboard adds the acceleration, 10 turns/s2, and a reminder that the ESP32 has sent 10.00 turns of pulses but cannot see a lost step.
2. JUMP: 300 RPM From the First Pulse
2. JUMP forward 10 turns: ramp 0.00 turns, peak 300 RPM, 2.000 s (planned 2.000 s), worst pulse 12 us late; the ESP32 is at 20.00 turns
Without a ramp, the move is faster on paper, 2.000 s, and the timing is perfect: the worst pulse only 12 microseconds late, because a constant period needs no maths. The ESP32 reports 20.00 turns and is perfectly happy. The motor is not:
Eight full steps lost, and the shaft at 14.4 degrees instead of 0: 8 x 1.8 = 14.4 degrees short, 19.96 turns instead of 20. The field started at 8000 pulses a second and the rotor could not follow; it slipped back twice, four full steps each time, one whole cycle of the coil currents, and then caught the field and ran on. In a way, that is the worst kind of failure: the move looks fine, nothing stalls, and the machine is now 14.4 degrees off. Every unramped start would add more.
The dashboard shows acceleration 0 and 20.00 turns of pulses sent; nothing on the ESP32's side reveals the eight missing steps. Only an encoder, or a homing switch at the next start, would find them.
3. STEEP: a 25 ms Ramp
3. STEEP forward 10 turns: ramp 0.06 turns, peak 300 RPM, 2.020 s (planned 2.021 s), worst pulse 120 us late; the ESP32 is at 30.00 turns
A ramp of only 25 ms and 100 pulses, 200 turns/s2, and the motor follows it: the lost steps stay at 8, all from the jump, and the shaft still sits at 14.4 degrees, now at 29.96 turns. The move costs only 20 ms more than the jump. So the rotor did not need a long ramp, only some ramp: the jump asked for its full speed within 125 microseconds, the steep ramp gave it 25 ms.
4. S-CURVE: the Smooth Ramp
4. SCURVE forward 10 turns: ramp 1.87 turns, peak 300 RPM, 3.731 s (planned 3.578 s), worst pulse 364 us late; the ESP32 is at 40.00 turns
Again no new lost steps: 39.96 turns, still the jump's 8. The S-curve took longer, as expected, and then a little more: 3.731 s against the planned 3.578 s. Near the top of its ramp the pulses are about 130 microseconds apart, and the S-curve's maths for each pulse (a division for the position in the ramp, the smooth step, a square root and the division for the period) needs more than that in the simulation. The pulses fell behind, the worst by 364 microseconds, more than two periods, so the sketch restarted its schedule instead of firing a burst. The top of the ramp simply ran a little slower than planned, which is always safe for a stepper, and the move took 0.15 s longer. On a real machine, a hardware timer that makes the pulses while the maths runs ahead is the usual cure.
Compare the curve with the trapezoid's: the corners are rounded, the ramp starts gently, is steepest in the middle and eases into the cruise. That is what a machine's frame and belts will thank you for.
5. TRAP Again With an 80 N.cm Load
Finally, we pressed 80 N.cm on M1's pop-up, about two thirds of the motor's 126 N.cm holding torque, and clicked TRAP again:
5. TRAP forward 10 turns: ramp 1.25 turns, peak 300 RPM, 2.469 s (planned 2.469 s), worst pulse 239 us late; the ESP32 is at 50.00 turns
The gentle trapezoid carries the load: 49.96 turns, still only the jump's 8 lost steps. The shaft now sits at 14.5 degrees, a hair further from the field, because the coils must hold the load. So the 10 turns/s2 ramp leaves a real margin: the rotor's inertia plus 80 N.cm still fits inside the torque the motor has up to 300 RPM. That margin is what a real machine needs for friction, a stiff belt or a heavier carriage.
The phone shows the same dashboard, with its links as buttons. And the serial monitor holds the whole story, one line per move:
| Move | Ramp | Time (planned) | Worst pulse | Lost steps (M1) |
|---|---|---|---|---|
| TRAP | 1.25 turns | 2.469 s (2.469 s) | 239 us late | 0 |
| JUMP | none | 2.000 s (2.000 s) | 12 us late | 8 (14.4 degrees) |
| STEEP | 0.06 turns | 2.020 s (2.021 s) | 120 us late | no new |
| S-CURVE | 1.87 turns | 3.731 s (3.578 s) | 364 us late | no new |
| TRAP + 80 N.cm | 1.25 turns | 2.469 s (2.469 s) | 239 us late | no new |
The ESP32 believes it moved the shaft 50.00 turns. The motor moved 49.96. The difference, 8 full steps, came from the one move without a ramp, and nothing in an open-loop controller will ever report it. That is the whole case for motion profiles in one table.
Download the Project Files
Click the button below to download Stepper-Motion-Profiles-ESP32-TB6600-Proteus-Simulation-v1.0.zip (about 3.7 MB, without the source code of the models):
Stepper Motion Profiles with ESP32 and TB6600 - Proteus Simulation V1.0- Proteus Simulation: ESP32-Stepper-Profiles.pdsprj, ESP32_Stepper_Profiles.hex and copies of the models.
- Arduino Code: ESP32_Stepper_Profiles.ino, the sketch.
- Proteus Library Files: the LIB files of the ESP32 DevKit V1, the TB6600, the NEMA 23, the OLED and the two WiFi Monitors.
- Proteus Model Files: the DLL models.
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files from Proteus Model Files into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
Open ESP32_Stepper_Profiles.ino in the Arduino IDE with the TEP boards for Proteus installed, compile it, export the compiled binary and set U1's PROGRAM property to the new HEX file. The top speed, the starting rate, the two accelerations, the move's length and the microsteps are at the top; if you change the microsteps, set the TB6600's MICROSTEP property to match.
Ideas to Extend the Project
- Add an encoder to the shaft and compare the counted pulses with the real position after every move: closed-loop stepping.
- Find the fastest safe acceleration automatically: raise it move by move until steps are lost, then back off by a margin.
- Add a homing switch and a soft limit, as on a real CNC axis.
- Coordinate two axes so they start and stop together on a straight line.
- Replace the polled timing with a hardware timer interrupt so the web server keeps working during a move.
- Try the other microstep settings and compare the smoothness and the top speed.
From Simulation to Real Hardware
- Mind the input levels: many TB6600 boards want 5 V on their optocoupler inputs; with a 3.3 V ESP32, use a level shifter or a transistor, or check that your board switches at 3.3 V.
- Size the supply: 24 V gives the motor its torque at speed; a higher voltage within the driver's rating gives more top speed.
- Set the current right: the motor's rated current on the DIP switches; more makes it hot, less makes it weak.
- Leave a margin: real machines lose torque to friction, belts and resonance; use about half of the acceleration that just works on the bench.
- Watch for resonance: steppers ring at certain speeds; microstepping and a quick pass through those speeds help.
Troubleshooting
- The motor never turns: the TB6600 needs VCC on +24V and its minus inputs on GND; ENA+ low means enabled.
- The motor buzzes but stays put: it was asked to start too fast; that is the JUMP move's lesson; use a ramp.
- The ESP32's position and the motor's differ: steps were lost; the ESP32 counts pulses, not turns.
- The dashboard is slow during a move: the move holds the loop on purpose; the page answers when the motor stops.
- The OLED stays blank: SDA / SCL on D21 / D22, address 0x3C, VCC on 3.3 V.
Limitations of the Simulation
- The motor and the driver are our libraries' models: the NEMA 23's torque, inertia, detent and friction and the TB6600's current control are simplified, so the exact limits of a real pair differ.
- There is no machine on the shaft, only the load the pop-up adds; real belts and screws add their own inertia and friction.
- The pulse timing runs on the ESP32's main loop; a real CNC controller uses hardware timers.
- The network to the laptop and the phone is simulated inside Proteus.
- ESP32 is a product of Espressif Systems; this project is not made or endorsed by them or by Labcenter.
So, that was all about the Stepper Motion Profiles with ESP32 and TB6600 - Proteus Simulation, and with it the last of these twenty-five IoT projects. I hope it helps you understand why a stepper motor needs a ramp, how trapezoidal and S-curve profiles are computed pulse by pulse, how an ESP32 times thousands of pulses a second, and why an open-loop stepper can lose steps without anyone noticing, all tested in a simulation before you build a real machine. More projects with the ESP32 and the Raspberry Pi 5 are coming. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!






















Comments
0