Arduino - BTS7960 Motor Driver

An Arduino Uno can be the brain of a sliding gate opener. The hard part is the 12V gear motor that drags the heavy gate: it pulls far more current than a small motor driver can give. The BTS7960 module is built for motors like this. In this tutorial, we are going to learn:

Arduino Uno driving a 12V DC gear motor through a BTS7960 43A H-bridge motor driver

Hardware Required

1×Official Arduino Uno
1×Alternatively, DIYables STEM V3, Fully Compatible with Arduino Uno R3
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×BTS7960 Motor Driver Module
1×12V DC Motor
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables STEM V3 Starter Kit (Arduino included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

Choose a 12V adapter that can give more current than your motor needs. The label of the motor, or its product page, tells you how much current that is.

About BTS7960 Motor Driver

The BTS7960 module is also sold as "IBT-2" or "HW-039". It carries two Infineon BTS7960B chips that share one big heat sink, bolted under the board. Each chip is a half-bridge, and the two halves together make one full H-bridge. So the module drives one brushed DC motor, forward or backward, and Arduino sets the speed with PWM. You can see it as the big brother of the L298N and the DRV8833. It is made for big gear motors, wiper motors, winches, scooters, wheelchair motors, heavy robots and, of course, gate openers.

BTS7960
Driver Chips 2 x Infineon BTS7960B (half-bridge), one full H-bridge
Motors 1 brushed DC motor, both directions
Motor Supply (B+ and B-) 5.5V to 27V DC (6V, 12V and 24V systems)
Current up to 43A (current limit of the chip, for short peaks)
PWM Frequency up to 25 kHz on RPWM and LPWM
Logic Supply (VCC) 5V from Arduino, for the 74HC244 buffer chip only
Protection current limiting, over-temperature

How does it work, in short? Each BTS7960B chip can connect its motor wire either to B+ or to B-. When RPWM is HIGH, the right chip connects its wire to B+, while the left chip keeps the other wire on B-. The current then flows through the motor in one direction. LPWM does the same thing the other way around. With PWM, the pin turns on and off very fast, so the motor gets only a part of the power and turns slower.

The 43A in the table is the level where the chip starts to limit the current. It is not a value for long runs. For a motor that runs for minutes, keep the current far below 43A. The heat sink decides how much the board can carry for a long time.

Pinout

BTS7960 motor driver module pinout

On one side, the module has a control header with 8 pins in two rows of 4. On the other side, it has a screw terminal for the power wires.

Control header:

  • RPWM pin: needs to be connected to a PWM pin of Arduino. A PWM signal on this pin turns the motor forward (right half-bridge).
  • LPWM pin: needs to be connected to another PWM pin of Arduino. A PWM signal on this pin turns the motor in reverse (left half-bridge).
  • R_EN pin: needs to be HIGH to switch the right half-bridge on. LOW switches it off.
  • L_EN pin: needs to be HIGH to switch the left half-bridge on. LOW switches it off.
  • R_IS and L_IS pins: current sense and fault outputs. The board prints them as "R_S" and "L_S". We do not use them in this tutorial, so leave them unconnected.
  • VCC pin: needs to be connected to 5V of Arduino. It powers only the 74HC244 buffer chip and the power LED, not the motor.
  • GND pin: needs to be connected to GND of Arduino. On the module, this pin is joined to B-.

Screw terminal:

  • B+ pin: needs to be connected to the positive (+) of the motor power supply (5.5V to 27V)
  • B- pin: needs to be connected to the negative (-) of the motor power supply
  • M+ and M- pins: the two wires of the DC motor

The 74HC244 buffer chip sits between the Arduino pins and the two power chips. The product page calls it the isolation chip. The Arduino pins only "talk" to this small chip, and the motor current never flows through them.

Speed, Direction, Brake and Coast

When R_EN and L_EN are both HIGH, the two PWM pins decide what the motor does:

RPWM LPWM Motor
PWM (0 to 255) 0 turns forward, a bigger value means a higher speed
0 PWM (0 to 255) turns in reverse, a bigger value means a higher speed
0 0 brake the driver joins the two motor wires together, so the motor stops fast

When R_EN and L_EN are both LOW, both half-bridges are off. Nothing holds the motor, so it rolls on and stops by itself. This is called "coast".

A gate opener can use both stops: brake to stop the gate at the right spot, and coast to let it slow down softly.

※ NOTE THAT:

  • Always keep one of RPWM and LPWM at 0. Never send PWM to both pins at the same time.
  • The motor gets its power from the 12V adapter through B+ and B-, never from Arduino. Never connect B+ to any pin of Arduino.
  • GND and B- are joined on the module. So the single GND wire from Arduino to the module also gives the common ground with the motor supply.
  • Check + and - of the adapter before you plug it in. Wrong polarity can damage the module.

Wiring Diagram

Pins 9 and 10 of Arduino carry the PWM signals, pins 11 and 12 switch the two half-bridges, and 5V and GND power the buffer chip of the module.

Arduino BTS7960 motor driver wiring diagram

This image is created using Fritzing. Click to enlarge image

BTS7960 Pin Connect To
RPWM Arduino pin 9
LPWM Arduino pin 10
R_EN Arduino pin 12
L_EN Arduino pin 11
VCC Arduino 5V
GND Arduino GND
R_IS, L_IS nothing (leave them free)
B+ + of the 12V power adapter (through the DC power jack)
B- - of the 12V power adapter (through the DC power jack)
M+, M- the two wires of the 12V DC motor

Jumper wires can come loose when you move the project. In this case, use a Proto Screw Terminal Block Shield or a Screw Shield V2. It plugs into the Arduino Uno and gives each pin a screw terminal. The wiring stays the same. Only the wires now go to the screw terminals, as shown below.

Arduino BTS7960 motor driver Screw Shield Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Look at the enable pins: R_EN goes to pin 12 and L_EN goes to pin 11. This order keeps the wires short and tidy. If you swap these two wires, the code still works, because the sketch always sets both enable pins at the same time.

How To Program For BTS7960 Motor Driver

  • No library is needed. Define the four control pins:
#define RPWM_PIN 9 // forward PWM #define LPWM_PIN 10 // reverse PWM #define R_EN_PIN 12 // right half-bridge enable #define L_EN_PIN 11 // left half-bridge enable
  • Set the four pins as outputs, put both PWM pins at 0, and then switch the driver on:
pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH);
  • Turn the motor forward. The speed is a number from 0 to 255:
analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, speed);
  • Turn the motor in reverse:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, speed);
  • Brake (the enable pins stay HIGH):
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0);
  • Coast (switch both half-bridges off). Set the enable pins HIGH again before the next run:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW);

Arduino Code - BTS7960 Motor Driver

The sketch takes the motor through six steps, and then starts again:

  • Speeds up forward, from 0 to full speed
  • Stays at full speed for 2 seconds
  • Slows down to 0
  • Brakes for 1 second
  • Turns in reverse at about half speed for 2 seconds
  • Coasts for 2 seconds with the driver off

Each step prints one line on the Serial Monitor.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-bts7960-motor-driver */ // Arduino Uno pins connected to the BTS7960 module #define RPWM_PIN 9 // Arduino Uno pin 9 (PWM) -> RPWM: PWM here turns the motor forward #define LPWM_PIN 10 // Arduino Uno pin 10 (PWM) -> LPWM: PWM here turns the motor in reverse #define R_EN_PIN 12 // Arduino Uno pin 12 -> R_EN: HIGH switches the right half-bridge on #define L_EN_PIN 11 // Arduino Uno pin 11 -> L_EN: HIGH switches the left half-bridge on #define RAMP_STEP 5 // how much the PWM value changes in one ramp step #define RAMP_DELAY 30 // time of one ramp step, in milliseconds void setup() { Serial.begin(9600); pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // both PWM inputs at 0 first, so the motor cannot jump when the driver turns on analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); driverOn(); Serial.println("BTS7960 on: R_EN = HIGH, L_EN = HIGH"); } void loop() { // [1] forward: the speed rises step by step from 0 to 255 Serial.println("[1] forward, speed up 0 -> 255"); for (int speed = 0; speed <= 255; speed += RAMP_STEP) { motorForward(speed); delay(RAMP_DELAY); } // [2] forward: keep the full speed Serial.println("[2] forward, full speed for 2 s"); motorForward(255); delay(2000); // [3] forward: the speed falls step by step from 255 to 0 Serial.println("[3] forward, slow down 255 -> 0"); for (int speed = 255; speed >= 0; speed -= RAMP_STEP) { motorForward(speed); delay(RAMP_DELAY); } // [4] brake: the motor stops fast Serial.println("[4] brake for 1 s"); motorBrake(); delay(1000); // [5] reverse at about half speed (128 of 255) Serial.println("[5] reverse, speed 128 for 2 s"); motorReverse(128); delay(2000); // [6] coast: the driver is off, the motor rolls to a stop by itself Serial.println("[6] coast for 2 s (R_EN = L_EN = LOW)"); motorCoast(); delay(2000); driverOn(); // turn the driver on again before the next forward run } // R_EN and L_EN HIGH: both half-bridges are on void driverOn() { digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } // forward: PWM on RPWM, LPWM stays at 0. speed: 0 to 255 void motorForward(int speed) { analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, speed); } // reverse: PWM on LPWM, RPWM stays at 0. speed: 0 to 255 void motorReverse(int speed) { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, speed); } // brake: both PWM inputs at 0 while the driver is on -> the two motor wires are joined void motorBrake() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); } // coast: both PWM inputs at 0 and both half-bridges off -> the motor is free void motorCoast() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW); }

Quick Steps

  • Wire Arduino, the BTS7960 module, the motor and the DC power jack as shown in the wiring diagram. Keep the 12V adapter unplugged for now.
  • Connect Arduino to PC via USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Now plug the 12V power adapter into the DC power jack.
  • Open the Serial Monitor, set the baud rate to 9600, and watch the motor.
  • If the motor turns the wrong way (for example, the gate closes when it should open), swap the M+ and M- wires.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
BTS7960 on: R_EN = HIGH, L_EN = HIGH [1] forward, speed up 0 -> 255 [2] forward, full speed for 2 s [3] forward, slow down 255 -> 0 [4] brake for 1 s [5] reverse, speed 128 for 2 s [6] coast for 2 s (R_EN = L_EN = LOW) [1] forward, speed up 0 -> 255 [2] forward, full speed for 2 s [3] forward, slow down 255 -> 0 [4] brake for 1 s
Ln 11, Col 1
Arduino Uno on COM15
2

Watch steps [4] and [6]. In step [3] the speed already goes down to 0, so in step [4] the brake simply holds the motor still. In step [6] the driver turns off while the motor still turns in reverse. Now you can see the coast: the motor keeps turning for a short moment, and then it stops by itself.

At a low speed, the motor may hum or whine. This is normal. Pins 9 and 10 of Arduino Uno make PWM at about 490 Hz, and you can hear this frequency in the motor.

Ideas to turn this into a real gate opener:

Is your motor small? Then the BTS7960 is more than you need. The Arduino - DRV8833 DC Motor Driver tutorial drives two small motors, and Arduino - DC Motor uses the DRV8833 too. The DRV8833 drives two motors at about 1.5A each, up to 10.8V. The BTS7960 drives only one motor, but with much more current and up to 27V.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES