In this tutorial you will learn how to control a stepper motor using the TB6560 microstepping driver and Arduino. This driver is easy to use and can drive large stepper motors such as e.g3 AND THERE ARE NO 23.
I have attached a schematic and 2 sample codes. In the first example, I'll show you how to use this stepper motor driver without an Arduino library. In the second example, we'll take a look at the AccelStepper library. This library is pretty easy to use and allows you to accelerate and decelerate the stepper motor's movement.
After each example, I'll break down and explain how the code works, so you shouldn't have trouble adapting it to your needs.
If you are interested in learning more about other stepper motor drivers, the following articles may be helpful:
- TB6600 Stepper Motor Driver with Arduino Tutorial
- How to control a stepper motor with A4988 driver and Arduino
- 28BYJ-48 stepper motor with ULN2003 driver and Arduino tutorial
- How to control a stepper motor with Arduino Motor Shield Rev3
deliveries
hardware components
TB6560 Stepper Motor Driver | × 1 | Amazonas | |
Nema 23 stepper motor | × 1 | Amazonas | |
Arduino Uno Rev3 | × 1 | Amazonas | |
power adapter(24 Volt) | × 1 | Amazonas | |
jumper wires | × 4 | Amazonas | |
USB-Kabel Typ A/B | × 1 | Amazonas |
Tool
wire stripper | Amazonas | ||
Small screwdriver | Amazon | ||
Self-adjusting crimping tool(recommended)* | Amazonas | ||
Ferrule assortment(recommended)* | Amazonas |
*Hackadaywrote a great article on the benefits of using wire end sleeves (aka wire end sleeves).
Software
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide websites with an opportunity to earn advertising fees by advertising and linking to products on Amazon.com.
About the driver
ThatTB6560 Microstep Driveris built around the Toshiba TB6560AHQ chip and can be used to drive two-phase bipolar stepper motors.
With a maximum continuous current of 3A, the TB6560 driver can be used to drive fairly large stepper motors such as a NEMA 23. Be careful not to connect stepper motors with a rated current of more than 3A to the driver.
The chip has several built-in safety features such as overcurrent, undervoltage lockout, and overheat protection. However, it doesn't have reverse polarity protection, so make sure you connect the power supply correctly. See the table below for more specifications.
TB6560 specifications
operating voltage | 10 – 35 VDC, 24 VDC empfohlen |
Maximum output current | 3 A pro Phase, 3,5 A Spitze |
microstep resolution | full, 1/2, 1/8 and 1/16 |
Schutz | Low voltage shutdown, overheat and overcurrent protection |
Dimensions | 75 x 50 x 35 mm |
Lockheed | 69 x 43 mm, ⌀ 3,5 mm |
Cost | check price |
For more information, see the following data sheet/manual:
Toshiba TB6560 data sheet
TB6560 manual
Note that the TB6560 is an analog driver. In recent years, digital drivers have been like thatDM556orDM542have become much cheaper. Digital drivers usually offer much better performance and quieter operation. They can be wired and controlled in the same way as the TB6560, so you can easily upgrade your system later.
I have used the DM556 drivers for my DIY CNC router and they have worked great for several years.
TB6560 vs TB6600
When shopping for a TB6560 stepper motor driver, you will likely come across the slightly more expensive oneTB6600 driveras. This driver can be controlled with the same code/wiring, but there are some key differences.
TB6560 | TB6600 | |
---|---|---|
operating voltage | 10 – 35 VDC, 24 VDC empfohlen | 9 – 42 VDC, 36 VDC empfohlen |
Maximum output current | 3 A pro Phase, 3,5 A Spitze | 3,5 A pro Phase, 4 A Spitze |
# Current settings | 14 | 8 |
microstep resolution | full, 1/2, 1/8 and 1/16 | full, 1/2, 1/4, 1/8, 1/16 and 1/32 |
clock frequency | 15kHz | 200kHz |
Cost | check price | check price |
So the main differences are the higher maximum voltage, the higher maximum current and up to 1/32 microsteps. If you want to drive larger stepper motors or need higher resolution, I recommend the TB6600.
Wiring - Connecting TB6560 to Stepper Motor and Arduino
The following schematic shows you how to connect the TB6560 stepper motor driver to the Arduino and a stepper motor.

In this tutorial we will connect the driver in a common cathode configuration. That means we connect all the negative sides of the control signal terminals together to ground.
The connections are also indicated in the table below:
TB6560 connections
TB6560 | connection |
---|---|
VCC | 10 – 35 VDC |
Masse | ground of the power supply |
IN- | Not connected |
IN+ | Not connected |
CW- | Arduino-GND |
CW+ | Pin 2 Arduino |
CLK- | Arduino-GND |
CLK+ | Pin 3 Arduino |
A-, A+ | Coil 1 stepper motor |
B-, B+ | Coil 2 stepper motor |
Note that we left the enable pins (EN- and EN+) separate. This means that the enable pin is always LOW and the driver is always enabled.
How do I determine the correct stepper motor wiring?
If you can't find your stepper motor's datasheet, it can be difficult to figure out which colored wire goes where. I use the following trick to determine how to connect 4-wire bipolar stepper motors:
The only thing you need to identify are the two pairs of wires that connect to the motor's two coils. One coil's wires connect to A- and A+ and the other to B- and B+, polarity doesn't matter.
To find the two wires from a coil, with the motor disconnected, do the following:
- Try turning the stepper motor shaft by hand and notice how hard it is to turn.
- Now take a random pair of wires from the motor and touch the bare ends together.
- Next, while holding the ends together, try turning the stepper motor shaft again.
If you feel a strong resistance, you have found a pair of wires connected to the same coil. The other pair of wires is connected to the second coil.
If you can still rotate the shaft freely, try another pair of cables. Now connect the two coils to the pins shown in the schematic above.
(If it is still unclear, please leave a comment below, more information can also be found on theRepRap.org-Wiki)
TB6560 Microstepping Settings
Stepper motors typically have a step size of 1.8° or 200 steps per revolution, this refers to full steps. A microstepping driver like the TB6560 enables higher resolutions by allowing intermediate step locations. This is achieved by energizing the coils with medium levels of current.
For example, if you drive a motor in 1/2 step mode, at 200 steps per revolution the motor will get 400 microsteps per revolution.
You can change the TB6560's microstepping setting or excitation mode by turning on or off the DIP switches on the driver. See the table below for details. Make sure the driver is not connected to the power supply when setting the dip switches!
micro stepping table
S3 | S4 | microstep resolution |
---|---|---|
OUT | OUT | full step |
AN | OUT | 1/2 step |
AN | AN | 1/8 step |
OUT | AN | 1/16 step |
In general, a smaller microstep setting results in smoother and quieter operation. However, it limits the maximum speed you can achieve when controlling the stepper motor driver with an Arduino.
TB6560 current settings
You can adjust the current that flows to the running motor by turning on or off DIP switches SW1, SW2, SW3, and S1. I recommend starting with a current of 1A. If your motor is missing steps or stalls, you can always increase the amperage later.
Current Table
(A) | SW1 | SW2 | SW3 | S1 |
---|---|---|---|---|
0,3 | OUT | OUT | AN | AN |
0,5 | OUT | OUT | AN | OUT |
0,8 | OUT | AN | OUT | AN |
1 | OUT | AN | OUT | OUT |
1.1 | OUT | AN | AN | AN |
1.2 | AN | OUT | OUT | AN |
1.4 | OUT | AN | AN | OUT |
1.5 | AN | OUT | AN | AN |
1.6 | AN | OUT | OUT | OUT |
1.9 | AN | AN | OUT | AN |
2 | AN | OUT | AN | OUT |
2.2 | AN | AN | AN | AN |
2.6 | AN | AN | OUT | OUT |
39 | AN | AN | AN | OUT |
The stopping current is the current used to hold the motor shaft in a stopped position. You should set this as low as possible to minimize unnecessary motor heating. Increase this value if your motor cannot hold its position.
Stop current table
Stop the stream | S2 |
---|---|
20 % | AN |
50 % | OUT |
The decay setting has to do with how the driver chip deals with the back emf from the motor. The TB6560 Toshiba datasheet provides some explanation and diagrams of this setting. I usually leave the Decay mode at 0%. You can play around with this setting to see what gives the best results for your setup.
For reference, the TB6600 driver has a fixed decay setting of 40%.
Decay adjustment table
S5 | S6 | |
---|---|---|
0 % normal | OUT | OUT |
25 % | AN | OUT |
50 % | OUT | AN |
100% faster mode | AN | AN |
In the rest of this tutorial I will be using the driver in 1/8 microstepping mode with 1A run current, 20% stop current and 0% decay setting.
TB6560 Arduino example code
Now that you've wired up the driver and set the DIP switches, it's time to connect the Arduino to the computer and upload code. You can upload the following example code to your Arduino usingArduino-IDE. For this specific example, you don't need to install any libraries.
This sketch controls both the speed, the number of revolutions and the direction of rotation of the stepper motor.
You can copy the code by clicking the button in the top right corner of the code box.
/* Example sketch of controlling a stepper motor with TB6560 stepper motor driver and Arduino without library. More info: https://www.makerguides.com */// Define stepper motor connections and steps per revolution:#define dirPin 2#define stepPin 3#define stepsPerRevolution 1600void setup() { // Declare pins as output: pinMode( stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { // Set clockwise direction of rotation: digitalWrite(dirPin, HIGH); // Slowly rotate the stepper motor 1 revolution: for (int i = 0; i < stepsPerRevolution; i++) { // These four lines add up to 1 step: digitalWrite(stepPin, HIGH); delay microseconds (2000); digitalWrite(stepPin, LOW); delay microseconds (2000); } delay(1000); // Set counterclockwise direction of rotation: digitalWrite(dirPin, LOW); // Spin the stepper motor 1 revolution fast: for (int i = 0; i < stepsPerRevolution; i++) { // These four lines add up to 1 step: digitalWrite(stepPin, HIGH); delay microseconds (1000); digitalWrite(stepPin, LOW); delay microseconds (1000); } delay(1000); // Set clockwise direction of rotation: digitalWrite(dirPin, HIGH); // Spin the stepper motor 5 revolutions fast: for (int i = 0; i < 5 * stepsPerRevolution; i++) { // These four lines add up to 1 step: digitalWrite(stepPin, HIGH); delay microseconds (500); digitalWrite(stepPin, LOW); delay microseconds (500); } delay(1000); // Set counterclockwise direction of rotation: digitalWrite(dirPin, LOW); // Spin the stepper motor 5 revolutions fast: for (int i = 0; i < 5 * stepsPerRevolution; i++) { // These four lines add up to 1 step: digitalWrite(stepPin, HIGH); delay microseconds (500); digitalWrite(stepPin, LOW); delay microseconds (500); } delay(1000); }
How the code works:
The sketch begins by defining the step (CLK) and direction (CW) pens. I connected them to Arduino pin 3 and 2.
the statement#define
used to give a constant value a name. The compiler replaces all references to this constant with the defined value when the program is compiled. So everywhere you mention itdirPin
, the compiler will replace it with the value 2 when compiling the program.
I also defined asteps per revolution
Constant. Since I set the driver to 1/8 microstepping mode, I set it to 1600 steps per revolution. Change this value if your setup is different.
// Define stepper motor connections and steps per revolution:#define dirPin 2#define stepPin 3#define stepsPerRevolution 1600
Imto install()
In this section of code, all motor control pins are declared as digital OUTPUTS with the functionpinMode()
.
void setup() { // declare pins as output: pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT);}
ImRibbon()
In this section of code, we make the motor spin one revolution slowly clockwise and one revolution fast clockwise. Next we let the motor spin 5 revolutions in each direction at high speed. So how do you control the speed, direction of rotation and number of revolutions?
// Set clockwise direction of rotation: digitalWrite(dirPin, HIGH); // Slowly rotate the stepper motor 1 revolution: for(int i = 0; i <stepsPerRevolution; i++) { // These four lines result in 1 step: digitalWrite(stepPin, HIGH); delay microseconds (2000); digitalWrite(stepPin, LOW); delay microseconds (2000); }
Control direction of rotation:
To control the direction of rotation of the stepper motor, we set the DIR pin (direction) to either HIGH or LOW. For this we use the functiondigitalWrite()
. Depending on how you connected the stepper motor, setting the DIR pin will make the motor rotate clockwise or counterclockwise.
Control number of steps or revolutions:
In this sample sketch, thefor loopsControl the number of steps the stepper motor will take. The code inside the for loop gives 1 (micro)step of the stepper motor. Since the code in the loop is executed 1600 times (stepsPerRevolution), this results in 1 revolution. In the last two loops, the code inside the for loop is executed 8000 times, resulting in 8000 (micro)steps or 5 revolutions.
Note that you can change the second term in the for loop to any number of steps.for(int i = 0; i < 800; i++)
would be 800 steps or half a revolution.
Controlled speed:
The speed of the stepper motor is determined by the frequency of the pulses we send to the STEP pin. The higher the frequency, the faster the motor runs. You can control the frequency of the pulses by changing itDelayMicroseconds()
in code. The shorter the delay, the higher the frequency, the faster the motor runs.
Installing the AccelStepper library
Written by Mike McCauley, the AccelStepper library is a great library to use for your project. One of the advantages is that it supports acceleration and deceleration, but it also has many other nice features.
You can download the latest version of this libraryhereor click the button below.
AccelStepper-1.59.zip
You can install the library by going toSketch > Include Library > Add .ZIP Library...in the Arduino-IDE.
Another option is to navigate toTools > Manage Libraries...or on Windows, type Ctrl + Shift + I. The library manager opens and updates the list of installed libraries.

You can search for "accelstepper" and search for Mike McCauley's library. Select the latest version and then click Install.

AccelStepper sample code
With the following sketch you can accelerate and decelerate the movements of the stepper motor without complicated coding. In the example below, the motor runs back and forth at a speed of 1000 steps per second and an acceleration of 500 steps per square second.
Note that I'm still using the driver in 1/8 microstepping mode. If you use a different setting, play around with the speed and acceleration settings.
/* Example sketch of controlling a stepper motor using TB6560 stepper motor driver, AccelStepper library and Arduino: acceleration and deceleration. More info: https://www.makerguides.com */// Include AccelStepper library: #include <AccelStepper.h>// Define stepper motor connections and motor interface type. The 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 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); // go back to zero: stepper.moveTo(0); stepper.runToPosition(); delay(1000);}
Code Explanation:
The first step is to include the library#include <AccelStepper.h>
.
// Include AccelStepper library:#include <AccelStepper.h>
The next step is to define the TB6560 to Arduino connections and motor interface type. The motor interface type must be set to 1 when using a step and direction driver. You can find the other interface typeshere.
// 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
Next you need to create a new instance of the AccelStepper class with the appropriate motor interface type and connections.
In this case I named the stepper motor "Stepper", but you can use other names like "z_motor" or "liftmotor" etc. AccelStepper liftmotor = AccelStepper(motorInterfaceType, stepPin, dirPin);. The name you give the stepper motor will later be used to set the speed, position and acceleration for that particular motor. You can create multiple instances of the AccelStepper class with different names and pins. This way you can easily control 2 or more stepper motors at the same time.
// Create a new instance of the AccelStepper class: AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
In the setup() we have to define the acceleration/deceleration in addition to the maximum speed. For this we use the functionsetMaxSpeed()
andsetAcceleration()
.
void setup() { // Set maximum speed and acceleration: stepper.setMaxSpeed(1000); stepper.setAcceleration(500);}
In the loop section of the code, we make the motor rotate a predefined number of steps. The functionstepper.moveTo()
is used to set the target position (in steps). The functionstepper.runToPosition()
drives the motor (with acceleration/deceleration) to the target position and blocks until it is at the target position. Because this feature is blocking, you shouldn't use it if you need to control other things at the same time.
// Set the target position: stepper.moveTo(8000); // Run to target position with set speed and acceleration/deceleration: stepper.runToPosition();
If you want to see more examples of the AccelStepper library, check out my tutorial for the A4988 stepper motor driver:
- How to control a stepper motor with A4988 driver and Arduino
Conclusion
In this article, I showed you how to control a stepper motor using the TB6560 stepper motor driver and Arduino. I hope you found it useful and informative. if yes pleaseshare it with a friendwho also likes electronics and makes things!
I would like to know what projects you plan to build (or have already built) with this driver. If you have any questions, suggestions, or feel something is missing from this tutorial,Please leave a comment below.
Note that comments are moderated to prevent spam.