GEAR Motor does not work

Hey every one, I'm new at programming and have truble acctivating a gear motor with module speed. I'm also working with servo at the same time, the servo works well but I can't make the gear motor work with a L293D. What I want is to ask for speed and then make it to the gear motor.

#include <Servo.h>

// Motor con L293D
int MDC1 = 3;
int in1 = 4;  // Asegúrate de conectar este pin adecuadamente al L293D
Servo SM;

void setup() {
  pinMode(MDC1, OUTPUT); // Control del motor
  pinMode(in1, OUTPUT);  // Control del motor
  digitalWrite(in1, LOW);
  Serial.begin(9600);
  SM.attach(9);
  Serial.println("Dirección del viento: N, NO, O, SO, S");
  Serial.println("Velocidad de viento: valor del 0 a 25 m/s");
}

void loop() {
  analogWrite(MDC1, 0);
  
  // Espera hasta recibir la dirección del viento
  while (Serial.available() <= 0) {
    delay(100);  // Pequeña pausa para no saturar el procesador
  }
  String direccion = Serial.readStringUntil('\n');
  direccion.trim();

  // Definir la posición del servo conforme a las letras posibles
  if (direccion == "N") {
    SM.write(180);
  } else if (direccion == "NO") {
    SM.write(135);
  } else if (direccion == "O") {
    SM.write(90);
  } else if (direccion == "SO") {
    SM.write(45);
  } else if (direccion == "S") {
    SM.write(0);
  }
  Serial.println(direccion);

  delay(4000);  // Retraso opcional para dar tiempo a cambiar la dirección del viento

  // Espera hasta recibir la velocidad del viento
  while (Serial.available() <= 0) {
    delay(100);  // Pequeña pausa para no saturar el procesador
  }
  String strVelocidad = Serial.readStringUntil('\n');
  strVelocidad.trim();
  int velocidad = strVelocidad.toInt();

  int pwmVal = map(velocidad, 0, 25, 0, 255); // Conversión a valor PWM

  // Controla el motor basado en la velocidad
  if (velocidad > 20) {
    analogWrite(MDC1, 0);
    digitalWrite(in1, LOW);
  } else if (velocidad > 3) {
    analogWrite(MDC1, pwmVal);
    digitalWrite(in1, HIGH);
  } else {
    analogWrite(MDC1, 0);
    digitalWrite(in1, LOW);
  }

  Serial.println(velocidad);
  delay(1000);  // Retraso antes de la siguiente lectura
}

You can not run motors or servos from the Arduino's 5V pin. The Arduino is a controller NOT a power supply.
What is the motor's voltage and current or wattage ratings?

WHICH gear motor? (hint - provide a link)

The enable pins need to be HIGH to enable the driver outputs. Either through a pin controlled by software or tied to Vcc.

That's why I added a power suply, the DC motor woeked well with 12v

How is the servo powered?

The servo is powered by the 5v pin and the DC motor by the power source

Not a good idea. Use a separate power supply for the servo, and don't forget to connect the grounds.

Let me rephrase:

You can not run motors or servos from the Arduino's 5V pin.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.