Arduino BTS7960 DC Motor Driver Interfacing With Code Example

In this tutorial, you’ll learn how to do Arduino BTS7960 Motor Driver Interfacing and use the BTS7960 with Arduino to control the speed and direction of DC motors. We’ll also create a couple of Arduino DC Motor Control With BTS7960 Projects using PWM for motor speed control.

Table of Contents

  1. Arduino DC Motor Control
  2. BTS7960 DC Motor Driver
  3. BTS7960 Motor Driver Pinout
  4. Wiring BTS7960 Motor Driver With Arduino
  5. Arduino BTS7960 DC Motor Driver Code Example
  6. Arduino BTS7960 Concluding Remarks
  7. More Arduino DC Motor Drivers

Arduino DC Motor Control

DC Motors are very simple rotary actuators that transform electrical energy into a mechanical rotation at a specific torque. We typically use DC motors for applications that require moving objects (e.g. Robotics, Automation, UAV/UGV, etc).

Controlling a DC motor includes: (1) controlling the motor’s speed, and (2) controlling the motor’s direction of rotation (CW or CCW). In this tutorial, you’ll learn how to control a DC motor’s speed & direction using Arduino and BTS7960 motor driver IC.

DC Motor

A typical DC motor will have the following characteristics:

  • Torque (in kg.cm)
  • Rated Rotation Speed (RPM)
  • Rated Full-Load current (e.g. 2A)
  • Rated No-Load current (e.g. 0.2A)
  • Rated voltage for operation (e.g. 12v)

1- DC Motor Direction Control

When electrical current passes through the motor’s winding (coils) that are arranged within a fixed magnetic field (Stator). The current generates a magnetic field in the coils. This in turn causes the coil assembly (Rotor) to rotate, as each coil is pushed away from the like-pole and attracted to the unlike-pole of the stator.

Reversing the direction of current flow in the coil translates to an inversion in the direction of the rotor’s magnetic field. Which in turn applies an inversed torque to each side of the coil resulting in a reverse direction in the rotation.

DC Motor Rotation

Arduino DC Motor Direction Control Using H-Bridge

To control the direction of a DC motor, you need to reverse the polarity of the input power source. This reversal of current flow causes the motor to rotate in the opposite direction.

There are various methods to achieve this polarity reversal in practical applications, such as using a motor driver IC or an H-bridge circuit. These methods provide a controlled and efficient way to reverse the motor’s direction while offering additional functionalities like speed control and braking.

An H-Bridge motor driver circuit is an H-shaped circuitry in which the DC motor is hooked through 4 Switches/Transistors between the power rails ( VM & Ground ). Altering the activated switches reverses the polarity of the voltage (VM) applied to the DC Motor. Consequently, the rotation direction is reversed.

H-Bridge GIF Animation

A real-world H-bridge circuit won’t have 4x ON/OFF switches. Instead, there will be 4-Transistors which are basically “electronic switches” doing the job of reversing the polarity of the motor supply voltage. Designing and building a fully-functioning H-Bridge circuit is beyond the intent of this tutorial.

Instead, we’ll be using a 1-channel H-Bridge motor driver called “BTS7960” which can be used to control the direction and speed of 1 DC motor. More details of this chip will be discussed later on in this tutorial.

2- DC Motor Speed Control

Controlling the speed of a DC motor is achieved in a couple of ways as shown below:

  1. Variable Supply Voltage
  2. Using PWM-Controlled Gate

1- Variable Supply Voltage: This can be achieved using voltage regulation circuitries. However. there are too many limitations and drawbacks to such a method that make it less practical to pursue. But theoretically, it just works and does the job. Varying the supply voltage will control the motor’s speed accordingly.

2- Using a PWM-Controlled Gate: This is the most common technique for motor control applications. It’s done by isolating one of the power source rails from the H-Bridge circuitry using a transistor. Hence, creating an open circuit with the (Ground or VM+).

In this way, activating the Control Gate (the EN transistor) will cause the H-Bridge to be powered up then the motor will start rotating. Regardless of the direction of rotations, activating the control gate with a PWM signal will somehow control the average voltage being delivered from the supply to the motor through the control transistor.

Arduino DC Motor Speed Control Using PWM

We use Arduino PWM output to control the speed of a DC motor. By varying the duty cycle for the motor output enable transistor, we can achieve motor speed control as we’ll see hereafter in this tutorial.

Arduino boards have several PWM output pins usually. Those pins are designated with a (~) mark next to the pin-number on the board. Before discussing how to use the PWM output pins, let’s first define what is the PWM technique and what are the properties of a PWM signal.

Pulse Width Modulation (PWM) is a technique for generating a continuous HIGH/LOW alternating digital signal and programmatically controlling its pulse width and frequency. Certain loads like (LEDs, DC Motors, etc) will respond to the average voltage of the signal which gets higher as the PWM signal’s pulse width is increased.

Average voltage:

LED

PWM Duty Cycle:

50%

PWM Frequency:

x Hz

PWM Duty Cycle Resolution:

As you can see, the LED gets brighter as the pulse width (duty cycle) increases, and it gets dimmer as the pulse width decreases. And this is typically what also happens with a DC motor's speed, it gets faster or slower as the PWM's duty cycle changes.

Check the tutorial below to learn more about Arduino PWM. It's a prerequisite for this tutorial to help you understand the topic in more detail.

Arduino PWM analogWrite Tutorial

This tutorial will provide you with more in-depth information about Arduino PWM output. Starting from the basics of PWM signal, its frequency, duty cycle, and resolution, and will discuss in detail how it works and how to use it in various Arduino control projects.


BTS7960 DC Motor Driver

The BTS7960 is a powerful half-bridge output driver IC, capable of driving high-current loads like DC Motors, 3-Phase BLDC, and Stepper motors. The BTS7960 module shown below has two BTS7960B ICs on board arranged in an H-Bridge configuration. This makes it ideal to drive DC Motors that require a lot of current since the BTS7960 is rated for up to 43A (with proper heat dissipation).

BTS7960-DC-Motor-Driver

The BTS7960 has a wide motor supply voltage range (6v to 27v) with a peak output current of 43A. The heat dissipation of the BTS7960 module is designed to be achieved through copper pads on the PCB with a heatsink mounted on the bottom. This is not an ideal configuration for maximum heat dissipation, and you'll need to add another heatsink on top of the BTS7960B ICs just to achieve a continuous DC load of 25A or above.

BTS7960 Technical Specs.

Motor Supply Voltage (VM)6v - 27v
Logic Supply Voltage (VCC)5v
Logic Input Voltage3.3v or 5v
Output Current (IO) Continuous DC43A
Output Peak Current Per Channel (IOMax) Non-Continuous Current For Short Periods (t < 10ms)60A

For more information about the BTS7960 half-bridge motor driver IC, you can check its Datasheet From Infineon.

Buy a BTS7960 Motor Driver: you can find it here on Amazon.com


BTS7960 Motor Driver Pinout

Here is the pinout diagram of the BTS7960 DC Motor driver module.

TBS7960-Pinout

Let's break them down by functionality and discuss the usage of each pin in the BTS7960 motor driver.

BTS7960 Power Pins

VM+ is the motor supply pin. It can accept any voltage within the 6v to 27v range. This needs to be connected to a separate supply other than the microcontroller's supply. Connecting it to the Arduino's 5v output will damage your Arduino board by over-driving its LDO or induce a lot of noise to the 5v line that feeds the microcontroller and potentially cause it to randomly reset.

VCC(5v) is the logic supply pin. This pin should be connected to the 5v to supply the internal logic circuits inside the BTS7960 motor driver IC.

GND is the ground pin. This pin should be connected to the ground of the Arduino board & the ground of the motor power supply (VM).

Motor Output Pins

Motor + & Motor - are the output pins of the H-Bridge in BTS7960 that connect to the Motor terminals.

Motor Enable Pins

R_EN & L_EN are the motor output enable pins for forward drive and reverse drive respectively. Those pins are used for motor drive enable of both directions. You can hook them up to any output pins of the Arduino or just connect both of them to +5v to keep the bridge enabled and control the speed using the PWM pins only.

Motor PWM (Speed Control) Pins

R_PWM & L_PWM are the motor speed control inputs (PWM) for both the forward and reverse drives. You can control the speed and direction of the DC Motor using those two inputs only.

x_IS Current-Sense & Diagnosis Pins

R_IS & L_IS are the current sense and diagnosis output pins for both the forward & reverse drives.

BTS7960 Output Voltage Drop

The BTS7960 motor driver's internal dual Half-Bridges have a slight voltage drop between the motor supply voltage (VM) and the output voltage that goes to the motor at the end. In the measurement that I carried out, it turned out to be a small voltage drop of 10mv at a 1A DC load.


Wiring BTS7960 Motor Driver With Arduino

Here is the wiring diagram for Arduino with the BTS7960 motor driver module. Note that the DC motor is being driven by the BTS7960 driver which is taking a 12v DC from an external power supply. Also, note that the ground of the external power supply is also connected to the ground of the Arduino board through the module's PCB.

ArduinoBTS7960
+5V
Vcc
GND
GND
5~
R_PWM
6~
L_PWM
+5V
R_EN
+5V
L_EN
No Connection R_IS
No Connection L_IS
Arduino-BTS7960-Wiring-Connection-Circuit-Diagram


Arduino BTS7960 DC Motor Driver Code Example

In this example project, we'll use an Arduino + BTS7960 DC Motor driver to control the direction and speed of a 12v DC Motor. A push button will be used to flip the rotation direction of the motor. And a potentiometer will be used to control the motor's speed.

The input button debouncing technique that we'll be using in this project is demonstrated in the tutorial linked below as well as many other button debouncing techniques. It's a great tutorial that is worth checking out if you'd like to go deeper into this subject.

Arduino Button Debouncing Tutorial

This article will provide you with more in-depth information about Arduino button debouncing techniques both hardware & software methods. With a lot of code examples & circuit diagrams.

The core logic of this application which takes input button pin reading, debouncing, applying control signals to the BTS7960, and changing the PWM duty cycle according to the ADC's reading for the analog input (potentiometer) is executed at a fixed time interval of 5ms instead of using delays.

We'll use the built-in timer-based millis() function to achieve this timing behavior without inserting any sort of delay into the code. If you'd like to learn more about this, it's highly recommended to check out this tutorial.

Wiring

The wiring for this example project is shown in the previous section, scroll up and check it out.

Code Example

Here is the full code listing for this example.

Code Explanation

First of all, we define the 2 IO pins used for the Arduino-BTS7960 motor driver interfacing (PWM) & the push button input reading.

And we'll also define a couple of variables that we'll use to store timestamps to execute the application's core logic at a fixed time interval ( TimeInterval = 5ms ). The way it works is extensively demonstrated in this tutorial.

setup()

in the setup() function, we'll set the pinMode for the IO pins and initialize the motor speed control output pins to be LOW, by writing 0 to the analogWrite() function.

loop()

in the loop() function, we'll check the timer-based millis function to execute the core logic every 5ms. Every 5ms, we'll read the push button input pin & debounce it. If the button is clicked by the user, we'll toggle the output direction control pins to flip the motor rotation direction (CW <-> CCW).

We'll also read the analog input (potentiometer) pin and scale down the 10-Bits value of the ADC down to 8-Bits to write it back to the output PWM pin's duty cycle to control the motor's speed according to the potentiometer's position.

debounce()

This function is used to debounce the push button input pin and it's explained in great detail in this tutorial.

Testing Results

Here is a demo video for testing this project on my Arduino UNO board.


Required Parts List

Here is the full components list for all the parts that you'd need to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we'll receive a small commission on your purchase at no additional cost to you, and it'd definitely support our work.

QTY.Component NameBuy Link
1BTS7960 Motor DriverAmazon
112v DC MotorAmazon
1Arduino UNO KitAmazon
1BreadBoardAmazon
1LEDs KitAmazon
1Capacitors KitAmazon Amazon
1Jumper Wires PackAmazon Amazon
19v Battery or DC Power SupplyAmazon
1Push ButtonsAmazon
1PotentiometerAmazon

Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.


Arduino BTS7960 Concluding Remarks

To conclude this tutorial, we can say that you can easily control high-torque high-load DC Motors with Arduino & BTS7960 Motor Driver using PWM and some IO pins. The BTS7960 DC Motor driver can deliver significantly higher current compared to other small drivers. To learn more about Arduino PWM, it's highly recommended that you check out this Arduino PWM Tutorial.

If you're just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

More Arduino DC Motor Drivers

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment