strange behavior on my first robot with L298

Hello,
I bought this kit to make my first robot:
https://www.banggood.com/4WD-Smart-Robot-Car-Kit-UNO-Bluetooth-IR-Obstacle-Avoid-Line-Follow-L298N-For- Arduino-p-1178195.html? rmmds = search & cur_warehouse CN =
But, I had a pb.
In fact, I made the wiring according to the figure below
At first use it works correctly (motors run properly), but the next day when I tried to continue the work, the motors no longer work.
The first time, I changed the config of PIN on arduino, and it works again, but the day after when I tried to continue the work, the motors no longer work.
actually I changed the ports of L298 on all the arduino Pin. When I turn on the power and I run my program, I hear very little noise from motors spinning. Then nothing

The pg consists in doing a simple moveForward (int speed)
the motors are DC 3V-6V
i don't know if this help :frowning:

PwerWiring.png

Is your 9V battery one of those rectangular smoke alarm batteries? If so, that is a problem. Those batteries can not supply very much current. You need a power source that can supply the stall current of the motors.

Hi,
yes, i used a 6 batteries 1.5V together with this rectangular box.
what's your suggestions ? change power to one battery 9V ?

Brs,

change power to one battery 9V ?

No.

yes, i used a 6 batteries 1.5V together with this rectangular box.

Your battery may be OK. When I said "rectangular smoke alarm batteries" I meant one of the small batteries with the snaps on top. A pack of 6 1.5 batteries could be enough. I can't say for sure until I know what exact batteries that you are using and the current demands of what the batteries are powering.

Do you have a multi-meter? Monitor the battery voltage while your circuit is running. Is the voltage 9V or near? Does the battery voltage remain relatively steady or drop slowly?

Hi Again,
when i'm preparing to send you the voltage measurment, it workw now without any change.

so you can find attached a picture i tried to explain all on it..

i have another problem now :slight_smile: this is my code :

int enA = 3;
int in1 = 4;
int in2 = 5;

// Motor Droite
int enB = 6;
int in3 = 7;
int in4 = 8;


void setup() {
  Serial.begin(9600);
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void loop()
{
 for (int i =60;i< 250;i++)
{
  MoveForward(i);
  Serial.println(i);
  delay(1000);
  }
}

void MoveForwardMotorRight(int speed)
{
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enB, speed);
}

void MoveBackwardMotorRight(int speed)
{
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  analogWrite(enB, speed);
}

void StopMotorRight()
{
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

void StopMotorLeft()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
}


void MoveForwardMotorLeft(int speed)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(enA, speed);
}

void MoveBackwardMotorLeft(int speed)
{
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(enA, speed);
}


void MoveForward(int speed)
{
  MoveForwardMotorLeft(speed);
  MoveForwardMotorRight(speed);
}

void MoveBackward(int speed)
{
  MoveBackwardMotorLeft(speed);
  MoveBackwardMotorRight(speed);
}

void Stop()
{
  StopMotorLeft();
  StopMotorRight();
}

void TurnLeft(int speed)
{
  MoveForwardMotorRight(speed);
  MoveBackwardMotorLeft(speed);
}


void TurnRight(int speed)
{
  MoveForwardMotorLeft(speed);
  MoveBackwardMotorRight(speed);
}

the problem is that aal motors didnt' start on the same time and speed

MA1 start when speed = 61
MA2 start when speed = 68
MB1 start when speed = 73
MB2 start when speed = 82

so when i put a common value for speed (MoveForward (speed)) those motors didn't spin at the same speed

did you see any similar problem ?

void loop()
{
for (int i =60;i< 250;i++)
{
MoveForward(i);
Serial.println(i);
delay(1000);
}
}

Different motors have different minimum speeds they will start at, I would make the minimum speed a little higher than the highest individual:

void loop()
{
 for (int i =90;i< 250;i++)
{
  MoveForward(i);
  Serial.println(i);
  delay(1000);
  }
}

Hi, and what about the speed?
If we put for example a common speed for all motors : MA1 will spin with 50 tour per minute
MA2 will spin with 42 tour per minute
MB1 will spin with37 tour per minute
And this mean that the robot will not follow a straight line.

You're building a line-follower, right? So it will drive the motors as required to keep the line-sensor positioned above the line. It doesn't matter that it cannot drive straight on its own.

(I love the "Ardulno Sensor Shield" in the photos. Somehow these guys can sleep better at night if they use Photoshop to change a few pixels in an image and dream that they didn't copy it. I bet their copy of Photoshop is pirated too.)

I realize you have the battery problem solved, at least it sounds like it. just figured I would throw this in for future battery trouble shooting: if you think there might be a battery issue, hook it up to a power supply from the wall with converter (be sure to check its the motors voltage so you don't break something). If everything works then it's either the wrong battery or a low/dead battery.

One problem is two of your motors are wired in parallel to 1 controller output, so there is no way to individually vary their speeds, if you apply the same voltage to both motors, one might run 1000 RPM and the other 990, you would need 2 PERFECTLY matched motors with the SAME load to run the same speed for the same voltage, I doubt you have that with a low cost toy robot.

Hi,
I think you have these motors.
download-400x400.png

They are cheap and each is a little different, the starting current is one of them, speed is the other.

Tom.. :slight_smile:

outsider:
One problem is two of your motors are wired in parallel to 1 controller output, so there is no way to individually vary their speeds, if you apply the same voltage to both motors, one might run 1000 RPM and the other 990, you would need 2 PERFECTLY matched motors with the SAME load to run the same speed for the same voltage, I doubt you have that with a low cost toy robot.

If both of those wheels are in contact with the ground, it will all sort itself out. It looks like a competent kit with appropriate motors for the task.

Hi,
Thank you all for your response.
i will start with MorganS

You're building a line-follower, right

No, i'm building an obstacle avoiding robot, but it will follow a maze (constructed by myself)
my Robot need to follow a straight line, otherwise the limit of this maze will be touched.

ScoobyDoo :

I realize you have the battery problem solved, at least it sounds like it

No, it's not battery problem, i'm pretty sure. and till now i didn't understand what was it.
as i explained before, all motors works today, and tomorrow only motors A works, after tomorrow none of my motors works, and the day after all my motors works well.

outsider :

you would need 2 PERFECTLY matched motors with the SAME load to run the same speed for the same voltage

You are right, thank you.

TomGeorge:

I think you have these motors.

Exactly, it looks like this one :slight_smile:

MorganS :

If both of those wheels are in contact with the ground, it will all sort itself out. It looks like a competent kit with appropriate motors for the task.

so you suggest that i need to try to put the wheels ? Ok, i will come back to you

Thanks for you all, but to "resolve" the problem i changed a little bit the speed between Motors A and B. this is my new code :

void MoveForwardMotorRight(int speed)
{
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  analogWrite(enB, speed);
}

void MoveForwardMotorLeft(int speed)
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  analogWrite(enA, speed - 8);
}

void MoveForward(int speed)
{
  MoveForwardMotorLeft(speed);
  MoveForwardMotorRight(speed);
}

Now, when i put the speed at 255 :

motors A1 : 62
motors A2 : 61
motors B1 : 60
motors B2 : 61

i will try to put the wheels now, and come back.

Dears,
i found out what was the power problem :frowning:
in fact, when i added the servoMotor to my circuit, the same problem is appeared.
sometimes the left motors don't work anymore, and sometimes the speeds of the left engines are too slow.

i connected the ServoMotor to arduino board (5V and GND and Pin 8)

Is there anyone who has seen this problem before?

i connected the ServoMotor to arduino board (5V and GND and Pin 8)

Just about every servo tutorial shows a servo powered by the Arduino 5V output. That will usually work for one unloaded micro servo. Just about every time someone has a problem with a servo it is because they are powering a loaded servo from the Arduino 5V output. Power the servo with a source that is capable of supplying the current required by the servo under load, around 1A per regular hobby servo. (the Arduino 5V is not capable of enough current).