Problem with Arduino Uno, L298N and DC Motors

Hi there,

I hope i'm posting this question in the right section. I wasn't sure if this belonged in the MOTORS section or the INTERFACING section, but i'm going to go ahead here.

I'm building an autonomous rover (i know, how creative!). My electronics knowledge is quite poor, so i'm almost certain the problem is with my wiring. I'm just hoping i haven't blown something up.

I'm using this motor driver/controller circuit:



http://www.ebay.com/itm/200659789109?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

To power these motors:


http://www.ebay.com/itm/4WD-Robot-Smart-Car-Chassis-Kits-car-with-Speed-Encoder-DC-3v-5V-6V-for-Arduino-/171122633517?pt=LH_DefaultDomain_0&hash=item27d7b42b2d

I've got 471pF ceramic caps across the leads of each DC motor. I was advised to do this to reduce the jerky-motion of the motors. (How accurate was this advice?)

and an Arduino UNO R3.

I realised that the motor controller that i had purchased only supported upto 2 DC motors, so i connected the two LEFT motors in parallel and the same on the RIGHT. I ran the two leads of each motor setup into the MOTORA and MOTORB inputs of the motor controller.

I decided to power the motor controller circuit (VMS) with a 9V battery and the GND to the -ve obviously. The 5V in was left empty. The ENA and ENB are connected to the PWMs of the Arduino Uno and the IN1,IN2,IN3,IN4 are connected to DIGITAL pins of the Arduino.

On the Arduino-end, i've got a 9V battery with a 2.1mm plug to supply power, and i created a common ground between the Arduino and the Motor Controller by connecting the GND pin on the Arduino to the GND of the Motor Controller on a mini breadboard (Am i doing this right?).

And i'm using the 5V from the arduino to power the Servo and the Ping(ultrasonic) sensor, with both their ground wires connected to the common ground at the breadboard.

I tried to run a small test code to see if the motors are working, but they don't seem to be:

This is the code:

int IN1=4;
int IN2=7;
int ENA=6;
void setup()
{
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
}
void loop()
{
analogWrite(ENA, 200);

digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
delay(2000);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
delay(2000);
}

I used a multimeter across the DC motors while the code was running and i would get about 0.4V to -0.4V when the above code was executed. So i'm assuming that the motors aren't receiving enough power?

Any help would be appreciated,

Thanks in advance

Shreyas

Hi, I dont know but I saw a tutorial where they said: CSA & CSB need to go to ground if you dont use them. Maybe worth a try.

Well you have made two small mistakes.

  1. You spent to much. L298N Stepper Motor Driver Board, Arduino Supported – ElectroDragon

  2. The product you bought does not have a data sheet that I could find :frowning:

Anyway try connecting 5v to the 5v pin on the motor driver. See if that helps. Also I don't see any PWM in your code. From my experience the PWM will control the speed. Try disconnecting the motors and just test with a multimeter after you make the changes and see how different PWM values affect the voltage.

Best of luck!

A couple things:

  1. As already noted, you need to connect the 5 volt line on the L298 driver - the driver has both logic voltage (5 volts) and motor voltage inputs that are separate.

  2. You mentioned hooking up 9 volts to the (motor?) input on the L298? If you are using one of those small 9 volt batteries for this (PPA3), you won't get very far; those will not be up to the task. If you must use a 9 volt battery, go with a 9.6 volt NiMH R/C pack or similar.

Hmm - something I noticed on that board, in regards to #1 above - it looks like it has a built-in method to supply a regulated 5V to the L298 (there is a jumper labeled "5V_EN") - but it is unclear whether that needs to be bridged to enable the on-board 5 volts, or unbridged (without a schematic - who knows). You might try contacting the seller for a schematic to figure it out. Or, trace it out yourself. Another possibility would be to hook up your 9V source to the board (disconnect it completely from the Arduino), then use your multimeter to measure the voltage at the 5 volt logic input voltage pin on the L298; if you don't measure 5 volts, hook up the jumper ton the "5V_EN" pin - you should have 5V then.

Thank you all for the quick responses!

cr0sh:
A couple things:

  1. As already noted, you need to connect the 5 volt line on the L298 driver - the driver has both logic voltage (5 volts) and motor voltage inputs that are separate.

  2. You mentioned hooking up 9 volts to the (motor?) input on the L298? If you are using one of those small 9 volt batteries for this (PPA3), you won't get very far; those will not be up to the task. If you must use a 9 volt battery, go with a 9.6 volt NiMH R/C pack or similar.

Hmm - something I noticed on that board, in regards to #1 above - it looks like it has a built-in method to supply a regulated 5V to the L298 (there is a jumper labeled "5V_EN") - but it is unclear whether that needs to be bridged to enable the on-board 5 volts, or unbridged (without a schematic - who knows). You might try contacting the seller for a schematic to figure it out. Or, trace it out yourself. Another possibility would be to hook up your 9V source to the board (disconnect it completely from the Arduino), then use your multimeter to measure the voltage at the 5 volt logic input voltage pin on the L298; if you don't measure 5 volts, hook up the jumper ton the "5V_EN" pin - you should have 5V then.

I connected the arduino 5V to the L298N 5V and ran this code:

int EnA=6; // Define output for activation of motor A
int EnB=7; // Define output for activation of motor B

void setup()
{
pinMode(Aon,OUTPUT);
pinMode(Bon,OUTPUT);
digitalWrite(Aon,HIGH); //In case activation is used, activate motor A
digitalWrite(Bon,HIGH); //In case activation is used, activate motor B
}

void loop()
{
int i;
for (i = 0; i < 255; i++)
{
analogWrite(2,LOW); //spin in one direction A
analogWrite(3,i);
analogWrite(4,LOW); //spin in one direction B
analogWrite(5,i);
delay(10);
}
delay(3000);

for (i = 0; i < 255; i++)
{
analogWrite(2,i); //spin in the other direction A
analogWrite(3,LOW);
analogWrite(4,i); //spin in the other direction B
analogWrite(5,LOW);
delay(10);
}
delay(3000);

analogWrite(2,LOW); //stops A
analogWrite(3,LOW);
analogWrite(4,LOW); //stops B
analogWrite(5,LOW);
delay(5000);

}

The motors are receiving more power (about 1V) , but still not enough to move. They start to rotate slowly if i give them a push, so i'm starting to believe it's a power issue. But i assumed the 9V battery would be enough to power them (I'm using two of these - one to power the arduino and one to power the motors via the motor controller [vms] : http://3d4me.files.wordpress.com/2009/02/9v-battery.jpg).

This is what i was told regarding the 5V_EN:

The 5V_EN jumper enables the onboard 5V regulator. If EnA and|or EnB are left floating it will enable bridge A and|or B. To disable, EnA and|or EnB should be put to 0v. The CSA and CSB are current sense pins and are used to sense the motor current. So if you're not using current sense, leave them jumpered to the ground

As of now, the 5V_EN and all the CSA/CSB/U1/U2/U3/U4 are jumpered to the ground.

Any ideas as to what i can do next?

A 298 chip loses a minimum of 2v between input and output (1.8 in fact), and if you look at the datasheet (2nd last line on page 3) you'll see that can rise to almost 5v under high current. With your motors doubled up, you could be drawing quite a high current and be incurring quite a voltage drop. That wouldn't explain the drop right down to 1v though, but as pointed out those 9v batteries are not renowned for their longevity.

I agree, it's a combination of voltage drop in the L298N and the 9V battery not being able to supply enough current. You need to:

  1. Replace the 9V battery by something more powerful. You could use a bank of AA alkaline or NiMH cells, or a LIPO.

  2. Preferably, instead of the L298N use a modern mosfet-based motor driver, such as this http://www.pololu.com/catalog/product/1213. This will reduce the voltage drop to a small fraction of a volt.

dc42:
I agree, it's a combination of voltage drop in the L298N and the 9V battery not being able to supply enough current. You need to:

  1. Replace the 9V battery by something more powerful. You could use a bank of AA alkaline or NiMH cells, or a LIPO.

  2. Preferably, instead of the L298N use a modern mosfet-based motor driver, such as this http://www.pololu.com/catalog/product/1213. This will reduce the voltage drop to a small fraction of a volt.

Thanks guys! I finally managed to get the wheels moving - all i needed was more current. I added a 4 AA Duracells in parallel with the 9V and it's working fine. I'm going to try pick up a 11-12V LiPO if i can get my hands on one. It's almost impossible to find one locally.

Here's a video of the little monster moving back and forth:

Now onto the code!

Thanks again!

I added a 4 AA Duracells in parallel with the 9V

I don't think putting 6v in parallel with 9v is the right way to go, but I'm not sure why 8), and I'm sure someone will explain. That said, glad you've made progress.

Just check though, that you don't provide too much voltage to the motor simply because you get hold of a nice big battery. Check the motors' datasheet for maximum allowed: yes the 298 will chomp volts, but make sure it's not too high. Under no load conditions remember it's only losing about 2v.

JimboZA:

I added a 4 AA Duracells in parallel with the 9V

I don't think putting 6v in parallel with 9v is the right way to go, but I'm not sure why 8), and I'm sure someone will explain. That said, glad you've made progress.

Just check though, that you don't provide too much voltage to the motor simply because you get hold of a nice big battery. Check the motors' datasheet for maximum allowed: yes the 298 will chomp volts, but make sure it's not too high. Under no load conditions remember it's only losing about 2v.

I did realise that connecting the 6V in parallel with 9V might damage the 6V because the 9V might drive current into the 6V pack. What i'll do is get hold of two better quality 9Vs and run them in parallel. I don't think that would pose any problems right?

Thanks for the tip, i'll make sure i pick a battery that suits the motors!

Your help is much appreciated :slight_smile:

ShreyasSkandan:
I did realise that connecting the 6V in parallel with 9V might damage the 6V because the 9V might drive current into the 6V pack. What i'll do is get hold of two better quality 9Vs and run them in parallel. I don't think that would pose any problems right?

Connecting batteries in parallel is not wise. If 6V is enough to turn the motors, why not run the whole thing from 6V? Alternatively, use a bank of 6 AA cells to get 9V, and use this instead of your 9V battery.

dc42:

ShreyasSkandan:
I did realise that connecting the 6V in parallel with 9V might damage the 6V because the 9V might drive current into the 6V pack. What i'll do is get hold of two better quality 9Vs and run them in parallel. I don't think that would pose any problems right?

Connecting batteries in parallel is not wise. If 6V is enough to turn the motors, why not run the whole thing from 6V? Alternatively, use a bank of 6 AA cells to get 9V, and use this instead of your 9V battery.

Thanks for the heads up, i had no idea connecting voltage sources in parallel was such a bad idea.

I'll try and replace the 9V with 6AAs as suggested.

Cheers!

Might I suggest this set-up, which is driving a bot similar to the one above.

I have 2 x ~300mA motors, I'm using just a L298N IC with a 5v Low Drop out regulator.
I'm using 4 x NiZn 2500wAh 1.6v AA size so total volts is 6.4v

6.4v attached to voltage regulator goes down to 5v to power the logic on the L298N and there is another connection on the L298N, which gets the battery voltage which supplies the high current to the motors.
The Arduino is powered by a 7.4v 1600mAh RC NiMH pack.

Using PWM on the EN-Pins is not working very good.
The Motors will not only drive slower ( like they should ) but they also get significantly weaker.
This behaviour makes it difficult to calculate curve radiusses. It is more like: trial and error.
It gets impossible on rough ground.
I've had better results with switching off one side for a short time instead of using a higher frequency PWM Signal.

I haven't tried the pwm library yet, but the original analogWrite doesn't work well.

Hi All,
My last couple of bots have been driven by 6x AA Nimh giving me 7.2V, this is used to drive the motors, then when connected to the Adruino Vin, gets converted to 5V to power it.

I have also used the L293 & L298 but as pointed out they do lose power, and drop a couple of volts across the output transistors. I found using PWM on the Enable pins, gave poor results with anything less then about 70, depens on motors I'm sure.
My current build uses a Pololu driver module that uses the TI DRV8833 this uses FETs so, very little power is wasted, if any, and it's only about 1"x.07"..
Here's a link: http://www.hobbytronics.co.uk/motor-control/drv8833-motor-driver

Hope it helps.
Regards
Mel.