Arduino UNO Q - BTS7960 Motor Driver

Picture a small conveyor belt on your workbench. It carries parts along, slows down while you load it, and stops when the box at the end is full. A belt like that needs a strong 12V gear motor, and a strong motor needs a driver that can take the current. That is the job of the BTS7960 module. On the Arduino UNO Q, the STM32 MCU tells the driver how fast and which way to turn. The Linux side then becomes the "boss" that starts, stops and slows down the belt.

What this page covers:

Arduino UNO Q controls a 12V DC motor with the BTS7960 motor driver module

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
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 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 .

The 12V adapter feeds the motor only. The Arduino UNO Q still runs from its USB-C cable. Look up how much current your motor draws, and pick an adapter that can give more than that.

Overview of the BTS7960 Motor Driver

The BTS7960 module is a heavy-duty driver for one brushed DC motor. You may also find it sold as IBT-2 or HW-039. Two Infineon BTS7960B chips sit on top of the board, and a big heat sink bolted underneath keeps them cool. Each chip is a half-bridge: it can switch one motor wire to the plus or to the minus of the supply. Two half-bridges together make a full H-bridge, so the motor can turn both ways. The speed comes from PWM: a higher duty cycle gives the motor more power.

Small drivers such as the DRV8833 are made for toy motors. The BTS7960 is made for motors that do real work: conveyor and winch gear motors, wiper motors, scooter motors and heavy robot wheels.

Feature BTS7960 Module
Motor supply (B+ / B-) 5.5V to 27V DC (6V, 12V and 24V systems)
Motors 1 brushed DC motor, both directions
Current up to 43A, where the chip's own current limit kicks in
PWM frequency up to 25 kHz on RPWM and LPWM
Logic chip 74HC14 buffer, powered from the VCC pin
Protection current limiting, over-temperature
Extra outputs R_IS / L_IS, current sense and fault signal

Do not read 43A as a number to run at all day. At that point the chip already holds the current back. For long runs, stay far below it. How long the board can carry a given current depends on how fast its heat sink loses heat.

BTS7960 motor driver module pinout with RPWM, LPWM, R_EN, L_EN, R_IS, L_IS, VCC, GND and the B+, B-, M+, M- screw terminal

The board has two groups of pins. A 2 x 4 pin header takes the small signals from the Arduino UNO Q. A screw terminal takes the big motor current.

Header pins (to the Arduino UNO Q):

  • RPWM (pin 1): PWM input for the forward direction. It runs the right half-bridge.
  • LPWM (pin 2): PWM input for the reverse direction. It runs the left half-bridge.
  • R_EN (pin 3): Switches the right half-bridge on (HIGH) or off (LOW).
  • L_EN (pin 4): Switches the left half-bridge on (HIGH) or off (LOW).
  • R_IS / L_IS (pins 5 and 6): Current sense and fault outputs. The board prints them as R_S and L_S. They stay unconnected in this tutorial.
  • VCC (pin 7): Powers only the 74HC14 logic chip and the power LED. It does not feed the motor.
  • GND (pin 8): Ground. On the module it is joined to B-.

The top row of the header holds VCC, R_IS, R_EN and RPWM. The bottom row holds GND, L_IS, L_EN and LPWM. Always go by the labels printed on your board.

Screw terminal (power side):

  • B+ / B-: plus and minus of the motor supply (here, the 12V adapter)
  • M+ / M-: the two wires of the DC motor

The 74HC14 chip sits between your board and the power chips. On the product page, this part is called the isolation chip. Your UNO Q pins talk only to this chip, never straight to the BTS7960B chips.

How RPWM, LPWM and the Enable Pins Move the Motor

With R_EN and L_EN both HIGH, the two PWM pins decide what happens:

RPWM LPWM Motor
PWM (0 to 255) 0 Forward, the duty cycle sets the speed
0 PWM (0 to 255) Reverse, the duty cycle sets the speed
0 0 Brake, the driver joins the two motor wires and the motor stops fast

Now pull R_EN and L_EN LOW. Both half-bridges switch off, and nothing holds the motor any more. It coasts and rolls to a stop by itself. On a conveyor, brake is the choice when a part must stop at one exact spot. Coast is fine when the belt only needs to stop at some point.

One rule above all: keep at least one of RPWM and LPWM at 0. Do not drive the two PWM pins together.

※ NOTE THAT:

  • VCC goes to the 5V pin of the Arduino UNO Q. VCC feeds only the 74HC14 logic chip, and the module maker specifies 5V for it. The maker lists 3.3V to 5V as the input level, so the 3.3V MCU pins of the UNO Q need no level shifter.
  • Nothing comes back to the board. R_IS and L_IS stay free, and the four control inputs have pull-down resistors, so no voltage from the module can reach a UNO Q pin.
  • One GND wire gives the common ground. GND and B- are joined on the module, so the GND wire to the UNO Q also ties the board to the minus of the 12V adapter.
  • Never connect B+ to the Arduino UNO Q. The 12V belongs on the screw terminal only.

BTS7960 or something smaller? The L298N drives two motors at about 2A each and loses about 2V inside. The BTS7960 drives only one motor, but it takes far more current and loses very little. For small motors, a DRV8833 is enough: see Arduino UNO Q - DRV8833 DC Motor Driver.

Wiring Diagram

The wiring has two sides that never mix. The signal side is six jumper wires from the BTS7960 header to the Arduino UNO Q. The power side is the 12V adapter and the motor, both on the screw terminal.

The wiring diagram between Arduino UNO Q BTS7960 motor driver

This image is created using Fritzing. Click to enlarge image

BTS7960 Pin Goes To
RPWM Arduino UNO Q D9 (PWM)
LPWM Arduino UNO Q D10 (PWM)
R_EN Arduino UNO Q D12
L_EN Arduino UNO Q D11
VCC Arduino UNO Q 5V (5V pin)
GND Arduino UNO Q GND
R_IS, L_IS leave free
B+ 12V adapter plus (+), via the DC power jack
B- 12V adapter minus (-), via the DC power jack
M+, M- the two wires of the 12V DC motor

If the project will run for a long time, or sit inside a box, it is better to fix the wires with screws. Put a Screw Shield V2 or a Proto Screw Terminal Block Shield on top of the Arduino UNO Q, then tighten each wire under a screw. Each wire goes to the screw terminal of the same pin, as in the image below.

The wiring diagram between Arduino UNO Q BTS7960 motor driver Screw Shield

This image is created using Fritzing. Click to enlarge image

A few things to check before power goes on:

  • Plug in the 12V adapter last, after every other wire is in place.
  • Check plus and minus on the DC power jack: adapter + to B+, adapter - to B-. Plus and minus the wrong way round can destroy the driver.
  • D9 and D10 carry the speed, so they must be PWM pins. R_EN and L_EN only switch on and off. If you move a wire, change the matching #define in the sketches.

How To Program For BTS7960

There is nothing to install. Four pins and two Arduino functions do all the work:

  1. Give the four pins names and make them outputs:
#define RPWM_PIN 9 // D9 -> RPWM #define LPWM_PIN 10 // D10 -> LPWM #define R_EN_PIN 12 // D12 -> R_EN #define L_EN_PIN 11 // D11 -> L_EN pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT);
  1. Switch the driver on. Set both PWM pins to 0 first, so the motor does not jump:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH);
  1. Run forward at a duty of 180 out of 255. LPWM stays at 0:
analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, 180);
  1. Run in reverse at the same speed. RPWM stays at 0:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 180);
  1. Brake: both PWM pins at 0, while R_EN and L_EN stay HIGH:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0);
  1. Coast: pull R_EN and L_EN LOW, and the driver lets go of the motor. Set them HIGH again before the next forward or reverse:
analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW);

In the sketch, these lines live in four small helpers: bts_forward(), bts_reverse(), bts_brake() and bts_coast(). Each helper writes 0 to the unused PWM pin first, so the two sides are never driven together.

Arduino UNO Q Code

Who does what on the board:

  • The STM32 MCU owns D9, D10, D11 and D12. PWM is real-time work, so the motor runs from here.
  • The Qualcomm MPU with Debian Linux has nothing to do yet. It takes over in the Bridge section.
  • The sketch repeats one test cycle: speed up forward, full speed, slow down, brake, half speed in reverse, coast.
/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-bts7960-motor-driver */ // Arduino UNO Q - BTS7960 43A Motor Driver (IBT-2): one 12V DC motor, both directions, PWM speed // The STM32 MCU of the Arduino UNO Q sends the PWM and enable signals to the BTS7960. // Wiring: RPWM -> D9, LPWM -> D10, R_EN -> D12, L_EN -> D11, VCC -> 5V, GND -> GND // The motor gets its power from a 12V adapter on B+ / B-, never from the Arduino UNO Q. #define RPWM_PIN 9 // Arduino UNO Q D9 (PWM) -> BTS7960 RPWM, forward speed #define LPWM_PIN 10 // Arduino UNO Q D10 (PWM) -> BTS7960 LPWM, reverse speed #define R_EN_PIN 12 // Arduino UNO Q D12 -> BTS7960 R_EN, right half-bridge on/off #define L_EN_PIN 11 // Arduino UNO Q D11 -> BTS7960 L_EN, left half-bridge on/off #define RAMP_STEP 5 // duty change per ramp step #define RAMP_DELAY 30 // milliseconds per ramp step (about 1.5 s from 0 to 255) // Both half-bridges on: needed to drive and to brake void bts_enable() { digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } // Forward: PWM on RPWM, LPWM stays 0. duty = 0 ... 255 void bts_forward(int duty) { analogWrite(LPWM_PIN, 0); // the other side first, so both sides are never driven together analogWrite(RPWM_PIN, duty); } // Reverse: PWM on LPWM, RPWM stays 0. duty = 0 ... 255 void bts_reverse(int duty) { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, duty); } // Brake: no PWM, but the driver stays on -> the two motor wires are joined, the shaft stops fast void bts_brake() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); bts_enable(); } // Coast: no PWM and both half-bridges off -> nothing holds the motor, it rolls to a stop void bts_coast() { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW); } void setup() { Serial.begin(115200); delay(1500); pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); analogWrite(RPWM_PIN, 0); // no speed signal yet analogWrite(LPWM_PIN, 0); bts_enable(); // then switch the driver on Serial.println("BTS7960 on UNO Q: driver enabled, motor at rest"); } void loop() { // 1. Forward, the duty climbs step by step Serial.println("[1] Forward ramp-up, duty 0 to 255"); for (int duty = 0; duty <= 255; duty += RAMP_STEP) { bts_forward(duty); delay(RAMP_DELAY); } // 2. Full speed forward for 2 seconds Serial.println("[2] Forward, full duty 255 for 2 s"); delay(2000); // 3. Forward, the duty falls back to 0 Serial.println("[3] Forward ramp-down, duty 255 to 0"); for (int duty = 255; duty >= 0; duty -= RAMP_STEP) { bts_forward(duty); delay(RAMP_DELAY); } // 4. Brake for 1 second Serial.println("[4] Brake for 1 s (both PWM 0, EN HIGH)"); bts_brake(); delay(1000); // 5. Reverse at about half speed for 2 seconds Serial.println("[5] Reverse, duty 128 (about half) for 2 s"); bts_reverse(128); delay(2000); // 6. Coast for 2 seconds: the driver lets go of the motor Serial.println("[6] Coast for 2 s (EN LOW, driver off)"); bts_coast(); delay(2000); bts_enable(); // switch the driver back on before the next round }

Detailed Instructions

New to the Arduino UNO Q? Follow Getting Started with Arduino UNO Q once, so Arduino App Lab is ready.

  • Signal wires: RPWM to D9, LPWM to D10, R_EN to D12, L_EN to D11, VCC to 5V and GND to GND, as in the diagram.
  • Power wires, adapter unplugged: Put the motor wires into M+ and M-, and the DC power jack into B+ (plus) and B- (minus).
  • Connect the board: Plug the Arduino UNO Q into your computer with the USB-C cable.
  • Open Arduino App Lab and wait until it shows your UNO Q.
  • New App: Click Create New App.
Create New App in Arduino App Lab on Arduino UNO Q
  • Call it BTS7960Motor and click Create.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste: Open sketch/sketch.ino, replace everything in it with the code above, and leave the other files alone.
  • Run: Click the Run button. The 12V adapter is still unplugged, so the motor stays still while the sketch uploads and starts.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Power the motor: Now plug the 12V adapter into the DC power jack. Hold or clamp the motor, because a 12V gear motor has real force.
  • Watch: Follow the console and the motor together. If "forward" turns the wrong way for your belt, swap the two motor wires on M+ and M-.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-11-18 09:12:04] BTS7960 on UNO Q: driver enabled, motor at rest [2026-11-18 09:12:04] [1] Forward ramp-up, duty 0 to 255 [2026-11-18 09:12:05] [2] Forward, full duty 255 for 2 s [2026-11-18 09:12:07] [3] Forward ramp-down, duty 255 to 0 [2026-11-18 09:12:09] [4] Brake for 1 s (both PWM 0, EN HIGH) [2026-11-18 09:12:10] [5] Reverse, duty 128 (about half) for 2 s [2026-11-18 09:12:12] [6] Coast for 2 s (EN LOW, driver off) [2026-11-18 09:12:14] [1] Forward ramp-up, duty 0 to 255 [2026-11-18 09:12:15] [2] Forward, full duty 255 for 2 s

Watch step 6 closely. After half speed in reverse, the motor slows down little by little, because the driver no longer holds it. In step 4 the driver holds the motor wires together, so the shaft is not free. At low duty you may also hear the motor hum or whine. That sound comes from the PWM signal and is normal.

Bridge: Linux + MCU

Now the conveyor gets a boss. A Python program on the Linux side decides when the belt starts, how fast it runs and when it stops. The MCU still makes every PWM pulse. Keep the same wiring.

  • The BTS7960 stays wired to the MCU. Only the MCU writes to D9, D10, D11 and D12.
  • The MCU offers these functions to Linux:
    • forward / reverse: run the belt one way at the current speed
    • brake: stop fast and hold
    • coast: switch the driver off and let the belt roll out
    • set_speed: a number from 0 to 255. A running belt changes at once, which is handy for slowing down while you load it
    • get_state and get_speed: read-only, they answer with text like forward and 200
  • The five functions that change pins are registered with Bridge.provide_safe(). The two read-only ones use plain Bridge.provide().
  • ⚠️ The router keeps /dev/ttyHS1 (Linux) and Serial1 (MCU) for itself. They are RESERVED: your code must never open them.

The path of one command: Python calls set_speed or forward → the MCU changes RPWM / LPWM → the BTS7960 sends 12V power to the motor.

MCU Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-bts7960-motor-driver */ // Arduino UNO Q - BTS7960 motor driver: a conveyor belt motor, run from Linux via Bridge // Wiring: RPWM -> D9, LPWM -> D10, R_EN -> D12, L_EN -> D11, VCC -> 5V, GND -> GND // Only the MCU drives the BTS7960 pins. Python on Linux calls the functions below by name. #include "Arduino_RouterBridge.h" #define RPWM_PIN 9 // D9 (PWM) -> BTS7960 RPWM, forward #define LPWM_PIN 10 // D10 (PWM) -> BTS7960 LPWM, reverse #define R_EN_PIN 12 // D12 -> BTS7960 R_EN #define L_EN_PIN 11 // D11 -> BTS7960 L_EN #define MODE_COAST 0 #define MODE_BRAKE 1 #define MODE_FORWARD 2 #define MODE_REVERSE 3 const char* MODE_NAMES[] = {"coast", "brake", "forward", "reverse"}; int belt_mode = MODE_COAST; // what the belt does now int belt_duty = 150; // speed for forward / reverse, 0..255, changed from Linux // Write the pins for the current mode and duty. // The PWM pin of the unused side is always set to 0 first. void apply_mode() { if (belt_mode == MODE_FORWARD) { analogWrite(LPWM_PIN, 0); analogWrite(RPWM_PIN, belt_duty); } else if (belt_mode == MODE_REVERSE) { analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, belt_duty); } else { // brake and coast: no PWM at all analogWrite(RPWM_PIN, 0); analogWrite(LPWM_PIN, 0); } // Only coast switches the two half-bridges off if (belt_mode == MODE_COAST) { digitalWrite(R_EN_PIN, LOW); digitalWrite(L_EN_PIN, LOW); } else { digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH); } } void belt_forward() { belt_mode = MODE_FORWARD; apply_mode(); Monitor.println("Belt forward, duty " + String(belt_duty)); } void belt_reverse() { belt_mode = MODE_REVERSE; apply_mode(); Monitor.println("Belt reverse, duty " + String(belt_duty)); } void belt_brake() { belt_mode = MODE_BRAKE; apply_mode(); Monitor.println("Belt brake"); } void belt_coast() { belt_mode = MODE_COAST; apply_mode(); Monitor.println("Belt coast, driver off"); } // A new speed. A running belt changes at once. A stopped belt uses it on the next start. void set_speed(int value) { belt_duty = constrain(value, 0, 255); if (belt_mode == MODE_FORWARD || belt_mode == MODE_REVERSE) { apply_mode(); Monitor.println("Speed set to " + String(belt_duty) + " (applied now)"); } else { Monitor.println("Speed set to " + String(belt_duty) + " (used on next start)"); } } // Read-only: "forward", "reverse", "brake" or "coast" String get_state(String arg) { return String(MODE_NAMES[belt_mode]); } // Read-only: the duty from 0 to 255 String get_speed(String arg) { return String(belt_duty); } void setup() { Bridge.begin(); Monitor.begin(); pinMode(RPWM_PIN, OUTPUT); pinMode(LPWM_PIN, OUTPUT); pinMode(R_EN_PIN, OUTPUT); pinMode(L_EN_PIN, OUTPUT); apply_mode(); // start in coast: no PWM, driver off // These functions change hardware pins, so they are registered with provide_safe Bridge.provide_safe("forward", belt_forward); Bridge.provide_safe("reverse", belt_reverse); Bridge.provide_safe("brake", belt_brake); Bridge.provide_safe("coast", belt_coast); Bridge.provide_safe("set_speed", set_speed); // Read-only values, so plain provide() is enough Bridge.provide("get_state", get_state); Bridge.provide("get_speed", get_speed); Monitor.println("BTS7960 Bridge ready - belt at rest (coast)"); } void loop() {}

Python Code (Bridge)

The Python script plays one short work cycle of the belt: normal speed, a slow part for loading, a brake when the box is full, a short move back, and a pause.

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-bts7960-motor-driver """ from arduino.app_utils import * import time # Linux side: one work cycle of a small conveyor belt. # The MCU makes every PWM pulse. Python only decides what the belt does next. def report(note): mode = str(Bridge.call("get_state")) # "forward", "reverse", "brake" or "coast" speed = int(str(Bridge.call("get_speed"))) # 0..255 if mode in ("forward", "reverse"): print(f"{note}: belt {mode} at {speed}/255") else: print(f"{note}: belt {mode}") def loop(): Bridge.call("set_speed", 200) Bridge.call("forward") report("Normal run") time.sleep(4) Bridge.call("set_speed", 90) # the belt keeps moving, only slower report("Loading, slow down") time.sleep(3) Bridge.call("brake") report("Box is full") time.sleep(2) Bridge.call("set_speed", 120) Bridge.call("reverse") report("Back up a little") time.sleep(1.5) Bridge.call("coast") report("Pause") time.sleep(3) App.run(user_loop=loop)

Detailed Instructions

  • Second App: Back in Arduino App Lab, click Create New App again. This time call it BTS7960Bridge.
  • Sketch: Put the MCU code above into sketch/sketch.ino, then add one library to the App:
  • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • Python: Put the Python code into the App's Python file (same App, no second one).
  • Run: Click the Run button, then plug in the 12V adapter.
  • Compare the two consoles: The Python console says what Linux asked for. The MCU console says what the pins did.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-11-18 11:40:20] BTS7960 Bridge ready - belt at rest (coast) [2026-11-18 11:40:21] Speed set to 200 (used on next start) [2026-11-18 11:40:21] Belt forward, duty 200 [2026-11-18 11:40:25] Speed set to 90 (applied now) [2026-11-18 11:40:28] Belt brake [2026-11-18 11:40:30] Speed set to 120 (used on next start) [2026-11-18 11:40:30] Belt reverse, duty 120 [2026-11-18 11:40:31] Belt coast, driver off [2026-11-18 11:40:34] Speed set to 200 (used on next start) [2026-11-18 11:40:34] Belt forward, duty 200
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-18 11:40:21] Normal run: belt forward at 200/255 [2026-11-18 11:40:25] Loading, slow down: belt forward at 90/255 [2026-11-18 11:40:28] Box is full: belt brake [2026-11-18 11:40:30] Back up a little: belt reverse at 120/255 [2026-11-18 11:40:31] Pause: belt coast [2026-11-18 11:40:34] Normal run: belt forward at 200/255

Look at the line at 11:40:25. The belt never stopped there. It only slowed from 200 to 90, because set_speed changes a running belt at once.

Telegram

A conveyor often stands far from your desk. With a Telegram bot you can start it, slow it down or stop it from your phone. Two safety rules are built into the script:

  • Run timer: if the belt has run for 2 minutes with no new command, it brakes by itself and tells you. Change RUN_LIMIT if your belt needs longer runs.
  • No sudden turn-around: if you send /reverse while the belt runs forward (or the other way), it brakes for half a second first. That is kinder to the motor, the gears and the driver.
Command What it does
/forward run the belt forward at the set speed
/reverse run the belt backward
/speed N set the speed from 0 to 255, also while the belt runs
/brake stop fast and hold
/coast driver off, the belt rolls to a stop
/status what the belt is doing right now

No bot yet? Make one with How to Create a Telegram Bot and copy its token.

On the MCU side, nothing changes. The bot talks to the same Bridge sketch as above.

Python Code (Telegram)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-bts7960-motor-driver """ from arduino.app_utils import * import requests import time # Linux side: a Telegram bot for the BTS7960 conveyor belt. # Keep the MCU sketch from the Bridge section. It offers forward, reverse, # brake, coast, set_speed, get_state and get_speed. BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" RUN_LIMIT = 120 # seconds: the belt brakes by itself after this long without a new command FLIP_PAUSE = 0.5 # seconds of braking before the direction changes last_update_id = 0 last_command_time = 0 running = False alert_chat = None # the chat that started the belt gets the run-timer message HELP_TEXT = ( "Conveyor belt commands:\n" "/forward - run forward\n" "/reverse - run backward\n" "/speed N - speed 0-255, also while running\n" "/brake - stop fast and hold\n" "/coast - driver off, belt rolls to a stop\n" "/status - what the belt does now" ) STOPPED_TEXT = { "brake": "Belt: braked, held still.", "coast": "Belt: coasting, driver off.", } def send_message(chat_id, text): try: requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}, timeout=10) except Exception as e: print(f"Error sending message: {e}") def get_updates(): try: resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}, timeout=10) return resp.json().get("result", []) except Exception as e: print(f"Error getting updates: {e}") return [] def belt_speed(): return int(str(Bridge.call("get_speed"))) def run(direction, chat_id): global running, last_command_time, alert_chat mode = str(Bridge.call("get_state")) if mode in ("forward", "reverse") and mode != direction: # Never flip the direction at speed: brake for a moment first print("Direction change: brake first") Bridge.call("brake") time.sleep(FLIP_PAUSE) Bridge.call(direction) running = True last_command_time = time.time() alert_chat = chat_id word = "forward" if direction == "forward" else "in reverse" send_message(chat_id, f"Belt running {word} at {belt_speed()}/255.") def stop(action, chat_id, reply): global running Bridge.call(action) running = False send_message(chat_id, reply) def handle(text, chat_id): global last_command_time if text == "/forward": run("forward", chat_id) elif text == "/reverse": run("reverse", chat_id) elif text == "/brake": stop("brake", chat_id, "Belt braked and held.") elif text == "/coast": stop("coast", chat_id, "Driver off. The belt rolls to a stop.") elif text.startswith("/speed"): parts = text.split() if len(parts) == 2 and parts[1].isdigit() and int(parts[1]) <= 255: speed = int(parts[1]) Bridge.call("set_speed", speed) if running: last_command_time = time.time() # a new speed also counts as a command send_message(chat_id, f"Speed is now {speed}/255. The belt changed at once.") else: send_message(chat_id, f"Speed is now {speed}/255. It is used on the next /forward or /reverse.") else: send_message(chat_id, "Usage: /speed 0-255 (example: /speed 120)") elif text == "/status": mode = str(Bridge.call("get_state")) if mode in ("forward", "reverse"): speed = belt_speed() send_message(chat_id, f"Belt: {mode} at {speed}/255 ({speed * 100 // 255}%).") else: send_message(chat_id, STOPPED_TEXT.get(mode, f"Belt: {mode}.")) else: send_message(chat_id, HELP_TEXT) def loop(): global last_update_id, running for update in get_updates(): last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if not chat_id: continue print(f"Telegram: {text}") handle(text, chat_id) # Run timer: brake the belt if nobody sent a command for RUN_LIMIT seconds if running and time.time() - last_command_time > RUN_LIMIT: Bridge.call("brake") running = False print(f"Run timer: belt braked after {RUN_LIMIT} s") if alert_chat: send_message(alert_chat, f"Run timer: no command for {RUN_LIMIT} s, so the belt was braked.") time.sleep(1) App.run(user_loop=loop)

Detailed Instructions

  • Token: Paste the token from @BotFather into BOT_TOKEN.
  • New Python, old sketch: In the BTS7960Bridge App, delete the old Python code and paste the bot code in its place.
  • Run: Click the Run button and plug in the 12V adapter.
  • Try it: Send /speed 150, then /forward. While the belt runs, send /speed 70 and watch it slow down. Finish with /brake.
  • Check: Send /status at any time to see what the belt is doing.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-18 16:05:12] Telegram: /speed 150 [2026-11-18 16:05:19] Telegram: /forward [2026-11-18 16:05:41] Telegram: /speed 70 [2026-11-18 16:05:58] Telegram: /status [2026-11-18 16:06:10] Telegram: /reverse [2026-11-18 16:06:10] Direction change: brake first [2026-11-18 16:08:11] Run timer: belt braked after 120 s
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/speed 150
10:15 AM ✓✓
Speed is now 150/255. It is used on the next /forward or /reverse.
10:16 AM
/forward
10:17 AM ✓✓
Belt running forward at 150/255.
10:18 AM
/speed 70
10:19 AM ✓✓
Speed is now 70/255. The belt changed at once.
10:20 AM
/status
10:21 AM ✓✓
Belt: forward at 70/255 (27%).
10:22 AM
/reverse
10:23 AM ✓✓
Belt running in reverse at 70/255.
10:24 AM
Run timer: no command for 120 s, so the belt was braked.
10:25 AM

The last message came from the bot by itself. After /reverse, nobody sent anything for two minutes, so the run timer stopped the belt.

OpenClaw

You can adapt the OpenClaw to this tutorial by refering the instruction on Arduino Uno Q - OpenClaw Tutorial

Project Ideas

The BTS7960 is made for motors that move real loads. Some builds that use both halves of the Arduino UNO Q:

  • Sorting Conveyor: Add a color sensor at the end of the belt. Python on Linux decides where each part goes, and the belt slows down while a small gate moves.
  • Garden Cart Winch: A 12V winch motor pulls a cart up a slope. A soft ramp keeps the cable from jerking, and a limit switch stops it at the top.
  • Gate Opener: A 24V gear motor opens a garden gate when you send a Telegram command, with a limit switch at each end.
  • Feed Auger: A screw auger moves animal feed out of a tank. The Linux side runs it for a few seconds at set times each day.
  • Heavy Robot Base: Use one BTS7960 per wheel motor for a robot that carries a load. The second driver needs two more PWM pins.

Challenge Yourself

Three tasks to test what you learned on this page:

  • Easy: Change RAMP_DELAY in the first sketch so the motor needs about 5 seconds to reach full speed instead of about 1.5 seconds.
  • Medium: Add a soft stop to the Bridge sketch: a slow_stop function that lowers the duty step by step in loop() with millis() (not delay()), then brakes.
  • Advanced: Put an IR sensor at the end of the belt. When a part arrives, the MCU brakes at once, and the Telegram bot sends "part at the end of the belt" to your phone.

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