Example Code for Arduino-Dual Motor Control
Last revision 2026/01/08
The tutorial presents how to control motor driver board by Arduino UNO and drive two motors simultaneously.
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- Dual-Channel DC Motor Driver-12A x1
- Wires
Software Preparation
Wiring Diagram

| Connection | ||||||
|---|---|---|---|---|---|---|
| Motor Driver Board | 2 | 3 | 4 | 7 | 8 | 9 |
| UNO Board | 2 | 3 | 4 | 5 | 6 | 7 |
Sample Code
/*
This sample code is for testing the 2 stepper motors
The rotation velocity can be adjusted by the code switch
Microcontroller: Arduino UNO
*/
int PWM1 = 2;
int INA1 = 3;
int INB1 = 4;
int PWM2 = 5;
int INA2 = 6;
int INB2 = 7;
void setup()
{
pinMode(PWM1, OUTPUT);
pinMode(INA1, OUTPUT);
pinMode(INB1, OUTPUT);
pinMode(PWM2, OUTPUT);
pinMode(INA2, OUTPUT);
pinMode(INB2, OUTPUT);
}
void loop()
{
digitalWrite(INA1, LOW);
digitalWrite(INA2, LOW);
digitalWrite(INB1, HIGH);
digitalWrite(INB2, HIGH);
analogWrite(PWM1, 255); //PWM adjust speed
analogWrite(PWM2, 255); //PWM adjust speed
delay(1000);
digitalWrite(INA1, LOW);
digitalWrite(INB1, HIGH); //Motor 1 rotate forward
digitalWrite(INA2, HIGH);
digitalWrite(INB2, LOW); //Motor 2 rotate backward
analogWrite(PWM1, 255); //PWM adjust speed
analogWrite(PWM2, 255); //PWM adjust speed
delay(1000);
digitalWrite(INA1, LOW);
digitalWrite(INB1, LOW); //Motor 1 stop
digitalWrite(INA2, LOW);
digitalWrite(INB2, LOW); //Motor 2 stop
analogWrite(PWM1, 255);
analogWrite(PWM2, 255);
delay(1000);
}
Result
Result: two motors rotate forward simultaneously; one rotate forward, the other rotate backward; stop rotating.
Was this article helpful?
