Arduino Uno 2WD Car with L298n not working

Hi All,

I've been working a 2WD car with an Uno, L298n and 2 dc motors. Every time I try to upload the code to the board I get this.

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean,
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\NATHAN~1\AppData\Local\Temp\arduino_build_436159/sketch_may12b.ino.hex"
avrdude: writing flash (834 bytes):

Writing | ################################################## | 100% 0.16s

avrdude: 834 bytes of flash written
avrdude: verifying flash memory against C:\Users\NATHAN~1\AppData\Local\Temp\arduino_build_436159/sketch_may12b.ino.hex:
avrdude: load data flash data from input file C:\Users\NATHAN~1\AppData\Local\Temp\arduino_build_436159/sketch_may12b.ino.hex:
avrdude: input file C:\Users\NATHAN~1\AppData\Local\Temp\arduino_build_436159/sketch_may12b.ino.hex contains 834 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.13s

avrdude: verifying ...
avrdude: 834 bytes of flash verified

avrdude done.  Thank you.

This code is

// motor Right setup
static int ENA = 5;
static int IN1 = 8;
static int IN2 = 9;
//motor Left setup
static int IN3 = 10;
static int IN4 = 11;
static int ENB = 6;

void setup() {
// seting all motor pins to OUTPUT
 pinMode(ENA, OUTPUT);
 pinMode(ENB, OUTPUT);
 pinMode(IN1, OUTPUT);
 pinMode(IN2, OUTPUT);
 pinMode(IN3, OUTPUT);
 pinMode(IN4, OUTPUT);

void loop() {
//power both Motor
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, HIGH);

//set PWM of both motors to full speed
  analogWrite(ENA, 255);
  analogWrite(ENA, 255);  


I have checked all the pins and it should work. I am powering the Uno and the L298n with separate 9V batteries so there should be enough voltage to power the motor but it just doesn't work.

Any suggestions?



9V batteries so there should be enough voltage

Are you trying to power motors with a rectangular 9V battery like for smoke alarms? Those may have the voltage, but cannot supply very much current.

What is the rated voltage of the motors? What is the stall current of the motors?

//power both Motor
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, HIGH);

You should check the truth table for the L298. Both motors are stopped with that code. Look toward the bottom of this page.

Yes, the rectangular 9V ones. To be honest I don't know anything about the motors. I was given this project for school and it had been half assembled.

So the code should be this for forward?

//power both Motor
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);

Is the message about the memory in the original post normal? As that is what I have been lead to believe is the problem.

So the code should be this for forward?

The motors should rotate, direction depending on power wiring. And given proper voltage and current. Post a photo of the motors. Maybe some one will recognize them and know the voltage and current that they need. How to post images.

Is the message about the memory in the original post normal?

I can't answer that as I use the Arduino IDE and am not familiar with AVR Dude.

Is the message about the memory in the original post normal? As that is what I have been lead to believe is the problem.

Which message?

If you measure the resistance of the motors, the maximum drawn current can be calculated.

DrDiettrich, The message at the top of the first post, how would I go about testing the resistance and such?

groundFungus, this was on Arduino IDE, see pictures below.

I’ve also attached pictures of the motors.

Check your IDE Preferences for "verbose output".

Resistance can be measured e.g. with a multimeter (DVM) - do you have one?

Can you post a picture of your project please so we can see your component layout?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

If you lift your car up so it spins its wheel, will be able to see if you have any control,.

Thanks.. Tom.. :slight_smile:

Attached is a circuit diagram. It is kind of rough but should be able to be read, (hopefully). Just replace the L293D with a L298N.

The wheels don’t spin at all for some reason.

I should have access to a multimeter at some point during the next few days so I will be able to check if there is an actual output from the Motor Drive board, and how much resistance is on the motors.

I’ve put some more photos of the motors in this post.

Thanks for all the help so far!

Can that battery even power those motors in the first place? Try connecting your battery directly to one, see what happens.

Check your battery - if they can power the motors at all it will be for a really short time. A few minutes or so. So you may have drained them already. Mind that you lose an additional 2-3V on the L298N, so your motors get 6-7V at most (check the data sheet for exact numbers).

Same for the Arduino. Upload will go fine as then it's powered by the USB port. That battery should last a few hours but it may very well be empty, too.

Use a proper power supply for your testing (9-12V wall wart). Then you can connect the Arduino to the same power supply as the rest.

Make sure the grounds are shared.

Oh, and learn to draw circuit diagrams. For that, start by ditching Fritzing and installing proper circuit software such as KiCAD or EagleCAD (or just do it by hand on paper, your circuit is simple enough).

I have connected the 9V to the motors directly and they worked. I've bought brand new batteries just in case that the old was the problem, but still no luck running through the whole circuit.

My guess would be that the motors are 5V because, 4 AA batteries directly to the motors got them to run. So 6-7V straight from the L298N should do the trick. Could the L298N board be fritzed? That would make the most sense. As it is the only thing I haven't been able to test yet.

I will give the two CAD programs a go, thanks for the tip.

UPDATE: Eagle CAD wasn't available for trial in Australia, or at least I couldn't find the trial version, but I will give KiCAD a go.

Do you have the grounds connected? It's not drawn in that Fritzing. Without that, it won't work ever.

If so: measure the voltage on the output pins of the Arduino - is it what you expect? If not: software issue, or Arduino broken.

If OK: measure the voltage on the input pins of the L298N - again, is it what you expect? If not: faulty connection.

If OK: measure the voltage on the output pins of the L298N (without motors). Is it what you expect? If not: chip broken.

If OK: measure the voltage at the motor pins. Is it what you expect? If not: faulty connection.

Fritzing also has a circuit diagram mode, and more. Simply select the tab and start composing.

Everything is getting power as the Arduino and the L298N light up.

I put some LEDs in the output pins of the Arduino the other day and they lit up. When I get access to the voltmeter I will test the input pins and such of the Driver Board, and will let you guys know.

You can use LEDs (with appropriate current limiting resistors) to test the outputs of the L298N.

You have to realise that using the 298 you will loose 2V drop across the IC, it is an ancient technology.
There are better MOSFET type controllers that are more efficient.

Tom.. :slight_smile: