l298N is not working properly with 4 motors

hey, i am new in robotics. I am trying to run l298N motor driver using 4 12V motors. I am using 6 9V batteries to power the motor driver and 2 9V batteries to power the arduino mega using VIN pin. I have removed the jumper and connected the +5V to arduino's 5V and to the common gnd.
The motors are working but not properly at the same time. when i start it, two connected motors are running on time but the other 2 are running slowly or not on time. I will be obliged if someone can help me and comment on my errors.

You might not have enough power for your motors.

In order to get the best help from the forum you should post a diagram of your setup and components used otherwise it would be impossible for anyone to provide proper advise.

int in1= 22;
int in2= 24;
int in3= 26;
int in4= 28;
int ena= 7;
int enb= 6;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
 pinMode(ena, OUTPUT);
 pinMode(enb, OUTPUT);
 pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
 
 forward();
 delay(3000);
 stop();
 delay(2000);
 backward();
 delay(3000);
 stop();
 delay(2000);
 turnLeft();
 delay(2800);
 stop();
 delay(2000);
 turnRight();
 delay(4800);
 stop();
 delay(2000);
}

void loop() {
  // put your main code here, to run repeatedly:
 
}
void forward()
{
 digitalWrite(in1, HIGH);
 digitalWrite(in2, LOW);
 analogWrite(ena, 250);

 digitalWrite(in3, HIGH);
 digitalWrite(in4, LOW);
 analogWrite(enb, 250);
}
void backward()
{
 digitalWrite(in1, LOW);
 digitalWrite(in2, HIGH);
 analogWrite(ena, 200);
 digitalWrite(in3, LOW);
 digitalWrite(in4, HIGH);
 analogWrite(enb, 200);
}
void stop()
{
 digitalWrite(in1, LOW);
 digitalWrite(in2, LOW);
 digitalWrite(in3, LOW);
 digitalWrite(in4, LOW);
} 
void turnLeft()
{
 digitalWrite(in3, HIGH);
 digitalWrite(in4, LOW);
 analogWrite(enb, 155);

 /**digitalWrite(in1, LOW);
 digitalWrite(in2, HIGH);
 analogWrite(ena, 255);**/

}
void turnRight()
{
 digitalWrite(in1, HIGH);
 digitalWrite(in2, LOW);
 analogWrite(ena, 155);

 /**digitalWrite(in3, LOW);
 digitalWrite(in4, HIGH);
 analogWrite(enb, 155);**/
}

Schematics please. And measure the voltage on the motors when they are "on".

Hi, @annesha123
Welcome to the forum.
Thanks for using code tags. :+1:

Do you have a DMM, Digital MultiMeter?

Thanks... Tom.... :smiley: :coffee: :+1: :australia:

6 x 9V = 54V
2 x 9V = 18V
Those voltages are WAY to high.

Series or parallel?

Parallel I hope.

Tom.. :smiley: :+1: :coffee: :australia:

sorry i dont understand.... i just stacked the batteries and connected it's positive wires together and negative wies together.

1 Like

Hi, @annesha123
Thanks for the schematic.

So you are driving 2 motors in parallel on each or the two outputs.

What are the motors?
Can you please post link to data/specs and or a picture?

Parallel.

Tom.. :smiley: :+1: :coffee: :australia:

Hi, @annesha123
Just to help others I have put your schematic into a CAD program.

Tom... :smiley: :+1: :coffee: :australia:
PS. Thanks for a good clear diagram. :+1:

yeah.... its absolutely correct!

so now what do i do?

NEVER, NEVER connect 9V batteries in PARALLEL.!
One or more of the batteries could overheat and leak and/or rupture.

Proceed with trouble shooting:
1. You cannot expect desired performance from 12V Motors by running them using 9V.

2. Collect a 12V/3A DC Power Supply. (Better to have an adjustable one: 0V - 25V).

3. Check the functioning of the Motors by connecting them one-by-one directly with the 12V supply.

4. Check that the L298 Motor Driver Board has all three on-board jumpers installed.
L298DriverPic
Figure-1:

5. Connect one Motor across OUT1/OUT2 of Motor Driver of Fig-1. Clamp the Motor so that it does not move while rotating.

6. Put a jumper across 5V/IN1 of Fig-1. Why -- check Fig-3.
7. Connect 12V across 12V/GND of Fig-1.
8. Check that the Motor is turning well.
9. Disconnect 12V supply.
10. Place a jumper across 5V and IN4 of FIg-1. Why -- check Fig-1.
11. Connect 2nd Motor across OUT3/OUT4.
12. Connect 12V supply with Motor Driver.
13. Check that both Motors are running at the same speed. If 2nd Motor runs in the opposite direction, then swap the OUT3/OUT4 connections.

14. Similarly, you can check the functionalities of the remaining two Motors.

15. Before you are going to operate the Motors from the IO pins of the MEGA, learn the working principles of the L298 Motor Driver from the following (Fig-2, 3) schematic diagram.
L298Schematic-1

Figure-2:

L298Schematic-2
Figure-3:

12V motors will often run fairly ok at 9V, but here it won't be 9V they are getting, but quite a bit less due to the voltage drops inherent in both sides of the L298 driver. This drop is worse the more current the motors draw. This drop is why the L298 needs such a big heatsink, to dump all that wasted energy when running at high currents. The ideal solution would be moving to a more modern type of driver IC, one with minimal voltage drops such as the TB6612. If the TB6612 can't handle the currents you need (a bit over 1A per channel, it has two separate channels), then look at dirvers based on pairs of half bridge chips such as the BTS7960 (or more recent equivalents).

1 Like

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