Arduino UNO R4 - DC Motor Shield
The Arduino Uno R4 - available as Minima and WiFi - brings more processing power, additional memory, and a 14-bit ADC while keeping the classic Uno header layout. That means the Motor Shield Rev3 plugs straight onto the Uno R4 with zero extra wiring.
In this guide you will:
- Stack the Motor Shield Rev3 onto an Arduino Uno R4 board.
- Wire a DC motor and an external battery pack.
- Write code that spins the motor forward and backward.
- Adjust motor speed through PWM values (0-255).
- Apply and release the electronic brake.
- Monitor motor current draw through the analog sensing pin.
- Operate two motors at once using Channel A and Channel B.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
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 work duty. 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 Uno R4 shares the exact same header positions as the original Uno R3, 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 (such as two 18650 lithium cells in series) to the shield's power screw terminals. The Arduino itself can continue running from USB.
Wiring Diagram
Place the Motor Shield Rev3 onto the Uno R4 headers, making sure every pin seats properly.
Attach the DC motor leads to the Channel A screw terminals - the channel labels are printed on the board.
Hook up the external battery pack to the power screw terminals.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
How to Install the Library
- Plug the Arduino Uno R4 into your computer using a USB Type-C cable.
- In the Arduino IDE, verify that the correct board (Arduino Uno R4 Minima or WiFi) and serial port are selected.
- Click the Libraries icon in the left sidebar.
- Type "DIYables_DC_Motor" into the search box and locate the library published by DIYables.
- Hit Install to add the library to your IDE.

No additional dependencies are needed - the library is entirely self-contained.
Minimal Sketch Structure
All motor control sketches share this skeleton:
motor.begin() configures the direction, PWM, and brake pins. Calling motor.run() sets the direction, releases the brake, and applies the requested speed. motor.brake() engages the brake and cuts the PWM to zero.
Single Motor on Channel A
Run a motor on Channel A, toggling between forward and backward every two seconds with a full stop in between.
How to Run
- Place the shield on the Uno R4 and connect the motor to Channel A.
- Connect the battery pack to the power terminals.
- Plug in the USB Type-C cable.
- Paste the code in Arduino IDE, choose the correct board and port, and press Upload.
- Open the Serial Monitor to follow the direction changes.
The motor alternates between forward and backward at speed 30, pausing 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, but on Channel B - just swap the channel constant.
How to Run
- Wire the motor to the Channel B screw terminals.
- Upload the sketch and open the Serial Monitor.
Everything works the same way; only the underlying pins differ.
Two Motors - Both Channels
Drive two motors independently: same direction, opposite direction, and synchronized braking.
How to Run
- Attach one motor to Channel A and another to Channel B.
- Upload and open the Serial Monitor.
The sketch cycles through three patterns: both forward, both backward, and motors spinning in opposite directions.
Reading Motor Current
Monitor the current consumption of a motor in real time.
How to Run
- Wire a motor to Channel A.
- Upload the sketch and open the Serial Monitor.
- The raw ADC value refreshes every 500 ms.
About Current Sensing
Analog pins A0 and A1 carry a voltage proportional to the motor current on Channel A and Channel B respectively. readCurrent() returns the raw ADC reading - on the Uno R4 this is a 14-bit value (0-16383) thanks to the Renesas RA4M1 ADC. Convert to milliamps using the shield's documented sensitivity factor.
Custom Pin Assignment
If you need to override the default pin mapping - for example, when using a third-party motor driver board - pass the pins directly to the constructor.
How to Run
- Update the pin numbers in the constructor to match your hardware.
- Upload and verify motor operation.
Troubleshooting
- Motor stays still - Confirm the motor wires sit firmly in the screw terminals and that the channel matches the code (MOTOR_CH_A vs. MOTOR_CH_B).
- No torque - Raise the speed value. Very low PWM values may not overcome the motor's inertia.
- External supply dead - Recharge or replace the batteries. Check that polarity is correct at the power terminals.
- Direction seems wrong - Swap the two motor leads at the screw terminal, or flip the direction constant in software.
- Current reading always zero - Make sure you used the channel constructor or the 4-pin constructor that includes the current-sensing pin.
Platform Support
The library relies exclusively on Arduino standard APIs (pinMode, digitalWrite, analogWrite, analogRead) and runs on all Arduino-compatible platforms.