# Best way to control the direction of motors

Hello! I am not currently working on this project. However, if I were to make an RC car with an Arduino, what would be the simplest and smallest way to control a motor's spinning direction by reversing the polarity? The motor (300mA) needs transistors to operate. So is it possible to toggle motor on and off and change its rotation direction with only PNP and NPN transistors? Or does it require another way? Thanks!

Yes it is possible. Look up the h bridge circuit

Thanks Grumpy_Mike. This is an H-Bridge example:

S1 S2 S3 S4 Result
1 0 0 1 Motor moves right
0 1 1 0 Motor moves left
0 0 0 0 Motor free runs
0 1 0 1 Motor brakes
1 0 1 0 Motor brakes
1 1 0 0 Arduino dies
0 0 1 1 Arduino dies
1 1 1 1 Arduino dies

Why not consider something like a L293D? They can handle the current you are talking about and are pretty cheap. They were designed for just this sort of application.

http://www.aztecmcu.com/sitebuildercontent/sitebuilderfiles/l293d.pdf

Since your question was...

what would be the simplest and smallest way

.... a 293 is a good choice. Only reason to it with transistors that I can think of, is if you had a need to learn about this from first principles. Let the 293 do the electronics for you.....

This tutorial shows wiring and Arduino code.

If the 300mA is the no-load rating then you'll need to find out the stall-current too - that's the one that will bite you.

How come on the Wikipedia H-Bridge chart on my reply #2 show that if the same charge is applied on both terminals of the motor, the motor will "brake"? Isn't there no current flowing?

When both the top or both the bottom switches are on, the motor terminals are effectively shorted together,
which acts as a electromagnetic brake.

Electromagnetic braking gets stronger as the square of the motor speed, note, and lots of current can flow
(all DC motors are also DC generators).

Will using the electromagnetic brake risk damaging the motor, other components or the Arduino?

Shouldn't do.

And obviously, the motor is not drawing current in electromagnetic brake mode, right?

No, it is supplying current. That's how the Prius works.

AWOL: Shouldn't do.

Depends on the set-up - full-on braking with a large motor spinning fast and lots of (moment-of-)inertia could rip the motor off its stand! With a small hobby motor I don't think there will be any issues...

With electric vehicles the electromagnetic braking is under PWM control so the braking force can be controlled to the desired level, avoiding wheel-lock or damage. Full-on braking is equivalent to stall-conditions so that the current (and thus torque) is limited ultimately by the motor's internal resistance.

DC motors produce torque pretty much directly proportional to current, and back EMF is directly related to rotation speed. When under normal load the applied average voltage is roughly the same as back EMF, only the difference between applied voltage and back EMF is available to drive current through the windings. Braking is simply applying 0V to the windings (thus full back-EMF is available to drive current through windings)

65, The conditions which you have labeled as 'shoot through', should be re-labeled to something like 'OUCH!', or 'what's that smell?'. the bridge (s) become short circuits and smoke belloweth forth...

No, it is supplying current. That's how the Prius works.

:open_mouth: I have to test that with a multimeter measuring current in series!

Do I need protection diodes to stop the back EMF or whatever from damaging the Arduino? If so, where would the diodes go?

Braking is simply applying 0V to the windings (thus full back-EMF is available to drive current through windings)

So the motor is using its back EMF to resist motion? Is there any difference between brake 0101 and 1010 (refer to chart)?

So the motor is using its back EMF to resist motion?

Yes Is there any difference between brake 0101 and 1010 No. One takes both ends of the motor to the +ve supply and the other takes both ends to ground. Either way they are shorted.

Oh yeah, my transistor H-Bridge with 500 mA NPN transistors are not working. See my picture in my first reply. What is wrong with the circuit? I checked the wiring and everything.

H-bridges using only NPN transistors are not terribly effective. Do you have a schematic?

I copied this one: http://www.clear.rice.edu/elec201/Book/images/H-bridge4.gif I wired it the same way as shown in Reply #2 of this thread.