Arduino L298N problem 4WD Motor

Hi everyone, i'm developer so i know about programming but nothing about electronic and that world :sweat_smile: .However, I've been in touch with arduino since i was a child because i love the idea of creating things. I usually follow tutorials (and chatgpt haha) because everything i want to create has already been made :joy: . A few days ago, I started trying to build a car with 4 wheels and DC motor (the classic arduino kit) with a bluetooth controller and wifi, camera, and some sensors (to watch my dog while i'm not at home). I've already worked with some of the sensors, and everything works well.
I just started assembling the car with its 4 wheels, DC motors and l298n. But I'm having trouble getting it all to work. I'm attaching some pictures/schemas and my code. Sometimes only 2 wheels from one motor works well and the other 2 don't, sometime works only 1 or 2 wheels, or only 2 work fast from one motor and 1 slow from the other motor, etc.. so they are not working correctly, it's weird. I've tried everything I know so far. My code is very simple right now, just moving forward and backward with a delay to make sure everything works before adding all the sensors and writing the rest of the code to control the car with a Bluetooth app or WiFi.
Components:

  • 4 wheels with their 3v-6v dc motors.
  • l298n (i think it's a different version than I've seen on Google)
  • arduino uno r3 (i also have an arduino mega and lots of arduino uno r3, i've tested with all of them)
  • battery x2 18650 (each 18650 has 3.7v and 6800mah)
    Connection:
  • Each dc motor has 2 wires (red and black), I connected the 2 left motors to the MotorB pin and the 2 right motors to the MotorA pin. (Each wire from each motor goes to a different pin, e.g. the red one from one left motor goes with the black one from the second left motor, i think this connection is only important for direction, so it's fine for testing because my goal is to see all 4 wheels moving at the same time and as fast as they can, then i will see how to connect everything to move in the same direction-forward/reverse/left/right).
  • Battery x2 18650 red wire to VMS ping in l298n and the black wire (gnd) to GND pin in l298n. (I bought 6 batteries so I tried with all of them -in pairs of 2- to discard a battery problem)
  • IN1, IN2 to pin 13,12 in arduino.
  • IN3,IN4 to pin 11,10 in arduino.
  • GND pin in l298n to GND pin in arduino.
  • The Arduino power supply is either the USB from my computer or a 5V 1A DC jack (I've also tried using the 5V from the L298N to power the Arduino, but the result is the same).

My code is:

int IN1 = 13;
int IN2 = 12;

int IN3 = 11;
int IN4 = 10;

void setup() {
  // MotorA
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  // MotorB
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

}
void loop() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  delay(5000);

  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  delay(5000);

}

I've already tested with ENA and ENB (with analogWrite and 255 value) but for this example, I left that out to avoid adding complexity.
I'll really appreaciate your help!

*Sorry for the colors of the wires, i dont have many male-female wires so i have to reuse them
** The wires don't interrupt the movement of the wheel, i put them just for the picture.
*** I can't upload more than 3 images because i'm new.



Just an FYI, the 18650 battery cannot have 6800mAh, it's more likely 1800. It's all about size and chemistry.
Also learn how to use the forum at https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/681307?u=sonofcy

1 Like

Maybe @2024matiasdev meant that the batteries have a total of 6800mAh between them because they are 3400mAh each, which is still very high, but maybe possible.

@2024matiasdev Unfortunately, when you connect 2 batteries in series to get ~7.4V, the capacities do not combine. The pair have a combined capacity of 3400mAh.

If you connected the batteries in parallel, then the capacities would combine to give 6800mAh, but the voltage would be only 3.7V. that would not be enough to power your motors because your old and inefficient motor driver will waste almost 2V leaving only around 1.7V for the motors.

True, but even 3400 is a stretch.

Do NOT connect those batteries in parallel, that is how lithium fires start unless they are LiFePO4.

I just zoomed in on the photo and you are right, it says 6800mAh on each one.

@2024matiasdev return those batteries and demand a refund. You have been swindled.

I have seen plenty advertised at 10000 or more.

Even on Amazon, but they are fake. It's a chemical reaction, and the volume of the cylinder determines the capacity. I think there may be two chemistries, one about 2000 mAh and the other 3000 mAh but certainly nothing more.

And I was the idiot who bought the 10000mAh ones only to discover what their true capacity was only around 5% of that claim.

Later I purchased some genuine LG 2400mAh batteries. Each LG battery weighted as much as 2 of the fake batteries.

He probably got them from Aliexpress, no returns possible. Just dispose of them safely. The Swiss guy published a link of real 18650 LiFe batteries on Aliexpress. I got a few and did a capacity test with a SkyRC MC3000. They are a legitimate 3500 mAh.

Good point. If the batteries have individual protection, then it should be safe. But most 18650 batteries do not have protection built in. The ones that have protection usually have a metal strip running the length of the battery, and are 1~2mm longer because there is a small protection PCB at the base.

@2024matiasdev your batteries have no protection and you risk them exploding or catching fire even though your batteries are connected in series. Charging them in a charger with protection will not prevent this because they become damaged due to being over-discharged.

Thanks everyone! Each battery says "3.7V 6800mAh".
I didn't know much about batteries, i had read a tutorial and i tried with 4xAA batteries, but they weren't enough to power the 4 wheels, so i've switched them for 2x18650 that i bought on Amazon, of course i chose the ones with the most mAh :joy: i didn't know they were fakes (i bought 6: 2 for l298n, 2 for arduino+sensors, 2 for raspberry+camera). Thanks for letting me know about the risks, i'm going to put them inside a battery bag that I bought on amazon, where I store my RC helicopter lipo batteries).
So, what is the best option to power an arduino uno + l298n + 4 wheels + some sensors such as esp32camera, hc06, etc? Hopefully, all the problems will be solved.

If you can find 18650 LiFePO4 they are MUCH safer. I literally slept on 6 100AH batteries in parallel in my RV. They will be less power, I don't recall how much.
The safest is the new Sodium. I got 50 when they were first announced. They are nominal 3V 1500 mAh. I have done a capacity test on them and I think they might be fairly accurate. The problem is there are no dedicated chargers yet. I have a SkyRC MC3000 which is programmable but even then it was very tricky.

If from Amazon, weigh them, that is the safe way to determine capacity.

its impossible to get a refund because im from Argentina (there is no way to make a claim), so i'd rather buy another battery (as long as they’re not too hard to buy here in my country). Is a lipo battery 7.4v 1500mah a good option?
image

The ancient L298 is extremely inefficient, wastes a lot of energy as heat, and should be powered from 8-12V.

Try a 6xAA battery pack instead. 8xAA will be even better.

Capture

LiPO and LiFe are both dangerous, but just use common sense. I can't comment on a specific battery, but I can tell you how to calculate what you need. Make a spreadsheet of all the electricity consuming parts, enter the V in 1 col, then the amps in the next. Make the next col the power by multiplying. Pay attention to units, all ma or all A. Now add up the powers and divide into the battery mAh rating. That is the number of minutes the battery will last.

I was going to suggest something like that. These LiPo packs usually have built-in self protection against over discharge and short circuit. But will 1500mAh be enough for a motorised robot with WiFi and camera to run for 8 hours or more? I doubt it. You need to do the maths on that.

As already pointed out, that L298 is going to waste a lot of the energy in the battery. TB6612FNG or MX1508 might be suitable replacements, but it depends on your motors.

OH YEAH, that battery is good for a few 10's of minutes, 8 hrs will be several of those.
@2024matiasdev
The TB6612FNG will save a lot of power and run cool.
Do the spread sheet like I said earlier to determine battery requirements.

Hi, @2024matiasdev
Welcome to the forum.

Do you have a DMM? (Digital MultiMeter)

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