TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (2023)

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× 1Amazonas
TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (1)Nema 23 stepper motor× 1Amazonas
TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (2)Arduino Uno Rev3× 1Amazonas
power adapter(24 Volt)× 1Amazonas
jumper wires× 4Amazonas
USB-Kabel Typ A/B× 1Amazonas

Tool

wire stripperAmazonas
Small screwdriverAmazon
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

TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (3)Arduino-IDE

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 voltage10 – 35 VDC, 24 VDC empfohlen
Maximum output current3 A pro Phase, 3,5 A Spitze
microstep resolutionfull, 1/2, 1/8 and 1/16
SchutzLow voltage shutdown, overheat and overcurrent protection
Dimensions75 x 50 x 35 mm
Lockheed69 x 43 mm, ⌀ 3,5 mm
Costcheck price

For more information, see the following data sheet/manual:

Toshiba TB6560 data sheet

TB6560 manual

(Video) TB6560 Stepper Motor Driver with Arduino.

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.

TB6560TB6600
operating voltage10 – 35 VDC, 24 VDC empfohlen9 – 42 VDC, 36 VDC empfohlen
Maximum output current3 A pro Phase, 3,5 A Spitze3,5 A pro Phase, 4 A Spitze
# Current settings148
microstep resolutionfull, 1/2, 1/8 and 1/16full, 1/2, 1/4, 1/8, 1/16 and 1/32
clock frequency15kHz200kHz
Costcheck pricecheck 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.

TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (4)

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

TB6560connection
VCC10 – 35 VDC
Masseground 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:

  1. Try turning the stepper motor shaft by hand and notice how hard it is to turn.
  2. Now take a random pair of wires from the motor and touch the bare ends together.
  3. 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.

(Video) How to run stepper motor using TB6560 stepper driver

(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

S3S4microstep resolution
OUTOUTfull step
ANOUT1/2 step
ANAN1/8 step
OUTAN1/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)SW1SW2SW3S1
0,3OUTOUTANAN
0,5OUTOUTANOUT
0,8OUTANOUTAN
1OUTANOUTOUT
1.1OUTANANAN
1.2ANOUTOUTAN
1.4OUTANANOUT
1.5ANOUTANAN
1.6ANOUTOUTOUT
1.9ANANOUTAN
2ANOUTANOUT
2.2ANANANAN
2.6ANANOUTOUT
39ANANANOUT

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 streamS2
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

S5S6
0 % normalOUTOUT
25 %ANOUT
50 %OUTAN
100% faster modeANAN

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#defineused 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.

(Video) TB6560 + NEMA 23 Arduino Tutorial

I also defined asteps per revolutionConstant. 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.

TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (5)
(Video) STEPPER MOTOR AND ARDUINO EASY DRIVING WITH TB 6560 V2.0 DRIVER

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

TB6560 Stepper Motor Driver with Arduino Tutorial (2 Examples) (6)

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.

Videos

1. TB6560 Stepper Motor Driver Module
(by eng)
2. TB6600 Stepper Motor Driver with Arduino
(MYTECTUTOR)
3. Tb6560 stepper motor driver
(Akin Onawole)
4. TB6560 3A Driver Board and motor set up
(Kevin's shop)
5. TB6560 Professional Version Record/Replay G-Code?
(Gfast Gao)
6. TB6560 (Single Axis Stepper Controller) + Arduino Pro Mini + IR-remote
(Egon Svensson)
Top Articles
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated: 06/16/2023

Views: 5934

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.