TB6600 stepper driver on an Arduino Uno
A NEMA 23 on a TB6600 wired common cathode to pins 2, 3 and 4: a turn forward, half a turn back, then offline with ENA, at 1/8 step. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 25 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $51. On Mokxi they're free.
What you'll learn
- Step and direction control of a stepper
- Microstepping and matching the driver switches
- Optocoupled inputs with a common cathode
- Enable and disable to free the shaft
- Powering a motor from a separate supply
- Difficulty: Intermediate
- Time: About 25 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
A TB6600 is a stepper motor driver with optocoupled inputs. The Uno's pins 2, 3 and 4 go to PUL+, DIR+ and ENA+, and the three minus inputs all go to ground (common cathode). The motor runs from a 24 V supply through the driver.
The driver's switches are set to 1/8 step, and the sketch tells the library the same, so each turn takes 1600 pulses. The StepperDriver style library handles the pulse timing at 120 rpm.
Each loop does one turn forward, half a turn back, then disables the driver for a second so the shaft is free, and enables it again.
Parts list
4 parts, plus the jumper wires. They retail for about $51; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × TB6600 stepper driver
- 1 × Stepper motor, NEMA 17
- 1 × Power, 24 V
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| TB6600 stepper driver pin ENA- | Arduino Uno R3 pin GND |
| TB6600 stepper driver pin DIR- | Arduino Uno R3 pin GND |
| TB6600 stepper driver pin PUL- | Arduino Uno R3 pin GND |
| TB6600 stepper driver pin ENA+ | Arduino Uno R3 pin 4 |
| TB6600 stepper driver pin DIR+ | Arduino Uno R3 pin 3 |
| TB6600 stepper driver pin PUL+ | Arduino Uno R3 pin 2 |
| Stepper motor, NEMA 17 pin B2 | TB6600 stepper driver pin B- |
| Stepper motor, NEMA 17 pin B1 | TB6600 stepper driver pin B+ |
| Stepper motor, NEMA 17 pin A2 | TB6600 stepper driver pin A- |
| Stepper motor, NEMA 17 pin A1 | TB6600 stepper driver pin A+ |
| TB6600 stepper driver pin GND | Ground |
| TB6600 stepper driver pin VCC | 24 V |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A NEMA 23 on a TB6600 driver, from an Uno, with the StepperDriver library.
//
// TB6600 PUL+ -> pin 2 DIR+ -> pin 3 ENA+ -> pin 4
// TB6600 PUL- DIR- ENA- -> GND (common cathode)
// TB6600 VCC / GND -> 24 V, A+ A- and B+ B- -> the motor's two coils
//
// Each input is an optocoupler: a pin driven high lights it. The DIP switches
// are set to 1/8 step and 2.8 A, so a 200 step motor takes 1600 pulses a turn,
// and begin() is told the same 8. ENA lit is offline, so the enable is active
// LOW in this wiring: disable() lets the shaft go free.
#include <TB6600.h>
const int MOTOR_STEPS = 200;
const int DIR_PIN = 3;
const int PUL_PIN = 2;
const int ENA_PIN = 4;
TB6600 stepper(MOTOR_STEPS, DIR_PIN, PUL_PIN, ENA_PIN);
void setup() {
Serial.begin(9600);
stepper.setEnableActiveState(LOW);
stepper.begin(120, 8);
stepper.enable();
Serial.println("Mokxi Uno: TB6600 at 1/8 step, 120 rpm");
}
void loop() {
stepper.rotate(360);
Serial.println("one turn forward");
delay(500);
stepper.rotate(-180);
Serial.println("half a turn back");
delay(500);
stepper.disable();
Serial.println("offline: the shaft is free");
delay(1000);
stepper.enable();
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
It opens serial, then calls setEnableActiveState(LOW) because the enable is active low in this wiring. stepper.begin(120, 8) sets 120 rpm and 1/8 microstepping, and stepper.enable() powers the coils. Then it prints a start message.
void setup() {
Serial.begin(9600);
stepper.setEnableActiveState(LOW);
stepper.begin(120, 8);
stepper.enable();
Serial.println("Mokxi Uno: TB6600 at 1/8 step, 120 rpm");
}loop sketch.ino
It calls stepper.rotate(360) for a turn forward, waits half a second, then rotate(-180) for half a turn back. Then stepper.disable() frees the shaft for a second before stepper.enable() locks it again. Each step prints a message.
void loop() {
stepper.rotate(360);
Serial.println("one turn forward");
delay(500);
stepper.rotate(-180);
Serial.println("half a turn back");
delay(500);
stepper.disable();
Serial.println("offline: the shaft is free");
delay(1000);
stepper.enable();
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The motor jitters or turns the wrong amount This project
The driver's DIP switches must match the microstep value instepper.begin(120, 8). Both must say 1/8. - The motor does not move at all This project
Check that the three minus inputs go to GND and that the 24 V supply is connected to the driver. - The motor does not turn or loses steps. TB6600 stepper driver
Set the DIP switches for the right current and microstep for your motor. Power the motor supply at 9 to 42 V, and join grounds. Do not hot plug the motor. - The control signals do nothing. TB6600 stepper driver
PUL, DIR and ENA are optocouplers needing a few milliamps. Use a resistor for 5 V or a larger one for 3.3 V logic as needed. Remember that ENA active turns the driver off. - The motor buzzes, shudders, or only vibrates instead of turning. Stepper motor
Coils are swapped. Find the two coil pairs by measuring resistance with a meter (a few ohms between wires of one coil). Connect each pair to one driver coil output, A to A and B to B. - The motor stalls or loses steps when you speed up. Stepper motor
A stepper cannot jump to a high speed. Start with slow step pulses and ramp up gradually. Check the driver current limit (Vref) and give the supply enough voltage, such as 12 V. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.