Build a Low-Voltage Motion Controller Demo
The Story
Real CNC machines need serious safety systems. This project limits the scope to STEP/DIR learning with one bench motor and no spindle. The Golden version keeps the implementation narrow and testable: code constants, wiring, GPIO notes, expected output, limitations, and troubleshooting all describe the same educational prototype.
Explain Like I'm 12
The ESP32 does not push the motor directly. It sends tiny step and direction messages to a driver board, and the driver powers the motor. The ESP32 reads a signal, checks it against a simple rule, and prints or changes an output so you can see what happened.
Learning Support
- Recommended ageAges 14+
- Adult supervisionAdult supervision required around motors, drivers, heat, and moving parts.
- Classroom useUse an unloaded stepper motor on the bench; do not attach cutting tools or pinch hazards.
- Parent promptAsk why the ESP32 sends signals but does not power the motor coils.
- Screen-free activityDraw the STEP, DIR, ENABLE, logic power, motor power, and common ground paths.
- Next challengeAdd limit switches and an emergency-stop strategy before any multi-axis motion.
- Skills practiced
- STEP/DIR signaling
- External motor driver
- Current limiting
- Motion safety
- Learning outcomes
- Generate STEP and DIR pulses from safe GPIOs.
- Wire A4988 logic separately from motor power.
- Explain common ground and VMOT decoupling.
- State why this is not a complete CNC controller.
- Mini experiments
- Send F200 and B200 commands.
- Change step delay from 1000 us to 2000 us.
- Disable the driver between moves and observe heat.
Safety Standards
- Unplug USB before changing jumper wires. Recheck 3.3 V, 5 V, and GND before reconnecting power.
- Do not power motors, pumps, LED strips, or servos from the ESP32 3.3 V pin. Use a suitable external supply and common ground.
- Breadboards are for low-current prototypes. Move high-current or unattended builds to proper terminals, enclosure, strain relief, and fusing.
- Motors and servos can reset the ESP32 when they draw surge current. Use a separate motor supply, driver module, and flyback protection where needed.
What You Will Build
A low-voltage single-axis motion demo where ESP32 GPIO14/GPIO27/GPIO26 control an A4988 driver connected to a stepper motor.
Learning Objectives
- Generate STEP and DIR pulses from safe GPIOs.
- Wire A4988 logic separately from motor power.
- Explain common ground and VMOT decoupling.
- State why this is not a complete CNC controller.
Components List
- ESP32 DevKit boardUSB-programmable ESP32 board used for the low-voltage control side.
- A4988 stepper driver moduleExternal driver for STEP/DIR control.
- NEMA 17 stepper motorBench motor only; set current limit before use.
- 12 V motor supplySeparate motor power for VMOT.
- 100 uF electrolytic capacitorAcross VMOT and GND near the driver.
Bill of Materials
| Part | Qty | Estimated Cost | Notes |
|---|---|---|---|
| ESP32 DevKit board | 1 | Varies | USB-programmable ESP32 board used for the low-voltage control side. |
| A4988 stepper driver module | 1 | Varies | External driver for STEP/DIR control. |
| NEMA 17 stepper motor | 1 | Varies | Bench motor only; set current limit before use. |
| 12 V motor supply | 1 | Varies | Separate motor power for VMOT. |
| 100 uF electrolytic capacitor | 1 | Varies | Across VMOT and GND near the driver. |
Wiring
GPIO14 is STEP, GPIO27 is DIR, GPIO26 is ENABLE. A4988 VMOT uses a separate motor supply with common ground.
-
1
Unplug USB and motor supply before rewiring.
-
2
Connect STEP to GPIO14, DIR to GPIO27, and EN to GPIO26.
-
3
Connect A4988 VDD to ESP32 3.3 V and logic GND to ESP32 GND.
-
4
Connect motor supply positive to VMOT and motor supply ground to driver GND, with a 100 uF capacitor across VMOT/GND.
-
5
Connect motor coils to 1A/1B and 2A/2B using the motor datasheet.
-
6
Set current limit before running motion commands.
GPIO Mapping
| Signal | ESP32 Pin | Direction | Notes |
|---|---|---|---|
| A4988 STEP | GPIO14 | Output | One pulse per microstep/full step. |
| A4988 DIR | GPIO27 | Output | Direction signal. |
| A4988 ENABLE | GPIO26 | Output | LOW enables driver; HIGH disables. |
Circuit Explanation
The ESP32 sends logic-level signals to the A4988. Motor current comes from VMOT, not from ESP32 pins.
Engineering Explanation
The demo uses bounded step counts and simple timing. Real CNC needs limit switches, emergency stop, acceleration planning, shielding, grounding, and enclosure design.
Libraries
- Arduino ESP32 coreNo extra libraries required for this STEP/DIR demo.
Code
Copy into Arduino IDE. Install any libraries noted in the component guides first.
// ESP32 Low-Voltage CNC Motion Controller Demo
// Single-axis STEP/DIR output for an A4988 driver. Not a complete CNC controller.
const int STEP_PIN = 14;
const int DIR_PIN = 27;
const int EN_PIN = 26;
long stepDelayUs = 1000;
void stepMotor(long steps, bool forward) {
if (steps <= 0 || steps > 5000) {
Serial.println("Step count must be 1..5000 for this demo.");
return;
}
digitalWrite(EN_PIN, LOW);
digitalWrite(DIR_PIN, forward ? HIGH : LOW);
for (long i = 0; i < steps; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(stepDelayUs);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(stepDelayUs);
}
digitalWrite(EN_PIN, HIGH);
}
void setup() {
Serial.begin(115200);
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, HIGH);
Serial.println("Low-voltage stepper motion demo ready.");
Serial.println("Commands: F<steps>, B<steps>, S<delay_us 500..5000>");
}
void loop() {
if (!Serial.available()) return;
char cmd = Serial.read();
long val = Serial.parseInt();
if (cmd == 'F') stepMotor(val, true);
else if (cmd == 'B') stepMotor(val, false);
else if (cmd == 'S' && val >= 500 && val <= 5000) {
stepDelayUs = val;
Serial.printf("Step delay set to %ld us\n", stepDelayUs);
}
}
Code Explanation
Serial commands F and B move bounded step counts. S changes step delay within a safe range. ENABLE is disabled after each move.
Expected Output
Serial Monitor accepts F200, B200, and S1000 style commands. The motor moves one direction, reverses, and then disables between moves.
Troubleshooting
- Motor vibrates but does not turn Check coil pairs and reduce speed by increasing step delay.
- A4988 overheats Disable power and lower the current limit.
- No motion Check ENABLE polarity, common ground, and VMOT supply.
Common Mistakes
- Driving motor coils from ESP32 pins.
- Running without setting A4988 current limit.
- Forgetting common ground.
- Calling this GRBL or production CNC.
Testing Checklist
- Verify logic wiring with motor supply off.
- Set A4988 current limit.
- Run F200 and B200 with an unloaded motor.
- Confirm driver disables after motion.
Engineering Tips
- Use current-limited supplies.
- Keep fingers away from moving shafts.
- Add limit switches before multi-axis experiments.
Upgrade Ideas
- Add limit switch inputs.
- Add acceleration ramping.
- Add a second axis only after single-axis safety is proven.
Real-World Applications
- Stepper motor lesson
- Motion-control prototype
- CNC safety discussion
FAQs
Is this GRBL?
No. It is a simple STEP/DIR learning sketch.
Can it run a spindle?
No. Spindle and real CNC safety are out of scope.
Why separate motor power?
The ESP32 cannot supply stepper motor current.
Review, Testing, and References
Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-06-27. Reviewed: wiring logic, Arduino code structure, beginner safety, and learning sequence.
Educational level: Advanced. Estimated completion time: 90-120 min. This project is for learning and prototyping; production or unattended hardware needs additional engineering review.
Project Complete!
You completed Build a Low-Voltage CNC Motion Controller Demo as a safe, bounded ESP32 learning build with matching wiring, code, tests, and limitations.
- STEP/DIR signaling
- External motor driver
- Current limiting
