Motors not moving

I have code written to run 2 dc motors using L298 motor driver and then run servo motors which are all controlled by an IR sensor detection. The servo motors are moving, but the dc motors are not moving. I have given the connections accordingly to the code. Please help me as this is very urgent.

#include <Servo.h>

int led = 13;
int enA = 12;
int in1 = 11;
int in2 = 10;
int enB = 9;
int in3 = 8;
int in4 = 7;
int irs = 6;

Servo servo1; 
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;

void setup() {


  Serial.begin(9600) ;
  servo1.attach(5);
  servo2.attach(4); 
  servo3.attach(3); 
  servo4.attach(2);
  servo5.attach(1);

  pinMode(led, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(irs, INPUT);
  
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  arminit();
  delay(2000);
}

void loop() {
 int sensorStatus = digitalRead(irs);
  if (sensorStatus == 1)
  {
    digitalWrite(led, HIGH);
    Serial.println("Conveyor Stoppedd!"); 
    delay(2000);
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, LOW);
    arm();
    delay(3000);
    motorControl();
  }
  else  {
    digitalWrite(led, LOW); 
    motorControl() ;
    Serial.println("Conveyor Starred!");
    arminit();
  }
}

void motorControl() {
  analogWrite(enA, 10);
  analogWrite(enB, 10);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}

void arm(){
  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  delay(2000);
  servo1.write(0);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  delay(2000);
  servo1.write(0);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  delay(2000);
  servo1.write(0);
  servo2.write(45);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  delay(2000);
  servo1.write(0);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  delay(2000);
  servo1.write(0);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
}

void arminit(){
  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
} 

From the Servo library reference:

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

The motors will need some minimum of PWM to get moving. 10 is probably way too low. Some of my motors take over 60 just to get moving with no load, more when loaded.

The L298 is a poor choice for a motor driver. It is ancient and inefficient technology. It will drop 2V to over 4V of the motor power and dissipate that power as waste heat. Pololu has a good line of modern moor drivers at reasonable prices. They stand behind their products and have instructional pages for each product.

What Arduino are you using that doesn't use Pin 1 for Serial?

What Arduino are you using that has Pin 12 as an analogWrite() (PWM) Pin?

I rather doubt that. :rofl:

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