Home/ Projects/ Two drivers, one motor
Project 11 of 16 Motion Advanced

Two drivers, one motor

Run the same motor through both drivers and learn why there is more than one. The L9110 takes two pins per motor and you PWM one of them. The L293D separates the jobs: direction on the input pins, speed on a dedicated enable pin, which is the arrangement most driver chips use and the one worth knowing. The L293D also accepts a much higher motor supply, so it is the one you reach for when the motor is bigger than this kit's. Both have flyback diodes built in — wire a motor straight to a GPIO pin without one and you damage the board.

ESP32 & ESP8266 IoT Automation Kit
One of 16 projects in the ESP32 & ESP8266 IoT Automation Kit — the parts below are from that kit.

What this project uses

Every item is in the kit — nothing extra to buy.

Everything for this project

ESP32 & ESP8266 IoT Automation Kit

All 24 parts in one box, with this project and 15 more to build from them.

AED 180.00 See the kit
Need only these parts? Order them loose · from AED 115.63
Used in this project tick what you still need
Also needed untick if you already have them
Selected parts AED 115.63

One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. Backorder parts ship once they arrive — the kit above has every part boxed today. Delivery is free on orders AED 150.00+.

Sketch for this project

Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.

11 Two drivers, one motor Arduino C++
/*
  11 — Two drivers, one motor
  Board: ESP32.  Parts: DC motor, L293D module, L9110 module.

  Same motor, two drivers, to see why there is more than one.
    L9110: two pins per motor, PWM on one of them.
    L293D module: direction on IN1/IN2, speed on a separate ENABLE pin. It supports a
           wider motor-supply voltage range and separate enable control, while the L9110
           module is simpler for small low-voltage motors like the one in this kit.
  Both modules include motor-protection circuitry. A motor straight on a GPIO
  can damage the board.

  Wiring (move the motor between the two — only one driver at a time):
    L9110:  VCC -> VIN (5 V), GND -> GND, A-1A -> GPIO 16, A-1B -> GPIO 17, motor -> MOTOR A
    L293D:  VCC/+5 -> VIN, motor supply (VS / +12V terminal) -> VIN for this small motor,
            GND -> GND, IN1 -> GPIO 25, IN2 -> GPIO 33, ENA -> GPIO 32, motor -> OUT1/OUT2
            (some modules have ENA jumpered permanently HIGH — then remove the
             jumper to control speed, or leave it and the ENA line does nothing)
  Set DRIVER below to match where the motor is plugged in.
*/

#define DRIVER_L9110 1
#define DRIVER_L293D 2
#define DRIVER DRIVER_L9110        // <-- change to DRIVER_L293D for the second half

const int L9110_A1A = 16, L9110_A1B = 17;
const int L293D_IN1 = 25, L293D_IN2 = 33, L293D_ENA = 32;

void driveL9110(int speed) {              // speed -255..255
  if (speed >= 0) { analogWrite(L9110_A1A, speed);  digitalWrite(L9110_A1B, LOW); }
  else            { digitalWrite(L9110_A1A, LOW);   analogWrite(L9110_A1B, -speed); }
}

void driveL293D(int speed) {              // direction on IN1/IN2, magnitude on ENA
  digitalWrite(L293D_IN1, speed >= 0 ? HIGH : LOW);
  digitalWrite(L293D_IN2, speed >= 0 ? LOW  : HIGH);
  analogWrite(L293D_ENA, abs(speed));
}

void drive(int speed) {
#if DRIVER == DRIVER_L9110
  driveL9110(speed);
#else
  driveL293D(speed);
#endif
}

void setup() {
  Serial.begin(115200);
  const int pins[] = {L9110_A1A, L9110_A1B, L293D_IN1, L293D_IN2, L293D_ENA};
  for (int p : pins) { pinMode(p, OUTPUT); digitalWrite(p, LOW); }
  Serial.println(DRIVER == DRIVER_L9110 ? "Driver: L9110" : "Driver: L293D");
}

void loop() {
  // Ramp forward, pause, ramp backward, pause — the same pattern on either driver.
  for (int s = 70;  s <= 255; s += 5) { drive(s);  delay(30); }
  delay(800);
  drive(0); delay(500);
  for (int s = -70; s >= -255; s -= 5) { drive(s); delay(30); }
  delay(800);
  drive(0); delay(1500);
}
Change DRIVER to DRIVER_L293D for the second half. Some L293D modules have ENA jumpered HIGH.

More from this kit

All projects →

Root
Online — usually replies instantly
Catalog assistant: verify final stock/price on the product page before checkout.