Wiring diagram:
![](https://harshasnmp.wordpress.com/wp-content/uploads/2022/12/tb6600-stepper-motor-driver-with-arduino-uno-wiring-diagram-schematic-768x564-1.jpg?w=768)
TB6600 Connections
TB6600 | Connection |
---|---|
VCC | 9 – 42 VDC |
GND | Power supply ground |
ENA- | Not connected |
ENA+ | Not connected |
DIR- | Arduino GND |
DIR+ | Pin 2 Arduino |
PUL- | Arduino GND |
PUL+ | Pin 3 Arduino |
A-, A+ | Coil 1 stepper motor |
B-, B+ | Coil 2 stepper motor |
TB6600 microstep settings
Microstep table
S1 | S2 | S3 | Microstep resolution |
---|---|---|---|
ON | ON | ON | NC |
ON | ON | OFF | Full step |
ON | OFF | ON | 1/2 step |
OFF | ON | ON | 1/2 step |
ON | OFF | OFF | 1/4 step |
OFF | ON | OFF | 1/8 step |
OFF | OFF | ON | 1/16 step |
OFF | OFF | OFF | 1/32 step |
Current table
Current (A) | Peak current | S4 | S5 | S6 |
---|---|---|---|---|
0.5 | 0.7 | ON | ON | ON |
1.0 | 1.2 | ON | OFF | ON |
1.5 | 1.7 | ON | ON | OFF |
2.0 | 2.2 | ON | OFF | OFF |
2.5 | 2.7 | OFF | ON | ON |
2.8 | 2.9 | OFF | OFF | ON |
3.0 | 3.2 | OFF | ON | OFF |
3.5 | 4.0 | OFF | OFF | OFF |
Arduino code:
/* Example sketch to control a stepper motor with TB6600 stepper motor driver and Arduino without a library: continuous rotation.
// Define stepper motor connections:
#define dirPin 2
#define stepPin 3
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// Set the spinning direction CW/CCW:
digitalWrite(dirPin, HIGH);
}
void loop() {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
Code 2:
/* Example sketch to control a stepper motor with TB6600 stepper motor driver and Arduino without a library: number of revolutions, speed and direction.
// Define stepper motor connections and steps per revolution:
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 1600
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(1000);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000);
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < 5 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < 5 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
}
Code with “AccelStepper” library:
/* Example sketch to control a stepper motor with TB6600 stepper motor driver, AccelStepper library and Arduino: acceleration and deceleration. More info: https://www.makerguides.com */
// Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// Set the maximum speed and acceleration:
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
}
void loop() {
// Set the target position:
stepper.moveTo(8000);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(1000);
// Move back to zero:
stepper.moveTo(0);
stepper.runToPosition();
delay(1000);
}