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); }