Problem with DC Motor and L293D Motor Shiel

Hi everbody

I'm doing an arduino uno R3 robot using 4 motors with an L293D Motor Shield. My problem is tha, when I connect the arduino to my laptop through an USB cable, my robot's motors run perfectly as what I coded. However when I unplug the USB and use an external source ( 3 x 4,2 volt baterries), my robot will go nut or don't move.Below is the simple code that I used to run my robot, also, I've attach some of my robot's pictures link. Please show me where I was wrong. Thanks in advance guys !

https://www.facebook.com/quanghuy.vo.948/media_set?set=a.753731021399593.1073741831.100002881079163&type=3&uploaded=4

#include <AFMotor.h>

AF_DCMotor motor1(1,MOTOR12_64KHZ);

AF_DCMotor motor2(2,MOTOR12_64KHZ);
AF_DCMotor motor3(3,MOTOR34_64KHZ);
AF_DCMotor motor4(4,MOTOR34_64KHZ);

void setup() {
Serial.begin(9600);
Serial.println("Motor test");

motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop() {

motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
delay(5000);

motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(1000);

motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(5000);

motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(1000);

}

Explain the battery in more detail please - what cells, are they in series or parallel... How
are they connected to 1) The Arduino, 2) the motor driver.

Well I used 3 cell ( 3 batteries in a pack if that's what you meant ?! ) and they are in serial, I connected them to the shield. Are they supposed to supply power for the arduino too sir ?

well,i don't know if it will be of any help to you,but,you can take a look at my video of controlling DC Motors using L293D with ardino uno.

voquanghuy:
Well I used 3 cell ( 3 batteries in a pack if that's what you meant ?! ) and they are in serial, I connected them to the shield. Are they supposed to supply power for the arduino too sir ?

What are you using to power the Arduino board when not powered by USB? Does the shield supply power to the Arduino?

I don't use any source to power the arduino, I just use 3 x 4,2 volt batteries to power the shield, but the led on arduino is turned on as the shield is connected to the arduino. Is it enough or I have to supply the arduino with another source separately ?

voquanghuy:
I don't use any source to power the arduino, I just use 3 x 4,2 volt batteries to power the shield, but the led on arduino is turned on as the shield is connected to the arduino. Is it enough or I have to supply the arduino with another source separately ?

I'm not familiar with the shield, I don't have one, but I would think that you do need to power the Arduino separately.
The fact that the LED lights isn't an indication that all is well. The Arduino might be getting 'phantom' power from the digital pin connections to the shield.
In general, it is not good practice to use the same supply for motors and for the Arduino, due to spikes from the motors, so there is a good chance that the shield does not power the Arduino.

Perhaps someone with the same shield could clear this up, or you could even read the shield's datasheet thoroughly. It will say whether or not it has an onboard 5V regulator to power the Arduino.
(After all, this would explain why your project works when USB is connected, but doesn't work when it's not connected.)

OldSteve:
I'm not familiar with the shield, I don't have one, but I would think that you do need to power the Arduino separately.
The fact that the LED lights isn't an indication that all is well. The Arduino might be getting 'phantom' power from the digital pin connections to the shield.
In general, it is not good practice to use the same supply for motors and for the Arduino, due to spikes from the motors, so there is a good chance that the shield does not power the Arduino.

Perhaps someone with the same shield could clear this up, or you could even read the shield's datasheet thoroughly. It will say whether or not it has an onboard 5V regulator to power the Arduino.
(After all, this would explain why your project works when USB is connected, but doesn't work when it's not connected.)

i tried your suggestion, connect the 9V battery to the arduino separately but the robot still doesnt behave like what I want. Do you still have any idea ? I'm very confused now guys ?

voquanghuy:
i tried your suggestion, connect the 9V battery to the arduino separately but the robot still doesnt behave like what I want. Do you still have any idea ? I'm very confused now guys ?

Not having the motor shield, at this point I could only guess.

A 9V battery is a bad choice for powering an Arduino, but as long as it has a full charge it should do the job short term.
The best thing to do is to wait for someone with the same motor shield to reply, and hope they can help.

OldSteve:
Not having the motor shield, at this point I could only guess.

A 9V battery is a bad choice for powering an Arduino, but as long as it has a full charge it should do the job short term.
The best thing to do is to wait for someone with the same motor shield to reply, and hope they can help.

OldSteve:
Not having the motor shield, at this point I could only guess.

A 9V battery is a bad choice for powering an Arduino, but as long as it has a full charge it should do the job short term.
The best thing to do is to wait for someone with the same motor shield to reply, and hope they can help.

Then how much Voltage do you suggest me to use to power up my arduino board? I also tried the 5V source too but the robot just ran correctly at some first moves, then it started to go wrong !

The key point is not to share motor power with the Arduino that's always a bad idea, most problems
people have are through doing this - separate power for motors and logic, always.

voquanghuy:
Then how much Voltage do you suggest me to use to power up my arduino board?

It's not a matter of voltage, it's a matter of current capability. 9V is fine, but a typical 9V battery like those used in a smoke detector have too low a capacity to be useful.

I also tried the 5V source too but the robot just ran correctly at some first moves, then it started to go wrong !

What 5V source? What is it's current capability? And how did you connect it to the Arduino? Not through Vin, I hope?
If you want help you need to provide full information about things.

I use an a 5V dapter to get power from socket to my arduino, I plug it into arduino's DC power jack. Also,I read some information about the L293D, they said that I should use the NiMH battery pack for the shield as the 9V battery won't do much thing. I wonder what is the difference between 2 sources ? Really thanks for helping me this far guys :slight_smile:

voquanghuy:
I use an a 5V dapter to get power from socket to my arduino, I plug it into arduino's DC power jack.

You can't do that. There is a voltage drop across the regulator, about 1V to 1.2V depending on load, so your board will only 'see' about 4V.

Also,I read some information about the L293D, they said that I should use the NiMH battery pack for the shield as the 9V battery won't do much thing. I wonder what is the difference between 2 sources ?

I already answered this when I said:-

It's not a matter of voltage, it's a matter of current capability. 9V is fine, but a typical 9V battery like those used in a smoke detector have too low a capacity to be useful.

Another point too, while I'm at it - You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.

ie Your code and any error messages should always be placed between code tags </>. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

So what type of battery do you advice me to use for my arduino board based on your experience ? As for the power for the motor shield, I use the Panasonic type NCR 18650-4,2V-4200mAh battery, I use 3 batteries so I guess I have enough current capacity for the robot.

Really sorry for the inconvenience but I'm new to arduino and this community, still trying to get used to it.

But your previous answer confused me as when I connect the robot to laptop through an USB cable, all the 4 motors run fine even without power supply for the motor shield ( just slower ). And this really drives me out of mind.

I know that keeping asking too many questions is irritating but this is my first motor project and there are many things I still haven't figured out logically. Please excuse me for that !

voquanghuy:
So what type of battery do you advice me to use for my arduino board based on your experience ? As for the power for the motor shield, I use the Panasonic type NCR 18650-4,2V-4200mAh battery, I use 3 batteries so I guess I have enough current capacity for the robot.

Really sorry for the inconvenience but I'm new to arduino and this community, still trying to get used to it.

Sorry, I should have elaborated further. The 5V supply you mention here would be fine:-

I use an a 5V adaptor to get power from socket to my arduino, I plug it into arduino's DC power jack

Just connect it 'directly' to the Arduino's 5V connection, not to Vin or the power jack.

I guess that apart from for testing, you won't want to use the 5V adaptor for your Arduino, since then the robot is tied to the mains power and can't travel far. For batteries, anything capable of about 7V would be fine, but you won't need as much capacity as the motor supply. Anything from about 500mAh upwards would give plenty of time between charges. Perhaps just a 7.2V NiMH, with a capacity of about 1000mAh?

Looking at the datasheet for the L293D, it requires a supply voltage of 4.5 V to 36, so the batteries for your motors aren't really suited to the purpose. Also, the L293D output saturation voltage is 1.2V, so even if the chip does function properly with 4.2V applied, the motors will only 'see' about 3V.
The battery capacity is fine, but the voltage is low enough to possibly be causing your problems.
Also, are they 'really' 4.2V, or only 4.2V when fully charged, straight off the charger?

  • Well, I just took the time to read the specs on the Panasonic NCR 18650 batteries that you're using. The nominal voltage is 3.6V, not 4.2V. They would be 4.2V straight off the charger, but would fairly quickly drop to 3.6V. That's too low for an L293D, according to it's datasheet.

Anyway, here's the L293D datasheet:-
L293D

And here's the Panasonic NCR18650 battery datasheet:-
Panasonic NCR18650

You might need to do some thinking about your design before continuing. (This is really all stuff that you should have done during the design stage, before even buying any of the parts.)

In answer to your latest post, I just read a little info on your motor shield. (The stuff I have already suggested that you read.)
There is a jumper on that shield to allow the batteries to supply the Arduino, as far as I can tell. I specifically asked you about this yesterday.

Now you need to go away and do a lot of reading on all aspects of your project, then approach it again if you want it to work properly. I've spent far too long trying to research the things that you should have already done. This is programming and electronic design, two complicated subjects. You cannot approach it half-assed.

And when looking for the info on your motor shield, don't overlook the fact that it is the old version, not the latest, which is V2. Otherwise the information will be misleading.

I'm trying to get up to speed on this project.

What is the output voltage of the battery pack? If those three batteries are in series then it should be about 12V. Is this correct?

Is there a link to the shield being used? I couldn't find it.

Where is the code from?

DuaneDegn:
I'm trying to get up to speed on this project.

What is the output voltage of the battery pack? If those three batteries are in series then it should be about 12V. Is this correct?

Oh oh. Series. I messed up. My bad, sorry. Somehow I managed to miss that. Too tired, I guess, I'd been awake for almost 24 hours.

Regarding powering the Arduino from the shield. That's how I interpreted this:-

If you would like to have a single DC power supply for the Arduino and motors, simply plug it into the DC jack on the Arduino or the 2-pin PWR_EXT block on the shield. Place the power jumper on the motor shield.

Maybe I'm mistaken again. I don't know, but it looks like that's what it means.

Anyway, after this latest mistake, I think I'll stop posting here on the forums, at least for now. Feeling quite embarrassed, and don't want to mislead people with bad information.