Arduino Mega - BTS7960 Motor Driver

In many tutorials, an electric hoist hangs from a beam. It raises a box of tools to a high shelf, stops, and later lets it back down. The motor of a hoist like that is a big 12V or 24V gear motor, and it draws much more current than the small motor drivers that most beginners start with can give. This is the kind of job the BTS7960 motor driver module was made for. This tutorial instructs you how to use the Arduino Mega 2560 with the BTS7960 to run one large DC motor forward and backward, fast or slow. In detail, we will learn:

Arduino Mega 2560 with BTS7960 motor driver running a 12V DC motor both ways

We suggest:

Hardware Preparation

1×Arduino MEGA
1×Alternatively, DIYables MEGA Development Board
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/Mega
1×Recommended: Sensors/Servo Expansion Shield for Arduino Mega
1×Recommended: Breadboard Shield for Arduino Mega
1×Recommended: Enclosure for Arduino Mega

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Look for the current printed on the label of your motor. Your 12V adapter should be rated for a higher current than that number.

Overview of BTS7960 Motor Driver and Its Pinout

BTS7960 motor driver module pinout

The BTS7960 module drives just ONE brushed DC motor, but a large and hungry one. Many sellers call the same board IBT-2 or HW-039. Two Infineon BTS7960B half-bridge chips are soldered on its top side, and a large heat sink below the board cools them. Each half-bridge decides whether its motor wire sees B+ or B-. Working as a pair, the two halves form a full H-bridge: when the right half drives the motor, it turns forward; when the left half drives it, it turns in reverse. Speed is set with PWM: the Mega flicks the signal ON and OFF hundreds of times per second, and the longer each ON part lasts, the faster the motor runs. A small 74HC14 buffer chip stands in the middle, so the pins of the Mega never drive the big power chips directly.

BTS7960 Motor Driver Module
H-bridge built from two BTS7960B half-bridge chips by Infineon
Motors per module a single brushed DC motor (forward + reverse)
Motor voltage between B+ and B- anything from 5.5V to 27V DC, good for 6V, 12V and 24V motors
Maximum current 43A, where the chip begins to limit it
Highest PWM frequency on RPWM / LPWM 25 kHz
Built-in protection current limit and over-temperature
Input buffer 74HC14, powered through VCC
Control pins 2 rows of 4 male header pins

Do not read 43A as the current the board can give all day. It is the point where the chip begins to hold the current back. If your motor works for a long time without a break, keep its current far lower. For such long runs, how big the heat sink is decides what the module can take.

Here is how the labels pair up on the 2 x 4 header:

Pin pair Top row Bottom row
7 and 8 VCC GND
5 and 6 R_IS L_IS
3 and 4 R_EN L_EN
1 and 2 RPWM LPWM

The 8 pins of the header, one by one:

  • RPWM pin: must be connected to Mega pin 9 or another PWM pin. This is the "forward" input: the wider the PWM pulses, the faster the motor turns that way.
  • LPWM pin: must be connected to one more PWM-capable pin, pin 10 in this tutorial. It is the "reverse" input and works the same way in the other direction.
  • R_EN pin: must be connected to an output pin of the Mega (pin 12 here). It is the on/off switch of the right half-bridge: LOW = off, HIGH = on.
  • L_EN pin: must be connected to an output pin of the Mega (pin 11 here). It switches the left half-bridge on and off in the same way.
  • R_IS and L_IS pins (printed R_S and L_S on some boards): these report the current and errors. Our hoist demo has no need for them, so both of them are left open.
  • VCC pin: must be connected to the 5V header of the Mega. It feeds the 74HC14 and the tiny power LED, nothing else. The motor takes nothing from this pin.
  • GND pin: must be connected to one of the many GND pins of the Mega. The board already ties it to B- on the inside.

The 4 positions of the screw terminal:

  • B+: must be connected to the plus (+) side of the adapter
  • B-: must be connected to the minus (-) side of the adapter
  • M+ and M-: must be connected to the motor, one wire each

※ NOTE THAT:

Not every BTS7960 board places its pins in the same spot, and the printed names can be a little different (for example R_S instead of R_IS). Follow the labels printed on your own module, not the position in a photo. Check each label twice!

What the Four Control Pins Do Together

With both enables HIGH, the PWM inputs pick the motion:

RPWM LPWM Motion of the motor
PWM value 1 to 255 0 Forward (lift). Higher value = faster
0 PWM value 1 to 255 Reverse (lower). Higher value = faster
0 0 Brake. M+ and M- are tied together inside the driver, and the motor halts quickly

A LOW on R_EN and L_EN shuts the whole driver off. M+ and M- are then not driven at all. The motor coasts: it keeps turning for a while and spins down on its own.

One rule to remember: at least one of the two PWM inputs must be 0. Do not give RPWM and LPWM a PWM signal together.

Two Power Inputs and One Ground

The module has a logic side and a motor side, and they get power from two different places:

  • The logic side (VCC and GND) gets 5V from the Arduino Mega. It needs only a very small current.
  • The motor side (B+ and B-) gets 12V from the adapter by way of the DC jack. All the heavy current flows here.

Inside the module, the GND pin and the B- terminal are the same point. This means the GND wire of the Mega does two jobs: it grounds the logic chip, and it shares ground with the 12V supply. You do not add a separate ground wire. The 12V on B+ is a different story: it must never reach the Mega, not even one pin. Make sure the + wire of the adapter lands on B+ and the - wire on B- before you switch it on, because a reversed supply can ruin the driver.

Wiring Diagram

Four signal wires run from the Mega to the driver. The two speed inputs use PWM pins 9 (RPWM) and 10 (LPWM), and the enable inputs use pin 12 (R_EN) and pin 11 (L_EN). Two more wires bring 5V and GND to the logic side.

The wiring diagram between Arduino Mega BTS7960 motor driver

This image is created using Fritzing. Click to enlarge image

BTS7960 Pin Arduino Mega 2560 Pin
VCC 5V
GND GND
RPWM D9 (PWM)
LPWM D10 (PWM)
R_EN D12
L_EN D11
R_IS, L_IS not used, nothing connected
B+ plus (+) of the 12V supply, from the DC jack
B- minus (-) of the 12V supply, from the DC jack
M+, M- one motor wire each

Pins 11 and 12 of the Mega can also make PWM, but here they only need to be HIGH or LOW. Mind the order of the two enable wires: the higher pin number (12) belongs to R_EN, and the lower one (11) belongs to L_EN, the same as in the code. The motor current flows only through the screw terminal, so the wires there should be thicker. Thin jumper wires are fine for the control header.

How To Program For BTS7960 Motor Driver

No library is needed. The code uses only analogWrite() and digitalWrite(), which are built into the Arduino core.

  • The first step is to name the four Arduino Mega pins that are connected to the control header:
#define MOTOR_RPWM 9 // D9 -> RPWM #define MOTOR_LPWM 10 // D10 -> LPWM #define MOTOR_L_EN 11 // D11 -> L_EN #define MOTOR_R_EN 12 // D12 -> R_EN
  • In the setup() function, all four pins are set as outputs. Both PWM pins start at 0, and only then is the driver switched ON:
pinMode(MOTOR_RPWM, OUTPUT); pinMode(MOTOR_LPWM, OUTPUT); pinMode(MOTOR_R_EN, OUTPUT); pinMode(MOTOR_L_EN, OUTPUT); analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, 0); digitalWrite(MOTOR_R_EN, HIGH); digitalWrite(MOTOR_L_EN, HIGH);
  • For a lift (forward), LPWM stays at 0 while RPWM gets a speed value between 0 and 255:
analogWrite(MOTOR_LPWM, 0); analogWrite(MOTOR_RPWM, speed);
  • For a lowering move (reverse), the two PWM pins swap their jobs:
analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, speed);
  • Braking means RPWM = 0 and LPWM = 0, with R_EN and L_EN still HIGH:
analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, 0);
  • A coast needs the enable pins LOW. Set them back to HIGH before the next move, or the motor will not turn:
digitalWrite(MOTOR_R_EN, LOW); digitalWrite(MOTOR_L_EN, LOW);

Arduino Mega Code for BTS7960 Motor Driver - Lift, Brake, Lower and Coast

The sketch below plays one hoist cycle again and again. The motor turns freely on your desk, but each step has a hoist name:

  • LIFT: forward, the PWM value climbs from 0 to 255, stays at 255 for 2 seconds, then falls back to 0
  • STOP: a 1-second brake
  • LOWER: reverse with a PWM value of 127 (about 50%) for 2 seconds
  • REST: 2 seconds of coasting with R_EN and L_EN LOW; after that, both enables go HIGH for the next cycle
/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-bts7960-motor-driver */ // Arduino Mega 2560 drives ONE 12V DC motor through the BTS7960 (IBT-2) motor driver // Think of the motor of a small workshop hoist: forward = lift, reverse = lower // No library is needed: the code uses only analogWrite() and digitalWrite() // R_IS and L_IS of the module are not used and stay unconnected #define MOTOR_RPWM 9 // Arduino Mega pin D9 (PWM) -> RPWM of the BTS7960 (forward speed) #define MOTOR_LPWM 10 // Arduino Mega pin D10 (PWM) -> LPWM of the BTS7960 (reverse speed) #define MOTOR_L_EN 11 // Arduino Mega pin D11 -> L_EN of the BTS7960 (left half-bridge ON/OFF) #define MOTOR_R_EN 12 // Arduino Mega pin D12 -> R_EN of the BTS7960 (right half-bridge ON/OFF) const int SPEED_STEP = 3; // the PWM value changes by 3 at each ramp step (0, 3, 6 ... 255) const int STEP_TIME_MS = 20; // wait time between two ramp steps void setup() { Serial.begin(9600); pinMode(MOTOR_RPWM, OUTPUT); pinMode(MOTOR_LPWM, OUTPUT); pinMode(MOTOR_R_EN, OUTPUT); pinMode(MOTOR_L_EN, OUTPUT); // both PWM inputs at 0 before the driver is switched on analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, 0); enableDriver(); Serial.println("Hoist driver armed: R_EN and L_EN are HIGH"); } // R_EN = HIGH and L_EN = HIGH: both half-bridges can work void enableDriver() { digitalWrite(MOTOR_R_EN, HIGH); digitalWrite(MOTOR_L_EN, HIGH); } // forward (lift): speed 0 to 255 on RPWM, LPWM is kept at 0 void runForward(int speed) { analogWrite(MOTOR_LPWM, 0); // the other PWM input goes to 0 first analogWrite(MOTOR_RPWM, speed); } // reverse (lower): speed 0 to 255 on LPWM, RPWM is kept at 0 void runReverse(int speed) { analogWrite(MOTOR_RPWM, 0); // the other PWM input goes to 0 first analogWrite(MOTOR_LPWM, speed); } // brake: RPWM = 0 and LPWM = 0 while the driver stays ON // the driver ties M+ and M- together, so the motor stops quickly void brakeMotor() { analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, 0); } // coast: R_EN = LOW and L_EN = LOW, both half-bridges are OFF // the motor is free and spins down on its own void coastMotor() { analogWrite(MOTOR_RPWM, 0); analogWrite(MOTOR_LPWM, 0); digitalWrite(MOTOR_R_EN, LOW); digitalWrite(MOTOR_L_EN, LOW); } void loop() { // 1. Lift: forward, the PWM value climbs from 0 to 255 Serial.println("[LIFT] forward, ramp 0 -> 255"); for (int speed = 0; speed <= 255; speed += SPEED_STEP) { runForward(speed); delay(STEP_TIME_MS); } // 2. Keep full speed for 2 seconds Serial.println("[LIFT] forward, full speed (255), 2 s"); delay(2000); // 3. Still forward, the PWM value falls from 255 to 0 Serial.println("[LIFT] forward, ramp 255 -> 0"); for (int speed = 255; speed >= 0; speed -= SPEED_STEP) { runForward(speed); delay(STEP_TIME_MS); } // 4. Brake for 1 second Serial.println("[STOP] brake, both PWM = 0, driver ON, 1 s"); brakeMotor(); delay(1000); // 5. Lower: reverse at about half speed for 2 seconds Serial.println("[LOWER] reverse, PWM 127 (about 50%), 2 s"); runReverse(127); delay(2000); // 6. Coast for 2 seconds: the driver is OFF Serial.println("[REST] coast, R_EN and L_EN LOW, 2 s"); coastMotor(); delay(2000); // switch the driver ON again before the next lift enableDriver(); Serial.println("[REST] driver ON again, next cycle"); Serial.println(); }

Detailed Instructions

  • Never used the Arduino Mega before? Start with how to set up the environment for Arduino Mega in the Arduino IDE.
  • Make all the connections shown in the wiring diagram. Leave the 12V power adapter unplugged for now.
  • Use the USB A/B cable to link the Arduino Mega and your PC.
  • Launch the Arduino IDE. In the board menu, pick Arduino Mega or Mega 2560, then the port the Mega is on.
  • Start a new sketch, put the code in it, then hit Upload.
  • After the IDE says the upload is done, give the motor its power: connect the 12V adapter to mains power.
  • Bring up the Serial Monitor and choose 9600 baud. Keep one eye on the motor and one on the messages:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Mega Or...
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Mega Or...' on 'COM15')
New Line
9600 baud
Hoist driver armed: R_EN and L_EN are HIGH [LIFT] forward, ramp 0 -> 255 [LIFT] forward, full speed (255), 2 s [LIFT] forward, ramp 255 -> 0 [STOP] brake, both PWM = 0, driver ON, 1 s [LOWER] reverse, PWM 127 (about 50%), 2 s [REST] coast, R_EN and L_EN LOW, 2 s [REST] driver ON again, next cycle [LIFT] forward, ramp 0 -> 255 [LIFT] forward, full speed (255), 2 s [LIFT] forward, ramp 255 -> 0 [STOP] brake, both PWM = 0, driver ON, 1 s [LOWER] reverse, PWM 127 (about 50%), 2 s [REST] coast, R_EN and L_EN LOW, 2 s [REST] driver ON again, next cycle
Ln 11, Col 1
Arduino Mega Or... on COM15
2

Compare the STOP line with the REST line. Before STOP, the ramp has already slowed the motor down, so the brake is a short, firm pause. REST comes straight after the reverse run, and you can see the shaft keep turning for a short time before it is still. Is the motor turning the "lower" way during the [LIFT] lines? Pull the 12V adapter out, then trade the places of the two motor wires in the M+ and M- terminals. No change to the sketch is needed.

A low PWM value can make the motor sing or buzz a little. Nothing is wrong: the PWM on pins 9 and 10 of the Mega runs at about 490 Hz, and our ears can hear that tone.

Additional Knowledge

BTS7960 vs L298N vs DRV8833

All three are H-bridge boards, yet each one fits a different size of motor:

BTS7960 L298N DRV8833
How many DC motors 1 2 2
Current 43A peak (chip limit) around 2A for each motor around 1.5A for each motor
Voltage drop across the driver very small around 2V small
Typical job hoists, winches, scooters, big gear motors, heavy robots medium motors small robots on batteries

It is evident that a hoist, a winch or any other single high-current motor belongs on the BTS7960. Its motor supply also covers 6V, 12V and 24V systems (5.5V to 27V). For a pair of small motors, the DRV8833 or the L298N does the job with one board for both motors.

Brake, Coast and a Real Hoist

In this tutorial, the motor spins with nothing on it, so coasting is harmless. With a load on a real hoist, it is a different story. When the driver is OFF (coast), the weight of the load can turn the motor backwards and the load drops. Braking slows the drum fast, but it cannot hold a load in the air for a long time. Real hoists add a worm gearbox or a mechanical brake to hold the load, and a limit switch at the top. Add these parts before you lift anything heavy, and never stand under a hanging load.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!