ESP32 C3 Super Mini - BTS7960 Motor Driver

Hens walk into the coop at dusk and want to go out again at sunrise. An automatic coop door does this job for you: a 12V gear motor winds a cord to lift the door in the morning and lowers it again in the evening. The ESP32 C3 Super Mini makes a good brain for such a door. It is tiny, cheap and has WiFi. But each of its pins gives only a few milliamps at 3.3V, while a motor that lifts a wooden door needs far more. The BTS7960 motor driver fills that gap. On this page, you build the motor part of the door: the C3 lets the motor speed up, slow down, stop hard, turn back and roll freely.

In this tutorial, you'll learn:

ESP32 C3 Super Mini controls a 12V DC motor with a BTS7960 motor driver

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×BTS7960 Motor Driver Module
1×12V DC Motor
1×12V Power Adapter
1×DC Power Jack
1×Breadboard
1×Jumper Wires

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 BTS7960 Motor Driver

The DIYables BTS7960 module controls one brushed DC motor, and it is made for the big ones. Other sellers list this board as IBT-2 or HW-039. Two Infineon BTS7960B chips sit on top of the board, and a big heat sink is bolted under it to keep them cool. Each chip is a half-bridge: it can connect one motor wire to the + or to the - of the motor supply. Together, the two half-bridges make one full H-bridge. When one chip feeds + to its motor wire and the other chip holds the second wire at -, current flows one way and the motor turns forward. Swap the two jobs, and the motor turns in reverse. The control signal switches the power on and off very fast (PWM). The longer the "on" part of each pulse, the faster the motor turns.

Key Features:

  • Motor supply (B+ / B-): 5.5V to 27V DC, so 6V, 12V and 24V motors all work
  • Current: up to 43A. At that point the chips start to limit the current, so treat it as a short peak. A motor that runs for minutes should pull much less, because the heat sink sets what the board can carry for a long time
  • PWM frequency: up to 25 kHz on RPWM and LPWM
  • Protection: current limiting and over-temperature protection inside the chips
  • Logic side: a 74HC14 buffer chip sits between your board's pins and the power chips
  • One motor, both directions: speed control by PWM, plus a brake and a coast mode

Why Pick the BTS7960 for a Coop Door:

  • A door can stick in mud, straw or ice. The motor then pulls a big current, and a small driver would give up
  • The motor gets its own 12V supply. The C3 only sends four small control signals
  • The driver wastes almost no voltage, so nearly all of the 12V reaches the motor
  • The brake stops the motor fast when the door reaches the end of its travel
  • No library to install: analogWrite() and digitalWrite() are all you need

BTS7960 Pinout

BTS7960 motor driver module pinout - 8-pin control header and B+, B-, M+, M- screw terminal

The control header has two rows of four male pins. The silkscreen shortens R_IS and L_IS to "R_S" and "L_S".

  • RPWM (pin 1): PWM input of the right half-bridge. It turns the motor forward. Wire it to GPIO0
  • LPWM (pin 2): PWM input of the left half-bridge. It turns the motor in reverse. Wire it to GPIO1
  • R_EN (pin 3): turns the right half-bridge on (HIGH) or off (LOW). Wire it to GPIO4
  • L_EN (pin 4): turns the left half-bridge on (HIGH) or off (LOW). Wire it to GPIO3
  • R_IS, L_IS (pins 5 and 6): current sense and fault outputs. This project does not use them, so leave them free
  • VCC (pin 7): powers only the logic chip and the power LED, not the motor. Wire it to 5V
  • GND (pin 8): ground. On the module, it is joined to B-

The green screw terminal on the other side takes the thick wires:

  • B+ and B-: + and - of the motor supply (5.5V to 27V)
  • M+ and M-: the two wires of the DC motor

What Each Pin Combination Does

R_EN and L_EN give each half of the bridge permission to work. While both are HIGH, the two PWM pins decide what the motor does:

RPWM LPWM Motor
PWM (0-255) 0 Turns forward. The duty cycle sets the speed
0 PWM (0-255) Turns in reverse. The duty cycle sets the speed
0 0 Brake. The driver joins the two motor wires, so the motor stops fast

Now set R_EN and L_EN LOW. Both halves switch off, and the motor is neither driven nor braked. It coasts and rolls to a stop on its own.

Keep this in mind when you change the code: RPWM and LPWM must never carry PWM together. Before one of them gets a duty above 0, set the other one to 0.

Keeping 3.3V and 12V Apart

  • Motor power: the 12V adapter plugs into the DC power jack. The + screw of the jack goes to B+, the - screw goes to B-. Make sure the adapter can supply more current than the door motor draws.
  • VCC on 5V: VCC feeds only the small buffer chip, and the maker of the module asks for 5V there. The control pins still take 3.3V signals, so the C3 pins drive them straight away. Pull-down resistors sit on these inputs, so no 5V flows back into a C3 pin.
  • Only signals go out: the C3 talks to the module, but the module sends nothing back, because R_IS and L_IS are left free. So the 12V side cannot push a voltage into a C3 pin.
  • Shared ground for free: on the module, GND is already joined to B-. So the wire from the G pin of the C3 to GND of the module also ties the C3 to the ground of the 12V supply.
  • Keep 12V away: never connect B+ to any pin of the ESP32 C3 Super Mini.

※ NOTE THAT:

BTS7960 or a smaller driver? An L298N drives two motors at about 2A each, but it loses about 2V inside. The BTS7960 drives only one motor, with a much higher current and very little loss. For small motors, like the wheels of a palm-sized robot, see ESP32 C3 Super Mini - DRV8833 DC Motor Driver.

Wiring Diagram between BTS7960 and ESP32 C3 Super Mini

Press the ESP32 C3 Super Mini into the breadboard so that it sits across the middle gap. Each pin of the board now has its own breadboard column, and the free holes of that column carry the same signal. All six wires leave from the lower row of pins, the one printed 5V, G, 3.3, 4, 3, 2, 1, 0. Each wire starts in a free hole next to its pin and ends on a pin of the BTS7960 control header. The module stays off the breadboard, because its header already gives the wires something to plug onto. The 12V adapter and the motor go only to the green screw terminal of the module.

Why these pins? They all sit in one row, so the wires stay short. GPIO2 is in that row too, but it is a boot strapping pin of the ESP32-C3, so we jump over it. GPIO0 and GPIO1 carry the PWM signals. GPIO3 and GPIO4 only switch the enable pins HIGH or LOW. The VCC wire starts next to the 5V pin at the end of the row, so the 3.3 pin stays empty.

The wiring diagram between ESP32 C3 Super Mini BTS7960 motor driver

This image is created using Fritzing. Click to enlarge image

BTS7960 Pin Goes To
RPWM GPIO0
LPWM GPIO1
R_EN GPIO4
L_EN GPIO3
VCC 5V (printed "5V" on the board)
GND GND (printed "G" on the board)
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

※ NOTE THAT:

Before the 12V adapter goes into the wall socket: check that + goes to B+ and - goes to B-. A swapped supply can kill the BTS7960 board. Finish all the other wires first and connect the motor power last. Then check the two enable wires once more: GPIO4 belongs to R_EN, GPIO3 belongs to L_EN.

ESP32 C3 Super Mini Code - BTS7960 Motor Driver

The sketch runs the motor through one full cycle and then starts again. For the coop door, think of forward as "door up" and reverse as "door down". Each move prints its own line, so you can match what you hear with what you read.

What the code does:

  • Makes GPIO0, GPIO1, GPIO3 and GPIO4 outputs, sets both PWM pins to 0, then sets R_EN and L_EN HIGH
  • Raises the forward duty from 0 to 255 in about 2 seconds
  • Holds full speed for 2 seconds, then lowers the duty back to 0
  • Brakes for 1 second
  • Runs the motor in reverse at about half speed (128) for 2 seconds
  • Pulls R_EN and L_EN LOW for 2 seconds so the motor coasts, then turns the driver on again
  • Uses four small helper functions: motorForward(), motorReverse(), motorBrake() and motorCoast()
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-bts7960-motor-driver */ /* * ESP32 C3 Super Mini - BTS7960 Motor Driver * * One 12V DC motor is connected to M+ and M- of the BTS7960 module. * The module has two half-bridges (right and left). Four pins control them: * RPWM = PWM, LPWM = 0 -> motor turns forward, the duty (0-255) sets the speed * RPWM = 0, LPWM = PWM -> motor turns in reverse, the duty sets the speed * RPWM = 0, LPWM = 0 -> brake: both motor wires are joined, the motor stops fast * R_EN = LOW, L_EN = LOW -> coast: both half-bridges are off, the motor rolls to a stop * Rule: never send PWM to RPWM and LPWM at the same time. One of them is always 0. * * No library is needed. analogWrite() and digitalWrite() are built into the * ESP32 board package. */ #define RPWM_PIN 0 // ESP32 C3 Super Mini GPIO0 -> BTS7960 RPWM (forward speed) #define LPWM_PIN 1 // ESP32 C3 Super Mini GPIO1 -> BTS7960 LPWM (reverse speed) #define R_EN_PIN 4 // ESP32 C3 Super Mini GPIO4 -> BTS7960 R_EN (right half-bridge on/off) #define L_EN_PIN 3 // ESP32 C3 Super Mini GPIO3 -> BTS7960 L_EN (left half-bridge on/off) // GPIO2 is not used on purpose: it is a boot strapping pin of the ESP32-C3. // BTS7960 VCC -> 5V pin, BTS7960 GND -> G pin. R_IS and L_IS stay unconnected. #define FULL_SPEED 255 // the highest analogWrite() value: 100% duty #define HALF_SPEED 128 // about 50% duty #define STEP_DELAY 8 // ms per speed step: 256 steps x 8 ms is about 2 seconds // Turn the driver on: both half-bridges can now work void enableDriver() { digitalWrite(R_EN_PIN, HIGH); // right half-bridge on digitalWrite(L_EN_PIN, HIGH); // left half-bridge on } // Forward: PWM on RPWM, LPWM stays at 0 void motorForward(int speed) { analogWrite(LPWM_PIN, 0); // set LPWM to 0 first, so the two PWM pins are never on together analogWrite(RPWM_PIN, speed); // the duty on RPWM sets the forward speed } // Reverse: PWM on LPWM, RPWM stays at 0 void motorReverse(int speed) { analogWrite(RPWM_PIN, 0); // set RPWM to 0 first analogWrite(LPWM_PIN, speed); // the duty on LPWM sets the reverse speed } // Brake: both PWM pins at 0 while R_EN and L_EN are still HIGH. // The driver joins the two motor wires, so the motor stops quickly. void motorBrake() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); } // Coast: switch both half-bridges off. The motor is free and rolls to a stop by itself. void motorCoast() { analogWrite(RPWM_PIN, 0); // no PWM signal analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); // right half-bridge off digitalWrite(L_EN_PIN, LOW); // left half-bridge off } void setup() { Serial.begin(115200); // start the Serial Monitor at 115200 baud // The four control pins are outputs pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); // RPWM and LPWM only ever get analogWrite(), never digitalWrite(). // On the ESP32, a pin that makes PWM should keep using analogWrite(). analogWrite(RPWM_PIN, 0); // no forward signal yet analogWrite(LPWM_PIN, 0); // no reverse signal yet enableDriver(); // R_EN and L_EN HIGH only after both PWM pins are at 0 Serial.println("Coop door motor ready - ESP32 C3 Super Mini + BTS7960"); } void loop() { // 1) Forward: raise the duty one step at a time, from 0 to 255 Serial.println("Door up: speeding up (duty 0 to 255)"); for (int duty = 0; duty <= FULL_SPEED; duty++) { motorForward(duty); delay(STEP_DELAY); } // 2) Keep the top speed for 2 seconds Serial.println("Door up: top speed for 2 s"); delay(2000); // 3) Lower the duty step by step, back to 0 Serial.println("Door up: slowing down (duty 255 to 0)"); for (int duty = FULL_SPEED; duty >= 0; duty--) { motorForward(duty); delay(STEP_DELAY); } // 4) Brake for 1 second (both PWM pins 0, enable pins still HIGH) Serial.println("Door stop: brake on for 1 s"); motorBrake(); delay(1000); // 5) Reverse at about half speed for 2 seconds Serial.println("Door down: half speed (duty 128) for 2 s"); motorReverse(HALF_SPEED); delay(2000); // 6) Coast for 2 seconds: the driver is off, the motor rolls freely Serial.println("Door free: driver off, motor coasts for 2 s"); motorCoast(); delay(2000); // Turn the driver on again before the next forward run enableDriver(); Serial.println("... cycle over, starting again ..."); }

Detailed Instructions

  • First time with the ESP32 C3 Super Mini? Go through Getting Started with ESP32 C3 Super Mini once, so the ESP32 board package is installed in the Arduino IDE.
  • Wire everything: Put the C3 on the breadboard and add the six control wires. Then connect the motor and the DC power jack to the screw terminal. Keep the 12V adapter unplugged.
  • Connect USB: Join the ESP32 C3 Super Mini and your computer with a USB Type-C cable.
  • Choose board and port: In the Arduino IDE, pick ESP32C3 Dev Module under Tools > Board, then the COM port of the board.
  • Paste the code: Open a new sketch and paste the code above. There is nothing to install from the Library Manager.
  • Upload: Click the Upload button. The 12V adapter is still unplugged at this point.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Power the motor: Now plug in the 12V adapter.
  • Open Serial Monitor: Set it to 115200 baud.
  • Watch the motor: It speeds up, runs fast, slows down, stops, turns back slowly, and then drifts to a stop without power. The Serial Monitor names each move:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Coop door motor ready - ESP32 C3 Super Mini + BTS7960 Door up: speeding up (duty 0 to 255) Door up: top speed for 2 s Door up: slowing down (duty 255 to 0) Door stop: brake on for 1 s Door down: half speed (duty 128) for 2 s Door free: driver off, motor coasts for 2 s ... cycle over, starting again ... Door up: speeding up (duty 0 to 255) Door up: top speed for 2 s
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Door goes down instead of up? If the "Door up" lines turn the motor the other way than you want, unplug the 12V adapter and change over the two wires on M+ and M-. The sketch stays as it is.
  • Pro Tip: At low speed, the motor may hum or whine during the ramps. The sound comes from the PWM signal (about 1 kHz) and is normal. If the Serial Monitor stays empty, set USB CDC On Boot to Enabled in the Tools menu and upload again.

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Applications and Project Ideas

The C3 also has WiFi and Bluetooth LE, so the motor does not have to follow a fixed loop. Some ideas:

  • Automatic chicken coop door: open and close the door at set times, with the clock taken from the internet over WiFi
  • Daylight coop door: let an LDR module tell the C3 when it gets dark outside
  • Gate opener: move a light garden gate with a 12V gear motor and buttons on your phone
  • Small winch: pull a cart or a small boat up a ramp, slowly and with force
  • Wiper motor display: turn a car wiper motor at a slow, steady speed for a rotating sign
  • Heavy robot base: use two BTS7960 modules, one for each wheel motor

Video Tutorial

Challenge Yourself

Ready for more? Try these tasks:

  • Easy: Change HALF_SPEED from 128 to a smaller number and find the slowest speed at which your motor still turns
  • Easy: Raise STEP_DELAY from 8 to 20 for a softer start and a softer stop
  • Medium: Add two limit switches, one at the top and one at the bottom of the door, and brake the motor when one of them is pressed
  • Medium: Type commands in the Serial Monitor: "u" = door up, "d" = door down, "s" = brake, "c" = coast
  • Advanced: Open the door when the LDR module sees daylight and close it after dusk. Wait a few minutes before each move, so a passing cloud does not close the door
  • Advanced: Host a small web page on the C3 with "Open" and "Close" buttons for the coop door

※ 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!