Curse of the L293D

After reading through The Makerspace Workbench (which I mostly enjoyed), I thought the Arduino-controlled car project looked like a good introduction to programming and electronics for my two sons. The project involves an Arduino Uno (which I replaced with a Sparkfun Pro Micro clone), a 3D printed chassis, a Tamiya 70168 double gearbox kit, a 9-volt battery, a marble, and a L293D to control the motors. The instructions in the book could be better, but with a bit of Googling, I was able to learn enough to get the project together.

Since the project calls for a 9V battery, and the motors want 3-6V, I added a 5V regulator (L7805CV). I also added capacitors as in here.

The problem I'm having is that the car just pauses silently for a couple of seconds after a second or so of operation.

I'm using PWM to the L293D's enable pins to vary the speed of each motor, making the car do a sort of random walk. The useful PWM range on the enable pins seems to be 128 to 255 (2.5V to 5V). My code just picks a random direction (forward or backward) and an enable value (from 128 to 255), uses that to run the wheels for half a second, coasts to a stop for a quarter of a second, then repeats. Simple. But it runs for a couple of cycles, then sits silently for a couple of seconds, then continues. When programming the Arduino and with USB power available, the motors get power, but seemingly less as the motors turn more slowly, it only rarely pauses when run in this way.

Could this pausing problem be the current limiter on the L293D causing trouble?

I'm also wondering if "feedback" from the motors is causing issues. The pausing problem didn't seem to be an issue when my sketch would run the wheels in whatever direction they needed to go for a couple of seconds at a time. But I thought the capacitors would help with that.

I could be wrong, but the problem seemed to start when I began playing with sending a PWM signal into the L293D's enable pins. It's hard to say though, as we started running the motors in more interesting ways at the same time.

Another problem is that the little car eats 9V batteries in a hurry. If we get 10 minutes of runtime, I would be surprised. And the pausing problem seems to get worse as the batteries die.

My boys and I have had fun with this project, enough that we're looking for something similar but better thought out, although cheap is good. Any recommendations are welcome. We were looking closely at this 4WD chassis, but are hesitant to push further as we, clearly, have a lot to learn.

I modified my sketch to "walk" for two seconds before coasting (for 1/4 second) and then choosing a different direction. The pausing problem is much less prevalent. Now, it might run properly for 15 seconds at a time before pausing.

Since the project calls for a 9V battery, and the motors want 3-6V, I added a 5V regulator (L7805CV). I also added capacitors as in

I only read this far in your post, but you cannot successfully power motors from the small PP3 9v batteries. Motors need a separate external power supply. Also, the L293D may drop a couple of volts, so maybe make a ~9v power supply for the motors using six AA rechargeable batteries.

Hi Rural,
What type of 9V are you using? PLEASE tell me you're not using those tiny PP3 things, as their usless for this job and can't provide the power (Current) your motors need..

Also the L293 is a bad choice as it waste power (2v+) in the output transistors. Try the DRV8833 FET driver module.

Sorry just seen what Zoomcat said, I agree!!

See my bots at :www.melsaunders.com under Electronics.

Regards.

Mel.

Cool. Thanks guys. This helps.

Yes, I'm using PP3 batteries. Alkaline. I dug through my electronics pile last night in search of 4x, 6x, and 8x AA cell boxes. I would have already switched to them if my chassis allowed an easy way to do so.

I also think that I have a driver that might work. A nice one from Pololu.

Based on my experiences, I feel that The Makerspace Workbench could use a revision. Several of the projects have issues. That's a constructive criticism. There's lots of good stuff in the book too.

If you have to use PP3 size batteries your only option is leading-brand NiMH versions,
alkaline will not provide enough current. But really they are not for motors, they were
invented to power transistor radios.

Before you proceed you need to check what current your motors actually use - if
its too much for an L293D then you'll need to find alternative motor driver.

Found a 6xAA battery box and rigged it up to power our project. I also geared down the Tamiya gearbox to 114.7:1 (from 38.2:1). The behaviour is almost exactly the same. So my strong suspicion is that the L293D is the problem. Reading the spec-sheet confirmed it.

I've got some cheapo L298N Dual H-Bridge driver boards on the way. Noticed that an educational kit used them. They will probably do for my current project, but they are far from amazing. Decent drivers from Pololu don't cost much more (but I'll need more than just the drivers to justify shipping).

Special thanks to Mel. I'm enjoying your robots.

298s are as bad as 293s.... they drop 1.8V minimum before you apply load, 4.8V dropped at 2A.

Edit: on a more positive note, I've used this Pololu successfully.

Hi Rural,
Glad you like the bots… did you note the Tamiya motor/gearbox on a couple?

@Jimbo yes that's the DRV8833 module that I have used, and can say yes it's a good 'un both the L293/89 have the same problem with wasting power.. And I don't think I will use them again there's no need to.

Regards

Mel.

Rural:
Found a 6xAA battery box and rigged it up to power our project. I also geared down the Tamiya gearbox to 114.7:1 (from 38.2:1). The behaviour is almost exactly the same. So my strong suspicion is that the L293D is the problem. Reading the spec-sheet confirmed it.

You did eliminate the 7805 regulator from the motor circuit, correct? If you didn't, that's part of your problem.

Basically, you never use a linear regulator with a motor - since the L293 will drop a couple of volts, a 9V battery pack made with 6 AA cells (alkaline - 7.2 volts if NiMh) should give you enough voltage after the drop (provided the motors don't pull much current, which I doubt those small toy ones on that gearbox do). Even if you are running 7 volts to a 6 volt motor, it won't be that big of a deal - the life expectancy of the brushes and bearings will just be a little less is all.

Both the L293 and L298 drivers work fine for their purpose; no, they aren't the most efficient, and they are also old - but as long as you realize their limitations and design for that, they work just as well as they did when they were first introduced to the market.

That said, though - the L298 was mainly meant for use as a stepper driver (with the L297). Also, if you need to be more efficient, then a mosfet-based driver is a better option overall.

Thanks cr0sh. I took the regulator out of the loop, supplied the Arduino via the raw pin, and gave it a go. It's worse, pausing every second or so. I'm starting to wonder if I damaged the L293, because it didn't do this when I first got everything rolling.

The DRV8833 is on my list as a potential buy. If the L298-based drivers don't work well enough, that's the direction I will go. I understood that there would be a similar voltage drop as the L298 is based on the same technology as the L293, but I'm trying to keep this project on the cheap as it might turn into a robotics introduction at the local library.

My first assumption is the battery, most consumer type batteries have terrible current sourcing.

When you try to draw more then it can provide they don't give you as much as they can give, they shut down completely. Those batteries are designed to last ~30-60min+ at full load, running them dry in 10min is proof of over use. The ones that don't shut down from over drawing just start to over heat like crazy.

You could be over heating the L293 but that's a easy test put your finger on it, if it doesn't start to burn its probably fine. Most chips are rated to run at up 100-150C before they have issues.

For everybody who suspected the batteries: You were spot-on. Woo-hoo!

Some Eneloop rechargeable AAs that I ordered arrived yesterday. Charged them up and stuck them in my 6xAA battery box and plugged it into my little "robot". It was like night and day. After seeing those motors working with the new batteries, I think they were on the edge of stalling most of the time with the old batteries. With a 5V regulator in the circuit, things seem about right.

I noted in another thread that my ultrasonic distance sensor was behaving incorrectly when the motors were running. With the good batteries in place, everything behaves correctly.

Now I just have to modify my chassis design (which is 3D printed) to add stowage for the battery box...

Edit: Actually, I spoke too soon. There still seems to be some interaction between the motors and the distance sensor. My guess is that some diodes are in order.

Hi Rural,

My guess is that some diodes are in order.

I think a few de-coupling caps may be needed. Also does that 5 Reg have the required smothing caps on it? I take it this goes in the the Arduino's 5v.

Edit: Actually, I spoke too soon. There still seems to be some interaction between the motors and the distance sensor.

Don't see how this can be a problem, not one I have had, and find all the various U/S sensors seem to work very well, have you got 0.1-0.33mF caps across the motors? the motors are the largest cause of noise on the supply lines.

I don't think you have posted your code, we could check it for you.....

Regards

Mel.

Sorry for dropping this. Got distracted by a rebuild of a CNC router.

To quickly recap: I seem to be getting interaction between the motors and distance sensor (an HC-SR04). But to be honest, I'm really unsure of what I have done. I have a 4WD chassis and slightly better drivers due to arrive any day now, and will start from scratch at that point. I'm pretty confident of my sketch and little confidence in anything else. But this has been really fun to play with and I look forward to taking it to completion.

Cactusface, I have caps between each of the motor legs and ground. Not sure if that's the correct way to go or whether the caps should be between the motor legs. These are ceramic caps, "104". There is also a 100uF cap on the output of the 5V regulator. I believe I've tried putting the cap on the input of the regulator as well.

Rural:
Cactusface, I have caps between each of the motor legs and ground. Not sure if that's the correct way to go or whether the caps should be between the motor legs. These are ceramic caps, "104". There is also a 100uF cap on the output of the 5V regulator. I believe I've tried putting the cap on the input of the regulator as well.

Usually, caps on a DC motor go between the leads and the motor case (note - it is very difficult to solder to a motor case - you need a fairly large soldering iron - > 50W - usually), and generally one between the leads. Typically, the single cap between the leads may suffice.

Hi cr0sh,
I did hear that caps to the motor case is a bad idea, and the motor case just becomes a radiator for noise! As you say across the motor terminals 0.1-0.33mF seems best.

Regards

Mel.

Yes, caps to the motor case is really only done when the motor case is grounded. It just makes for a very short, low impedance path to ground.

I got my largest package of electronics bits last week and have been figuring out each type of bit in turn. I got to the L298N modules (these ones) over the weekend. As far as I can tell so far, having just hooked them up to an Arduino and motors, they seem to work fine. Everything runs without issue for several minutes, well beyond the point where I get bored. There doesn't seem to be any issues with the ping sensor either.

Although they are larger than I would like, the modules sure simplify things.

A sort of epilogue to this project:

Well, I pushed further with this project and have rebuilt everything with a 4WD skid-steer chassis. Each motor is supposed to draw at most 250mA and 6-8V is recommended. Power is being provided by 6xAA NiMH batteries (Eneloop).

Running a sketch that has the vehicle test its entire range of motion, all is well.

This weekend, I added an NRF24L01+ module to the vehicle (using a 3.3V buck module for power) and then a Funduino Joystick Shield on an Uno with another NRF24L01+ to control the vehicle. Nothing ground-breaking here, although I'm pretty proud of the algorithm I used to convert the joystick position to direction and PWM for the motor controller).

What I found was that there was enough of a voltage drop when the left and right wheels fight each other (ie. when beginning to spin the vehicle around or when initially accelerating) that the NRF24L01+ on the vehicle would not properly receive a signal. Once everything gets moving, control comes back.

Adding a diode followed by a 330uF cap to clean up the power to the Arduino and NRF24L01+ helped, allowing the vehicle to hold my 7 and 10 year-old boys' attention for about 5 minutes. But I noticed that the L298N module can supply/consume power via a 5V input connected to the Arduino's Vcc. The L298N module can power itself from the same power supplied for the motors (as long as it's from 7-12V). So I disconnected the 5V supply. In that state, the power to the Arduino and NRF24L01+ could drop enough to cause the Arduino to reset. The L298N seems to supply cleaner power than my little diode and cap arrangement. It still seems like the NRF24L01+ link is introducing spurious delays, but the vehicle is quite useable in its current state.

Other than being a little surprised that the NiMH batteries may not be supplying enough juice, I'm pretty happy. It's been a lot of fun. I've certainly learned a lot.

Next steps: Lithium ion batteries for power. Even better, I found a decent DRV8833-based driver in my electronics pile. It was sitting there the whole time, intended as a driver for stepper motors. Arg!