Arduino Nano 33 IoT - BTS7960 Motor Driver

Say you have a 12V DC water pump for a garden bed or an aquarium, and you want to choose how strong the flow is. This tutorial instructs you how to use Arduino Nano 33 IoT and a BTS7960 motor driver module for this kind of job: the board sends a small PWM signal, and the BTS7960 turns it into real power for the motor. Later, the Wi-Fi of the Nano 33 IoT can bring that speed control to your phone. In detail, we will learn:

Arduino Nano 33 IoT and BTS7960 driver setting a 12V DC motor's speed

We suggest:

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×BTS7960 Motor Driver Module
1×12V DC Motor
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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 .

Overview of the BTS7960 Motor Driver and Its Pinout

BTS7960 Motor Driver Module Pinout
image source: diyables.io

Shops also list this same board under the names IBT-2 and HW-039. Two Infineon BTS7960B chips sit on top of the board, and a big heat sink under the board keeps them cool. One chip alone is a half-bridge; the pair makes a full H-bridge. That is why the module can spin one brushed DC motor both ways, with PWM for the speed. Next to small drivers like the L298N or the DRV8833, it is the heavyweight: think big gear motors, wiper motors, winches, scooters and strong robot bases.

BTS7960 Motor Driver Module
Driver chips Infineon BTS7960B, two of them (a half-bridge each)
Motor count one brushed DC motor, forward or backward
Motor supply on B+ / B- 5.5V to 27V DC, fits 6V, 12V or 24V motors
Current up to 43A (the current-limit level, a peak value)
Highest PWM frequency 25 kHz
Input buffer 74HC14 chip, fed by the VCC pin
Safety features current limiting and over-temperature protection

The control side is a 2 x 4 male header. The top row holds VCC, R_IS, R_EN and RPWM. The bottom row holds GND, L_IS, L_EN and LPWM, so each "R" pin sits right above its "L" twin. Here is what each pin does:

  • RPWM pin: must be connected to a PWM pin of the Arduino Nano 33 IoT. Pulses here spin the motor forward.
  • LPWM pin: must be connected to a second PWM pin. Pulses here spin the motor backward.
  • R_EN pin: must be connected to a digital pin. A HIGH level wakes up the right half-bridge.
  • L_EN pin: must be connected to a digital pin. A HIGH level wakes up the left half-bridge.
  • R_IS, L_IS pins: these report the current and any fault. This project ignores them, so leave them free.
  • VCC pin: must be connected to the +5V pin of the Arduino Nano 33 IoT. It feeds just the 74HC14 buffer and the power LED; the motor takes nothing from it.
  • GND pin: must be connected to a GND pin of the Arduino Nano 33 IoT.
  • B+ and B- screw terminals: the motor power comes in here, plus on B+, minus on B-.
  • M+ and M- screw terminals: the motor's own two leads go here.

※ NOTE THAT:

The silkscreen shortens R_IS / L_IS to "R_S" / "L_S". Other sellers of this IBT-2 style board may print the labels in a slightly different way. Go by the text on your own module, not by the position of the pin.

How the BTS7960 Turns the Motor

Think of each BTS7960B chip as a very fast switch for one motor wire: it can tie that wire to B+ or to B-. When one chip feeds its wire from B+ and the other chip ties its wire to B-, current runs through the motor one way. Swap the jobs of the two chips, and the current, and the motor, go the other way. The PWM signal flicks the B+ side on and off very quickly. The longer it stays on in each cycle (the duty cycle), the faster the motor spins.

As long as D12 and D11 hold R_EN and L_EN HIGH, the result depends only on the two PWM pins:

RPWM (D9) LPWM (D10) Result
duty 0 to 255 held at 0 spins forward; more duty, more speed
held at 0 duty 0 to 255 spins backward; more duty, more speed
held at 0 held at 0 brake - M+ and M- are linked to each other, and the motor halts in a moment

Drive R_EN and L_EN LOW, and both half-bridges switch off. This is "coast": the motor gets no power and rolls to a stop on its own, more slowly than with the brake.

At any moment, RPWM or LPWM (or both) must sit at 0. PWM on the two of them together is never allowed.

Powering the Module From a 3.3V Board

The BTS7960 module has two power sides. Keep them apart:

  • Logic side: the VCC pin goes to the +5V pin. VCC only runs the buffer chip, and the module maker calls for 5V there. The control inputs are fine with 3.3V signals, so the pins of the Arduino Nano 33 IoT drive them without any help. (On this board, the +5V pin is VUSB. It gives 5V only after you close the VUSB solder jumper on the bottom of the board, and only while the board runs on USB power.)
  • Motor side: the 12V adapter plugs into a DC power jack, and two wires run from the jack to the module: plus to B+, minus to B-. Never connect B+ to any pin of the Arduino Nano 33 IoT.
  • Ground: on the module, the header GND is wired to B-. A single wire from a GND pin of the board to the GND pin of the header is enough: the board and the 12V adapter now share one ground.

Nothing is wired to R_IS or L_IS, so no signal travels from the module back to the board. The four control inputs only have pull-down resistors, so the 5V on VCC does not reach the board's pins. Nothing from the 12V side can reach the 3.3V pins this way.

What about the 43A? The chips start to limit the current at that point, so think of it as a peak, not a value for long runs. A motor or pump that runs for minutes or hours should draw far less. For long runs, how well the heat sink gets rid of heat sets the real limit. Also pick a 12V adapter rated for more amps than the motor draws.

Wiring Diagram

Only six jumper wires go to the Arduino Nano 33 IoT: four control lines, +5V and GND. The motor and the 12V adapter connect to the big screw terminals of the module, never to the board.

The wiring diagram between Arduino Nano and 33 IoT BTS7960 motor driver

This image is created using Fritzing. Click to enlarge image

BTS7960 Module Arduino Nano 33 IoT / 12V Side
RPWM D9
LPWM D10
R_EN D12
L_EN D11
VCC +5V (close the VUSB jumper first)
GND GND
R_IS, L_IS leave free
B+ DC power jack, plus (+) terminal
B- DC power jack, minus (-) terminal
M+, M- motor leads (12V DC motor or 12V pump)

A screw terminal keeps each wire tight, even when the board shakes. To do that, mount the Arduino Nano 33 IoT on a Screw Terminal Expansion Board for Arduino Nano. Below is the wiring diagram with the screw terminal board.

The wiring diagram between Arduino Nano and 33 IoT BTS7960 motor driver Screw Terminal

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Finish all the wiring first, and plug in the 12V adapter last. Before you plug it in, check that plus goes to B+ and minus goes to B-. Plus and minus the wrong way round can ruin the module.

How To Program For BTS7960 Motor Driver

No library is needed. The module only needs two kinds of signals: PWM from analogWrite() and HIGH / LOW from digitalWrite().

  • The first step is to give a name to each Arduino Nano 33 IoT pin that goes to the control header:
#define RPWM_PIN 9 // forward PWM, wired to D9 #define LPWM_PIN 10 // reverse PWM, wired to D10 #define R_EN_PIN 12 // right enable, wired to D12 #define L_EN_PIN 11 // left enable, wired to D11
  • In setup(), make all four pins outputs. Hold both PWM pins at 0, and only 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);
  • To run forward, put 0 on LPWM and the speed (0 to 255) on RPWM:
analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, speed);
  • To run in reverse, it is the other way round:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, speed);
  • A brake is simply 0 on RPWM and on LPWM, with R_EN and L_EN left HIGH. For a coast, the enable pins go LOW as well, and they must be HIGH again before the motor can move once more.

※ NOTE THAT:

On the Arduino Nano 33 IoT, a pin that has been used with analogWrite() no longer listens to digitalWrite(). This wiring avoids the problem: D9 and D10 only ever get analogWrite(), while D12 and D11 only ever get digitalWrite().

Arduino Nano 33 IoT Code for BTS7960 Motor Driver

The sketch below wraps those lines into small helper functions: motorForward(), motorReverse(), motorBrake() and motorCoast(). Then it runs one round after another, and each round has six steps:

  1. Forward, with the speed rising from 0 to 255
  2. Full speed forward for 2 seconds
  3. Forward, with the speed falling back to 0
  4. Brake for 1 second
  5. Reverse at about half speed (128) for 2 seconds
  6. Coast for 2 seconds (driver off), then the driver is switched on again

Each step prints one line, with its number, to the Serial Monitor.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-bts7960-motor-driver */ // The Arduino Nano 33 IoT pins wired to the 8-pin control header of the BTS7960 module. // RPWM and LPWM need PWM pins. R_EN and L_EN only need plain digital pins. #define RPWM_PIN 9 // The Arduino Nano 33 IoT pin D9 connected to the RPWM pin of BTS7960 (forward PWM) #define LPWM_PIN 10 // The Arduino Nano 33 IoT pin D10 connected to the LPWM pin of BTS7960 (reverse PWM) #define R_EN_PIN 12 // The Arduino Nano 33 IoT pin D12 connected to the R_EN pin of BTS7960 (right half-bridge on/off) #define L_EN_PIN 11 // The Arduino Nano 33 IoT pin D11 connected to the L_EN pin of BTS7960 (left half-bridge on/off) #define FULL_SPEED 255 // 100% duty cycle #define HALF_SPEED 128 // about 50% duty cycle // Note: on the Nano 33 IoT, a pin that was used with analogWrite() does not react to digitalWrite() any more. // So the two PWM pins only get analogWrite(), and the two enable pins only get digitalWrite(). // switch both half-bridges on (needed for forward, reverse and brake) void driverOn() { digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } // forward: PWM on RPWM, LPWM stays at 0 void motorForward(int speed) { analogWrite(LPWM_PIN, 0); // set the other side to 0 first, never drive both analogWrite(RPWM_PIN, speed); } // reverse: PWM on LPWM, RPWM stays at 0 void motorReverse(int speed) { analogWrite(RPWM_PIN, 0); // set the other side to 0 first, never drive both analogWrite(LPWM_PIN, speed); } // brake: both PWM pins at 0 while the driver is on -> the motor wires are joined and the motor stops fast void motorBrake() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); } // coast: driver off -> the motor gets no power and rolls to a stop by itself void motorCoast() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW); } void setup() { Serial.begin(9600); // the Nano 33 IoT uses its native USB port for Serial: wait up to 3 seconds for the Serial Monitor unsigned long start_time = millis(); while (!Serial && millis() - start_time < 3000) { delay(10); } pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // both PWM pins at 0 before the driver is switched on, so the motor does not jump analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); driverOn(); Serial.println("BTS7960 ready: R_EN and L_EN are HIGH"); } void loop() { // step 1: forward, speed going up Serial.println("[1/6] Forward: speed going up from 0 to 255"); for (int speed = 0; speed <= FULL_SPEED; speed += 5) { motorForward(speed); delay(30); } // step 2: hold full speed Serial.println("[2/6] Forward: holding full speed for 2 s"); motorForward(FULL_SPEED); delay(2000); // step 3: forward, speed going down Serial.println("[3/6] Forward: speed going down to 0"); for (int speed = FULL_SPEED; speed >= 0; speed -= 5) { motorForward(speed); delay(30); } // step 4: brake Serial.println("[4/6] Brake: both PWM pins at 0 for 1 s"); motorBrake(); delay(1000); // step 5: reverse at about half speed Serial.println("[5/6] Reverse: half speed (128) for 2 s"); motorReverse(HALF_SPEED); delay(2000); // step 6: coast with the driver off Serial.println("[6/6] Coast: driver off for 2 s"); motorCoast(); delay(2000); driverOn(); // switch the driver on again for the next round }

Detailed Instructions

First time with the Arduino Nano 33 IoT? Then set it up in the Arduino IDE with the Getting Started with Arduino Nano 33 IoT tutorial before you go on.

  • Close the VUSB solder jumper on the bottom of the board, so the +5V pin gives 5V to VCC.
  • Wire the components as shown in the diagram. The 12V adapter stays unplugged until the upload is done.
  • Connect the Arduino Nano 33 IoT board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and its COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button and wait for the upload to finish.
  • Now connect the 12V adapter to the wall socket, so the motor side gets its power.
  • Open the Serial Monitor, set it to 9600 baud, and keep your eyes on the motor shaft. It speeds up, runs at full speed, slows down, stops hard, turns the other way at half speed, and then rolls to a stop.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' on 'COM15')
New Line
9600 baud
BTS7960 ready: R_EN and L_EN are HIGH [1/6] Forward: speed going up from 0 to 255 [2/6] Forward: holding full speed for 2 s [3/6] Forward: speed going down to 0 [4/6] Brake: both PWM pins at 0 for 1 s [5/6] Reverse: half speed (128) for 2 s [6/6] Coast: driver off for 2 s [1/6] Forward: speed going up from 0 to 255 [2/6] Forward: holding full speed for 2 s
Ln 11, Col 1
Arduino Nano 33 IoT on COM15
2

Does the motor turn the wrong way in step 1? Pull out the 12V adapter, then exchange the two motor leads on M+ and M-. The code stays the same.

At low speed, you may hear the motor hum or whine. This is normal: the default PWM frequency of the board is below 1 kHz, a sound you can hear.

Running a pump instead of a motor? Most pumps are made to turn in one direction only. Keep the forward steps, and remove the reverse step from the loop.

Additional Knowledge

BTS7960, L298N or DRV8833?

This board already has tutorials for the DRV8833 (also used in Arduino Nano 33 IoT - DC Motor) and the BTS7960 on this page. Here is how they compare with the older L298N:

BTS7960 L298N DRV8833
How much current up to 43A (peak) about 2A per motor about 1.5A per motor (2A peak)
Voltage drop in the driver very little about 2V very little
How many motors one two two

It is evident that the BTS7960 is the one to choose when a single motor needs a lot of current. For two small motors, the DRV8833 is smaller and simpler.

Project Ideas

The Wi-Fi of the Arduino Nano 33 IoT and the strength of the BTS7960 work well together:

  • A garden watering pump whose flow you set from your phone, slow for seedlings and strong for a big bed
  • An aquarium pump that runs gently at night and at full flow during the day
  • A pump that speeds up as the soil gets drier, with the reading from the Arduino Nano 33 IoT - Soil Moisture Sensor tutorial
  • A small electric winch or a heavy robot base, where the motor needs both directions and a firm brake

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!