ESP32 L293 H DC Motor not spinning

Hello,
I have set up a circuit very similar to the starter kit “zoetrope” except with an ESP32. The H bridge pins are connected in the same way, and I have tested the circuit with an Arduino Uno and the zoetrope example and it works. The DC motor does not spin at all when I connect it to ESP32. I tried different output pins and when I connect it to pin 2, which also communicates with the ESP32 LED, the LED turns on and off but the motor doesn’t move. I first tried ledcWrite and then simplified it just to digital low/high output for the H-bridge enable pin and neither version seems to work. What could be going on here?

#include "BluetoothSerial.h"
#include <ESP32_Servo.h>
#include "esp32-hal-ledc.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif


#include "Arduino.h"


BluetoothSerial SerialBT;

int controlPin1 = 4;
int controlPin2 = 19;
int enablePin = 13;

const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int motorSpeed = 200;

String message = "";
char incomingChar;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  SerialBT.begin("Dora the explorer"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");

  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
  ledcSetup(pwmChannel, freq, resolution);
  ledcAttachPin(enablePin, pwmChannel);
  ledcWrite(enablePin, 0);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    char incomingChar = SerialBT.read();
    if (incomingChar != '\n') {
      message += String(incomingChar);
    }
    else {
      message = "";
    }

    Serial.setTimeout(50);
    Serial.write(incomingChar);

    if (message == "Go") {
      digitalWrite(controlPin1, HIGH);
      digitalWrite(controlPin2, LOW);
      //ledcWrite(enablePin, motorSpeed);
      digitalWrite(enablePin, HIGH);
    }
    if (message == "Back") {
      digitalWrite(controlPin1, LOW);
      digitalWrite(controlPin2, HIGH);
      //ledcWrite(enablePin, motorSpeed);
      digitalWrite(enablePin, HIGH);
    }
    if (message == "Stop") {
      //ledcWrite(enablePin, 0);
      digitalWrite(enablePin, LOW);
    }
  }
  delay(20);
}

Be sure the H-Bridge is 3V3 compatible, the ESP is not a 5V device.

gilshultz:
Be sure the H-Bridge is 3V3 compatible, the ESP is not a 5V device.

Thank you! I think Vin supplies 5V to the circuit if the ESP32 is connected via USB? But if not, I think you might be right, since my H-bridge seems to have a voltage supply of 4.5-5.5 V.

It is not about the supply-voltage. It is about the signal-voltage. The IO-Pins of an ESP32 have only 3.3V.
How do you supply the H-bridge with power?
depending on the motor-size trying to power the motor from the Vin-pin of an ESP-board is way too less.
a standard USB-connector can only deliver 500mA. 70-200 mA are consumed by the ESP32. itself so there is not much keft for a motor.

For bigger things than LEDs you should always use a extra-power-supply. The GND of the second-power-supply must be connected to the GND of the microcontroller-board to make it work.

Did you measure the voltage of the IO-Pins of the ESP32? D they have 3.3V / 0V as set by your program?

best regards Stefan