Super Easy Reversible Motor Control for Arduino

Embed Size (px)

Citation preview

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    1/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Home Sign Up! Browse Community Submit

    All Art Craft Food Games Green Home Kids Life Music Offbeat Outdoors Pets Photo Ride Science Tech

    Easy, Reversible Motor Control for Arduino (or any Microcontroller)by nothinglabson April 11, 2011

    Table of Contents

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

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

    Step 1: Stuff You'll Need .....................................................................................................

    Step 2: Schematic and Theory of Operation .......................................................................................

    Step 3: Bridge NO and NC Pins (Part 1) .........................................................................................

    Step 4: Bridge NO and NC Pins (Part 2) .........................................................................................

    Step 5: Connect Coil Pin To Common Pin ........................................................................................

    Step 6: Connect TIP120 Collector to Relay Coil Pin .................................................................................

    Step 7: Nudge TIP120 Into Position .............................................................................................

    Step 8: Connect Second TIP120 Collector to Relay Common ..........................................................................

    Step 9: Connect TIP120 Emitters ...............................................................................................

    Step 10: Connect Resistors ...................................................................................................

    Step 11: Review Connections .................................................................................................

    Step 12: Hook It Up! ........................................................................................................

    Step 13: Upload the Code and Test .............................................................................................

    Step 14: Notes ............................................................................................................

    Related Instructables ........................................................................................................ 1

    http://www.instructables.com/member/nothinglabs/?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/tech?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/science?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/ride?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/photography?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/pets?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/outdoors?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/offbeat?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/music?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/life?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/kids?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/home?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/green?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/games?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/food?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/craft?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/art?utm_source=pdf&utm_campaign=categorieshttp://www.instructables.com/about/submit.jsp?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/community?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/tag/type-id/?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/account/gopro?sourcea=inside_pdfhttp://www.instructables.com/?utm_source=pdf&utm_campaign=title
  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    2/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Author:nothinglabs Nothing Labs

    Hi, I'm Rich Olson (nothinglabs.com). I sell cloud chambers for viewing radiation, make robots and dev software. I like Instructables with complete info ondoing cool stuff with cheap / common parts.

    Intro: Easy, Reversible Motor Control for Arduino (or any Microcontroller)This project uses just three main components to provide forward and reverse motor control. 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 $9Supports PWM for variable speed control

    Handles loads up to 5 ampsControlled using just two pins - "enable" and "direction"

    Limitations:Requires at least 7.5 volts to operateRelay is rated for "only" 100,000 cycles and may not be appropriate for some high vibration projectsDoesn'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 lik10 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 widelydocumented. 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 Relays And Transistors.

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/http://nothinglabs.com/http://member/nothinglabs/http://member/nothinglabs/
  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    3/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 1:Stuff You'll NeedAll 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 RelayRadio Shack Part: 275-249If purchasing online - try searching for "OMI-SH-212D"

    2 x TIP120 Darlington TransistorsRadio Shack Part: 276-2068

    2 x 220 Ohm ResistorsValues do not need to be exact.

    You'll also need:

    Soldering IronAnd solder - any gauge is fine.

    Hookup WireYou'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

    Step 2:Schematic and Theory of OperationThis circuit uses a DPDT (Double Pole Double Throw) relay to switch which direction the motor is turning.

    The motor is connected to both normally closed and normally open (in reverse) sides of the relay. This in effect reverses the wiring whenever the relay is turned on or

    Since the microcontroller can't quite produce enough current to drive the relay - a transistor (TIP120) is used to switch it on and off.

    The "Base" of the first TIP120 is the "Direction Pin" - turning it on and off switches the direction of the motor.

    A second TIP120 switches power to common on the relay. This is used to turn the motor on and off.

    The "Base" of the second TIP120 is the "Enable Pin" - turning it on causes the motor to actually run.

    The enable pin may be switched on and off very quickly for PWM (pulse width modulation) speed control.

    Both control pins are connected to the microcontroller via 220 Ohm resistors to limit current.

    The minimum voltage to drive this circuit is determined by the "pickup" voltage of the relay. This is listed as 9.6v - but I've found it to function properly as low as about7.5v.

    Don't worry if the schematic doesn't make total sense. We'll go through all the connections one-by-one.

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    4/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 3:Bridge NO and NC Pins (Part 1)Position the relay in front of you as shown in the picture.

    Use a piece of hookup wire and your soldering iron to connect the pins as shown.

    This connection bridges one of the Normally Open (NO) relay pins to one of the Normally Closed (NC) relay pins.

    Step 4:Bridge NO and NC Pins (Part 2)Again - use a piece of hookup wire and your soldering iron to connect the pins shown.

    This connection bridges the other Normally Open (NO) and Normally Closed (NC) relay pins.

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    5/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 5:Connect Coil Pin To Common PinOne last time - use a piece of hookup wire and your soldering iron to connect the pins shown.

    This connects one of the relay's Coil pins to one of its Common pins. Both of these pins will later be provided with positive voltage.

    Step 6:Connect TIP120 Collector to Relay Coil PinSolder the middle pin of one of the TIP120s to the relay pin on your lower right (as pictured).

    This connects the TIP120 Collector pin to the relay's other Coil pin.

    Step 7:Nudge TIP120 Into PositionCarefully push the TIP120 towards your left and against the relay as shown.

    This isn't just cosmetic - the TIP120 needs to be in this position for a connection we'll make later.

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    6/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 8:Connect Second TIP120 Collector to Relay CommonSolder the middle pin of the second TIP120 to the bottom pin second from the left on the relay (as pictured).

    This connects the second TIP120 Collector pin to one of the relay's Common pins.

    Step 9:Connect TIP120 EmittersPush the second TIP120 up against the relay's case.

    Bend the left-most pin of each TIP120 towards each other until they touch.

    Solder the pins together as pictured.

    This connects the Emitter pins of the two TIP120 transistors.

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    7/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 10:Connect ResistorsTrim the leads of two 220 Ohm resistors to about 1/4 inch using scissors.

    Solder a resistor to the end of the right-most pin of each TIP120 as pictured.

    These resistors are connected to the Base of the transistors. They limit current flow between the transistors and your microcontroller to safe levels.

    Step 11:Review ConnectionsCongratulations! You've completed the basic wiring - let's review how to hook things up.

    + PowerConnect this pin to your power source of 7.5v or higher.

    GNDThis pin needs to be connected to both ground of your power supply -and- ground on your microcontroller.

    EnableConnect this pin to a pin on your microcontroller. Turning on this pin turns on the motor.

    If you use a microcontroller pin with PWM - you can use it for variable speed control.

    DirectionConnect this pin to a pin on your microcontroller. Turning on or off this pin switches motor direction.

    Motor 1 and Motor 2These pins connect to your motor leads.

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    8/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Step 12:Hook It Up!Connect all leads as listed in the prior step using hookup wire and your soldering i ron.

    Be sure to connect the GND pin to both your power source, and your microcontroller.

    If you're using an Arduino - connect the Direction Pin to Arduino Pin 8 and the Enable Pin to Arduino Pin 9.

    Step 13:Upload the Code and TestPlace the code below in an Arduino sketch - and upload it.

    If you're not using an Arduino - review the code below to figure out what's going on. It's not rocket science.

    You should have a working motor controller!

    //pin 8 = direction//pin 9 = enable

    void setup() {pinMode(8, OUTPUT); //set direction pin as outputpinMode(9, OUTPUT); //set enable pin as output}

    void loop() {

    //start off going forward at 50% throttledigitalWrite(8, HIGH); //forwardanalogWrite(9,128); //50% PWMdelay(2000);

    //full speed ahead!digitalWrite(9, HIGH); //full speeddelay(2000);

    //and stop for a whiledigitalWrite(9, LOW); //turn enable pin off

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    9/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    delay(1000);

    //now lets go backwardsdigitalWrite(8, LOW); //backwardanalogWrite(9,128); //50% PWMdelay(2000);

    //and stop for a whiledigitalWrite(9, LOW); //turn enable pin offdelay(1000);

    }

    Step 14:NotesIf you're having problems with the controller refusing to reverse - it may be that your input voltage is too low.

    It should be possible to build a version of this driver that supports lower voltages by swapping out the relay with one having a lower "pickup" voltage. I chose the onefeatured in this project since Radio Shack stocked it.

    This project uses TIP120 "Darlington" transistors. These transistors are actually two transistors chained together into one. This gives them much higher "gain" - meanithey can use a very small current to switch a much larger current. A TIP120 on its own provides a super-simple way to do single-direction motor control.

    Both the relay and TIP120 are rated at 5 amps. If you plan on drawing more than a few amps continuously - you may want to add a heatsink (Radio Shack 276-1363) the "enable" transistor.

    Swapping out both the TIP120 and relay with higher-rated parts (readily available online) should let you build a much beefier version of this motor control fairly cheaply

    Have fun!

  • 8/10/2019 Super Easy Reversible Motor Control for Arduino

    10/10

    http://www.instructables.com/id/Super-Easy-Reversible-Motor-Control-for-Arduino-/

    Related Instructables

    Stepper Motor

    Moduleby carlyn

    Dual MotorDriver withArduino using aSN754410NEQuad Half H-

    Bridgeby

    ArduinoFun

    How To RadioControl DCMotors Cheaply

    by Al1970

    H-Bridge on a

    Breadboardby

    gzip

    Arduino R/CLawnmower

    (painted)by

    johndavid400

    Robot Platformincluding h-bridges from

    $10 R/C Carby

    whamodyne

    http://www.instructables.com/member/whamodyne/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Robot-Platform-including-h-bridges-from-10-RC-Ca/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Robot-Platform-including-h-bridges-from-10-RC-Ca/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Robot-Platform-including-h-bridges-from-10-RC-Ca/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Robot-Platform-including-h-bridges-from-10-RC-Ca/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Robot-Platform-including-h-bridges-from-10-RC-Ca/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/johndavid400/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-RC-Lawnmower/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-RC-Lawnmower/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-RC-Lawnmower/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Arduino-RC-Lawnmower/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/gzip/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/H-Bridge-on-a-Breadboard/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/H-Bridge-on-a-Breadboard/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/H-Bridge-on-a-Breadboard/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/Al1970/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-To-Radio-Control-DC-Motors-Cheaply/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-To-Radio-Control-DC-Motors-Cheaply/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-To-Radio-Control-DC-Motors-Cheaply/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-To-Radio-Control-DC-Motors-Cheaply/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/ArduinoFun/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Duel-Motor-Driver-with-Arduino-using-a-SN754410NE-/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/carlyn/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Stepper-Motor-Module/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Stepper-Motor-Module/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Stepper-Motor-Module/?utm_source=pdf&utm_campaign=related