1

I have a problem involving my ESP32, a L298n module, two whining motors and a 9V battery.

I've connected the battery positive 12 VDC to VCC, and the negative to GND.

Two 9V motors are connected to OUT1, OUT2 - OUT3 - OUT4.

My ESP32 is running off its microUSB port.

IN1 -> GPIO 18
IN2 -> GPIO 19
ENA -> GPIO 21 (PWM)
IN3 -> GPIO 22
IN4 -> GPIO 23
ENB -> GPIO 25 (PWM)
GND -> GND (ESP32)

The code serial output is in Spanish.

// Definir los pines
#define IN1 18
#define IN2 19
#define ENA 21
#define IN3 22
#define IN4 23
#define ENB 25

void setup() { // Inicializar la comunicación serial Serial.begin(115200);

// Configurar los pines como salidas pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENA, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENB, OUTPUT);

// Inicializar los motores apagados digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); analogWrite(ENA, 0); analogWrite(ENB, 0);

Serial.println("Setup completo, listo para comenzar."); }

void loop() { // Acelerar gradualmente el primer motor for (int speed = 0; speed <= 255; speed += 5) { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); analogWrite(ENA, speed); Serial.print("Velocidad del motor 1: "); Serial.println(speed); delay(100); }

// Acelerar gradualmente el segundo motor for (int speed = 0; speed <= 255; speed += 5) { digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); analogWrite(ENB, speed); Serial.print("Velocidad del motor 2: "); Serial.println(speed); delay(100); }

// Detener los motores Serial.println("Deteniendo motores..."); analogWrite(ENA, 0); analogWrite(ENB, 0); delay(2000); }

Gil Sven
  • 167
  • 8

1 Answers1

0

The L298 documentation shows that it drops (if my memory serves me correctly) at least 2V, up to almost 5V at higher currents. That means your motors are going to be receiving about 7V at best, down to about 4-5V at worst, assuming the battery is fresh and produces 9V in the first place.

Even if you use a better source than a PP3 type battery (see 6v6gt's comment) with a 298 you will still be short of voltage at the motor if you start with 9V regardless of how good the source is.

The 298 is decades-old technology and you should consider using a more modern device that doesn't suffer from such voltage drops. (The voltage drop manifests as heat btw, which is why those modules have heat sinks the size of a garage door.) Have a look at Pololu's site for a good range of far better drivers.

user95861
  • 21
  • 1