Arduino UNO Q - DC Motor Shield

The Motor Shield Rev3 plugs directly onto the Arduino UNO Q headers — same pin layout as the classic Uno. In this guide you will:

Arduino UNO Q DC Motor Shield

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Motor Shield for Arduino
1×DC Motor
1×Power source (e.g., 9V power adapter)
1×DC Power Jack
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 .

Motor Shield Rev3 Overview

At the heart of the Motor Shield Rev3 sits the L298P dual full-bridge driver. This chip gives you independent control over two DC motors — each with its own direction line, PWM speed line, brake line, and current-sensing analog input.

Here is what each control line does:

  • Direction — a digital output that sets the spin direction. Writing HIGH spins one way; LOW spins the other.
  • PWM — an analog (PWM) output that sets the duty cycle. Values range from 0 (stopped) to 255 (full speed).
  • Brake — a digital output. Setting it HIGH locks the motor shaft; setting it LOW lets the motor spin freely.
  • Current Sensing — an analog input that reports how much current the motor is drawing.

Because the Arduino UNO Q keeps the same header positions as the classic Uno, every pin lines up automatically:

Function Channel A Channel B
Direction D12 D13
PWM (Speed) D3 D11
Brake D9 D8
Current Sensing A0 A1

Powering the Motors

Motors need more current than USB can provide. Connect a 6–12 V external supply to the shield's power screw terminals. The Arduino UNO Q itself continues running from USB.

Wiring Diagram

Place the Motor Shield Rev3 onto the Arduino UNO Q headers, making sure every pin seats properly. Attach the DC motor leads to the Channel A screw terminals. Hook up the external power supply to the power screw terminals.

The wiring diagram between Arduino UNO Q DC Motor Shield

This image is created using Fritzing. Click to enlarge image

Single Motor on Channel A

MCU Code

The Arduino UNO Q has two processors: the STM32 MCU (handles real-time hardware control) and the Qualcomm MPU (runs Debian Linux). In this section, only the STM32 MCU is programmed — the Linux side stays idle. A later section will show how both processors work together.

The code below alternates the motor direction every 2 seconds with braking in between:

/* * 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-dc-motor-shield */ #include <DIYables_DC_Motor.h> DIYables_DC_Motor motor(MOTOR_CH_A); bool directionState = false; void setup() { motor.begin(); } void loop() { directionState = !directionState; int direction = directionState ? MOTOR_FORWARD : MOTOR_BACKWARD; motor.run(direction, 30); delay(2000); motor.brake(); delay(2000); }

Detailed Instructions

  • First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial to get your development environment ready before proceeding.
  • Stack the shield: Firmly press the Motor Shield Rev3 onto the Arduino UNO Q headers.
  • Wire the motor: Connect your DC motor to the Channel A screw terminals.
  • Connect power: Attach the external power supply to the shield's power terminals.
  • Connect: Plug the Arduino UNO Q into your computer with a USB-C cable.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: DIYables_DCMotorShield
  • Click Create to confirm.
  • You will see a set of folders and files generated inside your new App.
Arduino App Lab App folders and files on Arduino UNO Q
  • Find the sketch/sketch.ino file — this is where you will paste the MCU sketch.
  • Paste the sketch: Copy the MCU code above and paste it into the sketch file. Keep other files as default.
    • 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 DIYables_DC_Motor created by DIYables.io 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
    DIYables_DC_Motor DIYables.io

    Easy-to-use library for controlling DC motors via the Arduino Motor Shield Rev3 (L298P). Supports both Channel A and Channel B with direction control, PWM speed, brake, and current sensing. Custom pin assignments also supported.

    1.0.0
    Install
    More Info
    • 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
    • Upload: Click the Run button in Arduino App Lab to compile and upload to the STM32.
    Click Run button in Arduino App Lab on Arduino UNO Q
    • Observe: The motor alternates between forward and backward every 2 seconds, braking for 2 seconds between each direction change.

    Method Quick Reference

    Method What It Does Usage
    run(dir, speed) Spins the motor in the given direction at the given speed motor.run(MOTOR_FORWARD, 100)
    setSpeed(speed) Changes speed without touching direction or brake motor.setSpeed(200)
    setDirection(dir) Changes direction without touching speed or brake motor.setDirection(MOTOR_BACKWARD)
    brake() Engages the brake and drops speed to zero motor.brake()
    release() Disengages the brake motor.release()
    readCurrent() Returns raw ADC from the current-sensing pin motor.readCurrent()

    Single Motor on Channel B

    Identical behavior to Channel A, but on Channel B — just swap the channel constant.

    /* * 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-dc-motor-shield */ #include <DIYables_DC_Motor.h> DIYables_DC_Motor motor(MOTOR_CH_B); bool directionState = false; void setup() { motor.begin(); } void loop() { directionState = !directionState; int direction = directionState ? MOTOR_FORWARD : MOTOR_BACKWARD; motor.run(direction, 30); delay(2000); motor.brake(); delay(2000); }

    Detailed Instructions

    • Wire the motor to the Channel B screw terminals.
    • Follow the same Quick Steps as the Channel A section above (create App, paste sketch, install libraries, upload).
    • The motor alternates direction and brakes the same way — only the underlying pins differ.

    Two Motors — Both Channels

    Drive two motors independently: both forward, both backward, and opposite directions.

    /* * 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-dc-motor-shield */ #include <DIYables_DC_Motor.h> DIYables_DC_Motor motorA(MOTOR_CH_A); DIYables_DC_Motor motorB(MOTOR_CH_B); void setup() { motorA.begin(); motorB.begin(); } void loop() { // Both motors forward motorA.run(MOTOR_FORWARD, 100); motorB.run(MOTOR_FORWARD, 100); delay(2000); // Brake both motorA.brake(); motorB.brake(); delay(1000); // Both motors backward motorA.run(MOTOR_BACKWARD, 100); motorB.run(MOTOR_BACKWARD, 100); delay(2000); // Brake both motorA.brake(); motorB.brake(); delay(1000); // Opposite directions motorA.run(MOTOR_FORWARD, 100); motorB.run(MOTOR_BACKWARD, 100); delay(2000); // Brake both motorA.brake(); motorB.brake(); delay(1000); }

    Detailed Instructions

    • Attach one motor to Channel A and another to Channel B screw terminals.
    • Follow the same Quick Steps as the Channel A section above (create App, paste sketch, install libraries, upload).
    • The sketch cycles through both-forward, both-backward, and opposite-direction patterns.

    Linux + MCU Bridge Programming

    The Arduino UNO Q has two processors that work together: the MPU (Qualcomm, runs Debian Linux) and the MCU (STM32, runs Zephyr OS with your Arduino sketch). They communicate using RPC via the Arduino_RouterBridge library — never via raw serial ports.

    • The Motor Shield is connected to the MCU (STM32) — direction, PWM, and brake pins are all on the Arduino UNO Q header, driven by the STM32.
    • The MPU cannot control the motor shield directly — it must call a function on the MCU via Bridge.call() to spin forward, backward, or brake.
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can receive Telegram commands and remotely control the motor.
    • Communication: Bridge.call() on the Linux side invokes Bridge.provide_safe() functions on the MCU side (since motor.run() and motor.brake() use hardware APIs)
    • ⚠️ Reserved: /dev/ttyHS1 (Linux) and Serial1 (MCU) are used by the Arduino Router — never open them directly

    In short: MPU sends command → MCU drives Motor Shield → Motor Shield controls DC motor.

    MCU sketch — Motor Shield control with Bridge and Monitor output:

    /* * 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-dc-motor-shield */ #include "Arduino_RouterBridge.h" #include <DIYables_DC_Motor.h> DIYables_DC_Motor motor(MOTOR_CH_A); void motor_forward() { motor.run(MOTOR_FORWARD, 200); Monitor.println("Motor: Forward"); } void motor_backward() { motor.run(MOTOR_BACKWARD, 200); Monitor.println("Motor: Backward"); } void motor_brake() { motor.brake(); Monitor.println("Motor: Brake"); } void setup() { Bridge.begin(); Monitor.begin(); motor.begin(); motor.brake(); Bridge.provide_safe("forward", motor_forward); Bridge.provide_safe("backward", motor_backward); Bridge.provide_safe("brake", motor_brake); Monitor.println("DC Motor Shield Bridge ready"); } void loop() {}

    Python script (Arduino App Lab) — control motor from Linux:

    /* * 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-dc-motor-shield */ from arduino.app_utils import * import time def loop(): print("Motor spinning forward") Bridge.call("forward") time.sleep(3) print("Motor braking") Bridge.call("brake") time.sleep(1) print("Motor spinning backward") Bridge.call("backward") time.sleep(3) print("Motor braking") Bridge.call("brake") time.sleep(1) App.run(user_loop=loop)
    • Note: Make sure Bridge.begin() is called in the MCU sketch and the sketch is uploaded before running the Python script on the Linux side.
    • ⚠️ Warning: Never directly open /dev/ttyHS1 (on Linux) or use Serial1 (on MCU) in your code — these are reserved by the Arduino Router and accessing them will break the Bridge.

    Detailed Instructions

    • Upload the MCU sketch: Open Arduino App Lab, create a new App, paste the Bridge MCU sketch into sketch/sketch.ino, install both DIYables_DC_Motor and Arduino_RouterBridge libraries, and click Run.
    • Add the Python script: Paste the Python code above into the Python tab of the same App.
    • Run the App: Click Run — Python cycles the motor forward, brake, backward, brake automatically.
    • Check the console: Open the Console tab → MCU Monitor subtab to see motor status messages.

    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
    DC Motor Shield Bridge ready Motor: Forward Motor: Brake Motor: Backward Motor: Brake

    Telegram Integration

    Control the DC motor remotely from anywhere via Telegram.

    If you do not have a Telegram bot yet, see How to Create a Telegram Bot to get your bot token before continuing.

    MCU sketch: Keep the same MCU sketch from the previous Bridge section — no changes needed. Make sure it is already uploaded and running on the STM32 before proceeding.

    Python script (Arduino App Lab) — Telegram bot for motor shield control:

    /* * 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-dc-motor-shield */ from arduino.app_utils import * import requests import time BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" last_update_id = 0 def send_message(chat_id, text): requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) def get_updates(): global last_update_id resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) return resp.json().get("result", []) def loop(): global last_update_id updates = get_updates() for update in updates: last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if text == "/forward": Bridge.call("forward") send_message(chat_id, "Motor spinning forward.") elif text == "/backward": Bridge.call("backward") send_message(chat_id, "Motor spinning backward.") elif text == "/brake": Bridge.call("brake") send_message(chat_id, "Motor braking.") else: send_message(chat_id, "Commands:\n/forward — spin motor forward\n/backward — spin motor backward\n/brake — brake motor") time.sleep(1) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /forward to spin the motor forward.
    • Send /backward to spin the motor backward.
    • Send /brake to brake the motor.

    Detailed Instructions

    • Upload the MCU sketch: Use the Bridge MCU sketch from the previous section (upload it first if not already done).
    • Paste the Telegram script: Copy the Python code above into the Python tab of your App in Arduino App Lab.
    • Set your token: Replace YOUR_BOT_TOKEN in the script with your actual bot token.
    • Run the App: Click Run — the bot starts listening for Telegram messages.
    • Test it: Send /forward — the motor spins. Send /brake — it stops hard. Send /backward — it reverses.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /forward [2026-04-29 12:00:01] Motor spinning forward. [2026-04-29 12:02:10] Telegram: /backward [2026-04-29 12:02:10] Motor spinning backward. [2026-04-29 12:04:05] Telegram: /brake [2026-04-29 12:04:05] Motor braking.
    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
    /forward
    10:15 AM ✓✓
    Motor spinning forward.
    10:16 AM
    /backward
    10:17 AM ✓✓
    Motor spinning backward.
    10:18 AM
    /brake
    10:19 AM ✓✓
    Motor braking.
    10:20 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q DC motor shield control is coming soon.

    • Coming Soon: OpenClaw support for controlling DC motors via the Motor Shield on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    • Remote robot drive: Use Channel A and Channel B together to build a two-motor differential-drive robot controlled via Telegram
    • Automated conveyor: Drive a Channel A motor forward or backward on schedule using the MPU's Linux cron
    • Motorized camera slider: Use precise PWM speed control to move a camera smoothly along a track
    • Dual-axis turntable: Control two motors simultaneously for pan and tilt motion via Telegram commands
    • Smart fan controller: Adjust fan speed remotely — set slow, medium, or full speed from Telegram

    Challenge Yourself

    • Easy: Add a /status Telegram command that reports the current motor state (forward, backward, or braking)
    • Medium: Add a /speed <0-255> Telegram command to set the PWM speed before spinning
    • Advanced: Control both Channel A and Channel B independently from Telegram using commands like /a forward, /b backward, /a brake

    Function References

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