Easy-to-use Arduino library for controlling DC motors via the **Arduino Motor Shield (L298P dual full-bridge driver). Supports both Channel A and Channel B with direction control, PWM speed, brake, and current sensing.
| Board | Tested |
|---|---|
| Arduino Uno R3 | ✅ |
| Arduino Uno R4 WiFi | ✅ |
| Arduino Uno R4 Minima | ✅ |
| Arduino Mega | ✅ |
| Arduino Giga | ✅ |
| DIYables STEM V4 IoT (works like Arduino Uno R4 WiFi) | ✅ |
| DIYables STEM V4B IoT (works like Arduino Uno R4 WiFi) | ✅ |
| DIYables STEM V3 (works like Arduino Uno R3) | ✅ |
| DIYables STEM V4B Edu (works like Arduino Uno R4 Minima) | ✅ |
| DIYables MEGA2560 R3 (works like Arduino Mega 2560 Rev3) | ✅ |
| Other boards | Not yet, expected to work |
- Control DC motors on Channel A and/or Channel B
- Set direction (forward / backward)
- Set speed via PWM (0-255)
- Activate and release brake
- Read motor current via analog sensing pins
- Support for custom pin assignments
- Arduino UNO (or compatible board)
- Arduino Motor Shield Rev3
- DC motor (6-12V)
- External power source (e.g., 2x 3.7V Li-Ion 18650 batteries)
| Function | Channel A | Channel B |
|---|---|---|
| Direction | D12 | D13 |
| PWM (speed) | D3 | D11 |
| Brake | D9 | D8 |
| Current Sensing | A0 | A1 |
#include <DIYables_DC_Motor.h>
DIYables_DC_Motor motor(MOTOR_CH_A);
void setup() {
motor.begin();
}
void loop() {
motor.run(MOTOR_FORWARD, 100); // forward at speed 100
delay(2000);
motor.brake(); // stop
delay(1000);
motor.run(MOTOR_BACKWARD, 100); // backward at speed 100
delay(2000);
motor.brake(); // stop
delay(1000);
}- ChannelA: Control a motor on Channel A
- ChannelB: Control a motor on Channel B
- BothChannels: Control two motors simultaneously
- CurrentSensing: Read motor current draw
- CustomPins: Use custom pin assignments
See DIYables DC Motor Library Reference for the complete API documentation including all constructors, methods, and constants.
- Arduino - DC Motor Shield
- Arduino Uno R4 - DC Motor Shield
- Arduino Mega - DC Motor Shield
- Arduino Giga R1 WiFi - DC Motor Shield
BSD. See license.txt.
