Easy, Reversible Motor Control for Arduino (or any Microcontroller)

 by nothinglabs
Featured
connections.JPG
This project uses just three main components to provide forward and reverse control for a single motor.  You can easily interface it to an Arduino or any other microcontroller.

It's so simple - you can wire it up "free-form" without a circuit board in about 15 minutes.


Features:
All parts available at Radio Shack for under $9
Supports PWM for variable speed control
Handles up to 5 amps peak / 2.5 amps continuous (5 amps continuous with heatsink)
Controlled using just two pins - "enable" and "direction"

Limitations:
Requires at least 7.5 volts to operate
Relay is rated for "only" 100,000 cycles and may not be appropriate for some high vibration projects
Doesn't provide motor "braking"

The most common way to provide reversible motor control is with an H-Bridge.  A basic H-Bridge is made up of 4 transistors - but commonly end up requiring more like 10 components when you include things like flyback diodes and secondary transistors.  

I wanted something simpler for a CNC project I'm working on - so I came up with this design.  I'm fairly sure I'm not the "inventor" of this circuit - but it's not widely documented.  As far as I can tell it doesn't have a name.

I am hereby naming it the RAT Controller.  RAT being an acronym for Relay And Transistors.
 
Remove these adsRemove these ads by Signing Up

Step 1: Stuff You'll Need

parts.jpg
All parts are available at Radio Shack - expect to pay a bit under $9 for the main components.
The same parts are available online for under $4.

12VDC Coil DPDT Miniature PC Relay
Radio Shack Part: 275-249
If purchasing online - try searching for "OMI-SH-212D"

2 x TIP120 Darlington Transistors
Radio Shack Part: 276-2068

2 x 220 Ohm Resistors
Values do not need to be exact.

Optional: Heatsink
A TO-220 size heatsink such as Radio Shack 276-1363 will allow this motor controller to provide 5 amps continuously as opposed to just peak. You'll also need a #6 screw and nut. See the final "Notes" step for information on installing or making your own heatsink out of a pop can.

You'll also need:

Soldering Iron
And solder - any gauge is fine.

Hookup Wire
You'll need some kind of hookup wire to make connections and interface with your microcontroller.
22 Gauge Solid Core Hookup wire works well and easily fits into Arduino headers.
Available at Radio Shack - Catalog # 278-1221


1-40 of 70Next »
RISL says: Mar 2, 2013. 10:02 PM
hello friend i have a question about your proyect and it is posible to use with a step direction 3d printer, the 3d printer use an arduino but is the only thing i need or is necesary a interpreter, i use a sprinter firmware, i need some change or only i have to conect direct.
nothinglabs (author) in reply to RISLMar 4, 2013. 7:10 PM
it should be able to drive any standard DC motor.

Not totally sure - but your printer may user stepper motors - which won't work with this project.
saip says: Feb 11, 2013. 6:45 AM
i dont understand all this circuit connections....can u suggest me any website where i could learn about all this stuff.......plz help me.................
itshuang says: Feb 10, 2013. 5:02 PM
Thanks for your suggestion. I found a wiring that might work for my need: http://www.quasarelectronics.co.uk/kit-files/help-files/uhf-remote-control-reversible-dc-motor-with-limit-switches.pdf

If I use the forward and reverse leads (2.5~3v) to activate the top and bottom relays (e.g a SPDT relay, such as this one: http://www.mdfly.com/index.php?main_page=product_info&products_id=444) respectively, and power(+) connected to the top NC, and power(-) to the bottom NO, do you think it will work? I appreciate your comments to a newbie like me.
itshuang says: Feb 7, 2013. 6:30 AM
While I am searching for ways to make my high torque DC motor reversible, I came across this instructable. It is amazing. What I am trying to do is to use a RC car's Transmitter(Tx)/Receiver(Rx) to control my DC motor's rotation(forward/reverse). The outputs from the Rx are one forward and one reverse which may be "high" depending on what is triggered on the Tx side. It works for low power DC motors. However, it is too weak to drive a high torque motor. So I need to get extra power to drive my motor reversibly. Is this control can be modified in some way to meet my need if I use the outputs from Rx as triggering signals (Say forward connects to one transistor and reverse links to another transistor)?
nothinglabs (author) in reply to itshuangFeb 9, 2013. 11:44 AM
Hard to say - but maybe.

You might try connecting both leads from the RC car to the "enable" pin through their own diodes. Then - additionally connect just one of the leads directly to the reverse pin.

I think this -might- work (or it might make smoke).

have fun / good luck!

-Rich
MohitJindal says: Jan 19, 2013. 3:54 AM
I am planning to buy a new DC motor driver board which can run 5amp motor but I don't know how to connect it with Atmega 8A chip. Please see the pdf I attached for Atmega 8A.

Here are the 7 pins in DC motor controller:-

Pin No. Pin Functionality
1 GND Ground
2 IN-1 Logic input for the motor direction.
3 Diagnostic 1
(DG-1) Output pin with logic 1 output in normal operation. Represents side of the internal
H bridge corresponding to IN-1. Pin is pulled to logic low by the motor driver in
case of over temperature or overload due to short circuit.
4 PWM Used to apply Pulse Width Modulation to control motor velocity
5 Diagnostic 2
(DG-2) Output pin with logic 1 output in normal operation. Represents side of the internal
H bridge corresponding to IN-2. Pin is pulled to logic low by the motor driver in
case of over temperature or overload due to short circuit.
6 IN-2 Logic input for the motor direction.
7 CS* Current Sense output to measure the current flowing through the driver
schmidtbag says: Dec 22, 2012. 6:34 PM
Great guide. I'm using motors that operate up to 24V 36A (I'm running them at 6A though) so I used different relays and transistors, which work fine. The problem is (which I found out the hard way) was the transistors don't have the built-in transistor that the TIP120 has and so blew up from the EMF. Thankfully I have more and only 1 transistor died. Anyways, which diode would you recommend and where do I place them in the schematic you have above? Thanks
nothinglabs (author) in reply to schmidtbagDec 26, 2012. 1:53 AM
Glad you like the instructable!

I haven't used an EMF protection diode with this circuit before (and haven't done too much with them in general) - so take this with a grain of salt.

I would place the diode between the transistor's collector and the positive input voltage. Wire it so the arrow points towards the positive voltage input (the other way round will cause a short).

more info here:
http://www.learnabout-electronics.org/ac_theory/inductors02.php

Sizing is a good question. There is some info at link above. The back EMF voltage can be higher than the driving voltage. Might look for something that can handle the input current at some multiple of the voltage than your'e driving it at. Might be able to get away with something less beefy since it's not getting hit constantly.

Good luck!

-Rich
asharma71 says: Oct 22, 2012. 2:53 PM
I used this circuit with the following parts:
HLS-4078-12vDC
www.helishun.com/hls-4078.html
1k resistor
and tip122
everything works fine but reverse. i suspected 6 volt battery was a problem but i am using a 12 volt battery now.

Please help
Unknown.jpegUnknown.jpegUnknown-1.jpeg
nothinglabs (author) in reply to asharma71Oct 29, 2012. 1:00 PM
I would use a multimeter to make sure you're getting higher than 9v coming -out- of the reverse tip122.

You'll loose some voltage through the transistor - and if the battery is too small - it'll drop more when it tries to turn the motor.

Easy test is to leave enable off - and then just toggle reverse back-and-forth in code. Make sure you hear the relay go "click"
stringstretcher says: Oct 10, 2012. 1:54 PM
Great project! I wire switches like this all the time. Never thought of making one of these. I will surely use this a lot.
Thanks!
paseanlysan says: Aug 2, 2012. 11:40 AM
this is an awesome project!! but i CANNOT get the motor to run in reverse for the life of me...i am 100% sure i have the schematic right and it built right... i am 100% sure my code is correct and im even using a 12 volt battery... it will do forward and forward with pwm but NOT backward... its killing me.. please help!! i spent like 20 bucks getting parts and id hate to go and find another solution to this
nothinglabs (author) in reply to paseanlysanAug 2, 2012. 1:40 PM
are you using the exact relay specified?

what kind of 12v battery are you using?
jackxeus says: Jul 22, 2012. 4:17 PM
I cannot figure out what I'm doing wrong! The circuit powers my motor, but it won't switch the direction of rotation. I am using a 12VDC, 1Amp wall wart power supply, so I assume that's providing enough power. I hear the relay switching, but the motor continues to rotate in the same direction.

Any ideas?
nothinglabs (author) in reply to jackxeusJul 23, 2012. 4:09 PM
I would tripple check your wiring - specifically the wires cross-connecting the two sets of relay outputs.

good luck!

-Rich
compgeek97 says: Apr 15, 2012. 7:20 PM
does it matter what relay is used as long as it's 12v 5a? i found 2 OMRON MY2NJ on ebay for cheaper than the ones used in this instructable. I'm a kid with no job so I kinda need to cut all the corners I can :D
nothinglabs (author) in reply to compgeek97Apr 15, 2012. 10:34 PM
From the specs - it looks like those guys have a 28v trigger voltage - which is too high.

suspect it would probably not work.

hope this helps!

-Rich
DNMEBOY says: Aug 25, 2011. 2:31 PM
I made this and it seems to be working correctly but my motor does not go backwards. Any ideas?
stupidloginthing in reply to DNMEBOYDec 17, 2011. 2:09 PM
funny. I'm using a 10 volt battery and using this circuit for a stepper motor from a drill intended for 7.2 V. It won't go backwards either. (I set the PWM power control to half (128) so that it's not too hard on the motor.)

I get the feeling something is fundamentally wrong because no power comes through to the motor when it's supposed to be running in reverse.

any ideas?
nothinglabs (author) in reply to stupidloginthingDec 19, 2011. 11:46 AM
a very common cause of this problem is a battery that's not producing enough voltage to fully switch the relay. 10v should be enough - is it possible the battery isn't fully charged? (it may also be that the voltage sags to under 7.5v when powering the motor).

this might sound really generic - but I would triple-check all the wiriing.

is it possible anything is backwards / upside down?

I'm assuming you're not really using a stepper motor - but some kind of geared DC motor (stepper motors require very special drivers).

Good luck - let me know how it goes.

-RIch
stupidloginthing in reply to nothinglabsDec 20, 2011. 10:28 AM
yeah its not a stepper motor it just behaves strangely. I think that's likely because we had an AC-DC power source before that we set at 12V and it worked fine then. the battery was producing 10.8V, which wasn't quite enough to reverse it, then later it didn't make a sound and wouldn't reverse (as battery drained).

anyways I ordered a motor controller because I'll need to use servos too. this was a good experiment and got us an A on our class project, so thank you.
DNMEBOY in reply to DNMEBOYAug 25, 2011. 3:02 PM
Nevermind, I was using a 7.4v lipo to power this project, I had the thought that the voltage may not be enough so I connect a 12v Lead Acid battery and it works exactly as it should. So if anyone else runs into the same problem chances are its your input voltage being to low. I wish I still had some 3s 11.1v lipos. The lead acid battery is just BIG.
nothinglabs (author) in reply to DNMEBOYAug 25, 2011. 3:49 PM
that'll do it! 7.4v is right on the edge (wouldn't surprise me if it worked on a full charge).

if you poke around online - you should be able to find some relays that would work fine at lower voltages.

glad you got it working!

-Rich
DNMEBOY in reply to nothinglabsSep 6, 2011. 2:12 PM
I disconnected everything from my arduino after running a motor with this and now windows doesnt even see my arduino uno, nothing in device manager, any ideas? im pretty bummed since i just ordered that motor sheild.
nothinglabs (author) in reply to DNMEBOYSep 8, 2011. 2:28 AM
sorry you're having arduino probs. I don't think it's this project though - I've played around a fair amount with it without problems.

is it possible you connected your battery to VSS instead of VIN? that might do it.

I've found pushing the reset button just before programming can help it take an upload (shouldn't need to do this - but sometimes helps)

also - trying another USB port might help.

-Rich
DNMEBOY in reply to nothinglabsSep 8, 2011. 11:08 AM
It seems that the 8u2 on my board has died. It's the only thing I can think of. It makes sense as the 8u2 is in charge is USB/serial communication. Which isn't working yet the arduino still runs your sketch. Your project isn't to blame I'm sure. Just that I was messing around with it when my arduino stopped working. I had the USB plugged in while running the motor. I could hear the arduino connecting and disconnecting from windows. Not sure what happened. The project was powered with a 12v lead acid battery. Positive to your motor controller and ground to the ground on the arduino as well as the ground from the motor controller to the arduino. My guess is that something was connected wrong but no different than the first time I did this project.

I only asked you because you seem to know more than me about this stuff and I was desperately trying to find the problem. The seller has agreed to ship me a new arduino provided I return the dead one. Going to be a long wait from hong kong.
nothinglabs (author) in reply to DNMEBOYSep 9, 2011. 1:13 AM
one thing that sometimes helps is re-flashing the arduino boot loader - but you have to have an AVR programmer to do that.

on the other hand - if you're not even seeing it as a serial port - that does sound like a hardware issue.

i will mentiin that while I've generally had good luck with clone arduino (pretty mcuh anything from asia) - I've maybe had a few more issues with them than the ones actually from italy.

good luck!

-Rich
DNMEBOY in reply to nothinglabsSep 9, 2011. 5:09 AM
According to what I've learned if the led on pin 13 blinks on reset the bootloader is fine. The arduino still runs your sketch. Maybe if my replacement fails I'll purchase an arduino that's not a clone. I've got 3 kids so money is tight. If I can get a clone for 20 bucks on eBay with free shipping that's a great deal. I've also always been told that the only thing worth buying cheap is beer. So maybe a quality arduino would be worth the extra money.
DNMEBOY in reply to nothinglabsSep 6, 2011. 11:44 AM
I found a 5v relay at radioshack but honestly I would have no clue how to wire it up and make it work like the one you made.

I went ahead and ordered a motor controller based on the L293D from ebay. Just waiting for it to arrive from hong kong...

Im planning on building an autonomous vehicle that uses skidstearing. So basically like a little tank. Ive got alot to learn. Right now im pretty much just finding tutorials like this and copy/pasting code. Ive yet to come up with anything on my own.
nothinglabs (author) in reply to DNMEBOYSep 8, 2011. 2:25 AM
I can't say for sure - but I suspect that 5v relay won't work for this project.

good luck with your robot!

copy/pasting is a pretty good way to learn stuff. I suspect a large amount of commercial software is developed like that...

-Rich
Eternal_Tristan says: Dec 14, 2011. 10:23 AM
You should be able to swap a 2n2222 for the giant TIP-120 connected to the relay coil. That will save you a couple bucks.
nothinglabs (author) in reply to Eternal_TristanDec 14, 2011. 5:35 PM
good suggestion - but any risk of back EMF from the coil? one of the reasons I like the darlingtons is they have a diode that limit back EMF....
cShellPro says: Aug 31, 2011. 11:31 PM
Hi NothingLabs,
having read your Instructables, I'm wondering
why you use a relay to control a motor?

You could build a simple H-Bridge
and drive the MOSFETs with transistors.

Please have a look at this link:

http://www.instructables.com/id/H-Bridge-on-a-Breadboard/

Ciao Frank
nothinglabs (author) in reply to cShellProSep 1, 2011. 12:31 AM
There's no question the mosfet / h-bridge approach has advantages - but you'd be looking at at least twice the component count (and may or may not be able to get everything from Radio Shack).
cShellPro in reply to nothinglabsSep 1, 2011. 12:40 AM
For an H-bridge you just need two transistors, four MOSFETS
and of course resistors or go straight for
an H-Bridge such as SN754410. Parts are readily available.
Swishercutter says: Apr 13, 2011. 12:53 PM
Is that really your soldering iron tip? I think you need a new one. Once you have the new one do 4 things to preserve your tinning.

1.) Before you power up (every time) make a coil of solder on the tip so that it melts as the iron warms up.
2) Always add solder to the tip before setting the iron in the holder. Some people say keep the tip clean but that only applies to the dross (blackish metallic stuff that builds on the tip that doesn't melt), it is best to always have solder on your tip.
3) Add a large blob of solder to the tip as you turn the iron off so that there is a blob on it while its being stored.
4) Never...I will repeat NEVER use your soldering iron for anything except solder.
Air exposure while heated is what damages the tip mainly. Your solder joints will flow better and easier with a maintained tip.

These are the things I was taught in industry by 30 year solderers.
ptacnik in reply to SwishercutterJul 23, 2011. 7:58 AM
I Went trough the hassle of getting IPC certificates once, This transcripts from the DVD's Exist !! FREE !!! here is one for Soldering Iron Tip Care and you can get the certificate for FREE !!!!  the good thing is that you can try as many times as you want, you will notice that Tin can Disolve the Iron plating, and the sponges stress the tip and creates micro cracks, that filter tin in to the core and breake the tip ;-) 
Swishercutter in reply to ptacnikJul 28, 2011. 3:41 PM
I was lucky (or unlucky) enough to be working for a company that required the certificate...so I was even paid to take the classes. Once you are certified you just have to retest to become recertified...mine expired in 2002.

I agree about the sponges...some people overuse the sponge, I only use it if there is dross on the tip. My tip is a few years old and looks new.
nothinglabs (author) in reply to SwishercutterApr 13, 2011. 6:30 PM
yup - that's my soldering tip...

I've gotten lazy and just crank the heat up until it works... which I'm sure compounds the problem.

I also have the bad habit of leaving it on for long durations.

I'll probably swap it before I do anything which requires precision...
1-40 of 70Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!