7
http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/ technology workshop living food play outside Arduino Modules - L298N Dual H-Bridge Motor Controller by Reichenstein7 on August 27, 2014 Table of Contents Arduino Modules - L298N Dual H-Bridge Motor Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: Arduino Modules - L298N Dual H-Bridge Motor Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: Getting to know your L298N Dual H-Bridge Motor Controller module: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: Wiring to an Arduino: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 3: Arduino Sketch Considerations: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 4: Arduino Sketch Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Arduino Modules L298N Dual H Bridge Motor Controll

Embed Size (px)

DESCRIPTION

Arduino Modules L298N Dual H Bridge Motor Controll

Citation preview

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    technology workshop living food play outside

    Arduino Modules - L298N Dual H-Bridge Motor Controllerby Reichenstein7 on August 27, 2014

    Table of Contents

    Arduino Modules - L298N Dual H-Bridge Motor Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Intro: Arduino Modules - L298N Dual H-Bridge Motor Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 1: Getting to know your L298N Dual H-Bridge Motor Controller module: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 2: Wiring to an Arduino: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 3: Arduino Sketch Considerations: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 4: Arduino Sketch Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    Intro: Arduino Modules - L298N Dual H-Bridge Motor ControllerQuick and simple start guide for using and exploring an L298N Dual H-Bridge Motor Controller module with an Arduino.

    The model in the example I am using is from Ebay.

    Materials needed:

    L298N Dual H-Bridge Motor Controller module (various models will work)Male to Female jumper wiresAn Arduino, any flavor.A DC power supply, 7-35vA motor that is the correct voltage for your power supply used.

    Step 1: Getting to know your L298N Dual H-Bridge Motor Controller module:Usage:

    H-Bridge's are typically used in controlling motors speed and direction, but can be used for other projects such as driving the brightness of certain lighting projects suchas high powered LED arrays.

    How it works:

    An H-Bridge is a circuit that can drive a current in either polarity and be controlled by *Pulse Width Modulation (PWM).* Pulse Width Modulation is a means in controlling the duration of an electronic pulse. In motors try to imagine the brush as a water wheel and electrons as a the flowingdroplets of water. The voltage would be the water flowing over the wheel at a constant rate, the more water flowing the higher the voltage. Motors are rated at certainvoltages and can be damaged if the voltage is applied to heavily or if it is dropped quickly to slow the motor down. Thus PWM. Take the water wheel analogy and think ofthe water hitting it in pulses but at a constant flow. The longer the pulses the faster the wheel will turn, the shorter the pulses, the slower the water wheel will turn. Motorswill last much longer and be more reliable if controlled through PWM.

    Pins:

    Out 1: Motor A lead outOut 2: Motor A lead outOut 3: Motor B lead outOut 4: Mo (Can actually be from 5v-35v, just marked as 12v)GND: Ground5v: 5v input (unnecessary if your power source is 7v-35v, if the power source is 7v-35v then it can act as a 5v out)EnA: Enables PWM signal for Motor A (Please see the "Arduino Sketch Considerations" section)In1: Enable Motor AIn2: Enable Motor AIn3: Enable Motor BIn4: Enable Motor BEnB: Enables PWM signal for Motor B (Please see the "Arduino Sketch Considerations" section)

    Specifications:

    Double H bridge Drive Chip: L298NLogical voltage: 5V Drive voltage: 5V-35VLogical current: 0-36mA Drive current: 2A (MAX single bridge)Max power: 25WDimensions: 43 x 43 x 26mmWeight: 26g

    *Built-in 5v power supply, when the driving voltage is 7v-35v

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    Step 2: Wiring to an Arduino:There are several different models of these L298N Dual H-Bridge Motor Controllers. The generic wiring schematic above should do the trick for most.

    Two things to mention;

    Make sure you have all of your grounds tied together; Arduino, Power source, and the Motor controller.The PWM Pins are unnecessary if you do not want to control PWM features.

    Step 3: Arduino Sketch Considerations:The Arduino code sketch is pretty straight forward. Since there isnt a library for the L298N Dual H-Bridge Motor Controller you just have to declare which pins thecontroller is hooked to.

    The int dir(number)Pin(letter) pins can be connected to any available digital pin you have available, as long as you declare the correct pin in your sketch. Thismakes the L298N Dual H-Bridge Motor Controller very versatile if your project is using a lot of Arduino pins.The int speedPin(letter) pins need to be connected to a PWM pin on the Arduino if you want to enable speed control through PWM.As a quick cheat I have included a list of PWM pins for the main two types of Arduino's I use:

    AT MEGA PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function.UNO PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

    Step 4: Arduino Sketch Example:This code example I wrote to allow a serial monitor program such as Putty to control the L298N Dual H-Bridge Motor Controller via a keyboard with key presses.

    Controls:

    Key .......... Motor

    1 ............... Motor 1 Forward

    2 ............... Motor 1 Stop

    3 ............... Motor 1 Reverse

    4 ............... Motor 2 Forward

    5 ............... Motor 2 Stop

    6 ............... Motor 2 Reverse

    Code:

    Fixed the formatting issues (12/29/2014):

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    Download the attached L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino

    Alternate Download: http://www.mediafire.com/download/z654e8at1b21d7e/L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino

    File Downloads

    L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino (2 KB)[NOTE: When saving, if you see .tmp as the file ext, rename it to 'L298N_Dual_H_Bridge_Keyboard_Control_Reichenstein7.ino']

    Related Instructables

    Dual H-Bridge -L298 BreakoutBoard -Homemade byBIGDOG1971

    Control DC andstepper motorswith L298N DualMotor ControllerModules andArduino bytronixlabs

    Toy to ObstacleAvoider byeberhard1

    Dual MotorDriver withArduino using aSN754410NEQuad Half H-Bridge byArduinoFun

    How to Controlany R/C car withan airplanetransmitter! byvkarpuram

    Getting StartedWith TheMC33932 DualMotor Shield byJayconSystems

    Advertisements

    Comments32 comments Add Comment

    Reichenstein7 says: Dec 29, 2014. 2:02 PM REPLYI have added a link to the .ino file via Mediafire for those who are still seeing formatting errors.

    vjoshi14 says: Apr 7, 2015. 9:22 AM REPLYPlease help, i am not able to run the DC motor with this h bridge. it has in1, in2, in3, in4, e-a, e-b, gnd, 5v, 12v on one side and 4 screw ports on the other.please tell me do I need to add a power supply on the ports too and also on which port should I add the motor to, and the most important thing this program isnot working for me.

    LeoZ1 says: Nov 2, 2014. 2:29 PM REPLYI just got my controller working! It's exactly the same model as the one in this tutorial, which was very helpful! But there's a trick to this model, just somethingI noticed. Instead of declaring a PWM speed control pin, I just left the jumpers on ENA and ENB on, because they automatically enable the Motor A and B.Then I just PWM'ed either IN pins on the controller. I found that I could still vary the speed of the motor this way, even with one less connection. Is this thecorrect way to go? I want to make sure that even if the motor seems to work, I'm not damaging anything or wasting a lot of energy in the process. Because Ihave noticed that the heat sink gets extremely hot. (I'm inputting around 14-16V).

    MadhusudanK says: Apr 5, 2015. 4:36 AM REPLYEven I want to know if this is the correct way or not, because I have only three PWM pins left and I need to control 3 DC geared motors with those.Please reply @ Reichenstein7

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    nimz says: Mar 16, 2015. 3:03 AM REPLYCan i use it run 4 dc motors?

    killercatfish says: Mar 12, 2015. 5:44 AM REPLYAny recommendation for a power supply? My students want to use this to run two dc motors on a car chasis. So smaller the better to fit on there.

    Thanks!

    Reichenstein7 says: Mar 14, 2015. 7:26 PM REPLYI have been using heavy 12v SLA batteries and wall-warts myself, but any DC source that ranges 7-35v should do the trick.

    tintinmovie says: Jan 18, 2015. 3:09 PM REPLYI made it and it works except the stop. I added a delay of 2 seconds but that did nothing. When I type 2(Stop) it will go forward or backwards depending onwhich one it is on. So if it is going forward it will go backwards and if it's going backward it will go forward. Can you help me with this problem?

    Reichenstein7 says: Mar 10, 2015. 8:35 PM REPLYThis is probably a wiring problem, I have had similar occur here in a botched install. Check the wires against the above diagram.

    AlexanderR2 says: Mar 2, 2015. 7:32 AM REPLYI have a quick question. When you mention "make sure the power source, arduino and motor driver grounds are tied together" Did you mean all of themsoldered into just one cable or..? I'm new to electronics, and i'm quite confused since I only see one ground connection in your diagram.Thanks in advance.

    AlexanderR2 says: Mar 2, 2015. 7:35 AM REPLYIf its not what you meant, where would I connect the power source ground cable?

    Thanks, and sorry if its a stupid question. Im CS student, this is for a robotics investigation Im doing with arduino :)

    Reichenstein7 says: Mar 10, 2015. 8:32 PM REPLYYour question is not stupid. =)In most of these small projects you want to make sure all of the grounds are connected together otherwise anomalies may occur (motors stuttering,intermittent brownouts, etc). There are instances where you would want grounds to be isolated, but not here.What I mean by the above is make sure the ground for the battery or power source, the motor controller and Arduino are all connected together toensure the desired output works reliably.

    inese.eglava says: Mar 4, 2015. 10:28 AM REPLYMy Arduino didn't change speed through PWM with direct connection. I put 2k resistor between ENA (ENB) and Arduino Output pins 9 (10).

    8401288342 says: Feb 16, 2015. 11:40 PM REPLYWhat is the maximum delivered voltage and current at the Motor end.

    TahirK says: Jan 9, 2015. 11:50 PM REPLYCan i use this controller with servo motor voltage regulator? means if voltage down that 12v then motor rounding on clock vise and if voltage up than 12vthen motor rounding anti clock vise.

    AbdulM5 says: Dec 30, 2014. 6:10 AM REPLYif i am using pwm, so do i have to remove jumper from enable pins. Also which pin should be connected to arduino then.

    Reichenstein7 says: Dec 30, 2014. 10:01 AM REPLYIf you want to control the motor speed via PWM, you will have to pull the jumpers off of the 2 ENA pins. Each of these should be connected to a PWMcapable pin on the Arduino. The 3rd picture in this Instructable shows a wiring diagram.

    -----

    As a quick cheat I have included a list of PWM pins for the main two types of Arduino's I use:

    AT MEGA PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite() function.UNO PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    Vova.Kuzmenkov0 says: Nov 21, 2014. 6:49 AM REPLYHey Reichenstein7!

    There is an error in your sketch: you've missed initialisation of serial port in void setup() {..} sectionPlease add the following:

    void setup() {...*your initialisations here*

    Serial.begin(9600);Serial.println("Enter Number 1 to 6 to control the motor");}Then the code will work! You'll be able to control motors via serial monitor.

    All in all your guide was a great help to me! thanks!

    Regards,

    Vova

    Reichenstein7 says: Nov 21, 2014. 8:03 AM REPLYI will take a look at the code this afternoon, sometime things get missed in the copy + paste of things, but I know the code I have added to my repoworks.

    Reichenstein7 says: Nov 26, 2014. 10:53 AM REPLYOkay, so a little late checking up on this. Apparently this site is really bad for putting this code on. If you click the link and open the code in awebpage, characters are lost or incorrect.

    If you click the link and save it, The files name and all formatting is lost. There also seem to be a few characters that cannot be saved and show upas boxes.

    I used to post code at the end of the Instructable, but had similar bad results.

    Anybody have a better way of sharing code on this site or should I start linking it to somewhere like Mediafire?

    quadro123 says: Nov 13, 2014. 10:21 AM REPLYWhen i wanna to control 24V dc module, jumper near left capacitor need to be pocked in? Or take it out? Also when i Connect 24V power supply, do i reallyneed to connect 5V from arduino uno?

    vsharma23 says: Oct 10, 2014. 1:13 AM REPLYI m new in Arduino and i mtrying to make robot . I m using this motor controler can you plz help me how to connect it with arduino and dc motor.??

    plz reply..

    Reichenstein7 says: Oct 11, 2014. 6:30 AM REPLYSure, I use this model in a few of my other projects. I will try to publish a writeup in the next couple of days. Feel free to follow me, I am in the middle ofpublishing instructions for a variety of Arduino compatible sensors and controllers.

  • http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/

    vsharma23 says: Oct 11, 2014. 8:53 PM REPLYok thanks.

    Reichenstein7 says: Nov 5, 2014. 6:19 AM REPLYI realized a few days ago that I have used this controller in another instructables. Take a look here:

    http://www.instructables.com/id/Project-Launch-Platform-Robot-Part-1-The-Head/

    yakeen4u says: Sep 16, 2014. 6:31 PM REPLYthis project include joystick?

    Reichenstein7 says: Sep 17, 2014. 5:36 AM REPLYThis is a really quick sketch that shows how to call the features of this module. My sketch only includes keyboard control, but can easily adapted to ajoystick.* ( Depending upon the type of joystick you use, you could remap the joystick with the keys from my sketch and that would work. However I would add toit to at least take advantage of the PWM [Variable speed]To change speed simply change the variable in " (speedPinA, 255) " and add it as another case. )

    rafael.duarte.752 says: Sep 6, 2014. 7:36 PM REPLYCan you share again the arduino sketch please?

    Thanks in advance

    Reichenstein7 says: Sep 6, 2014. 9:03 PM REPLYThe sketch is attached. The formatting gets all messed up if I paste it.

    carlos66ba says: Aug 28, 2014. 12:51 PM REPLYNice instructable. I have a question: do you know what is the maximum switching frequency that the L298N supports? Thanks!

    omnibot says: Aug 28, 2014. 10:57 PM REPLY40kHz commutation frequency according to the datasheet at http://www.sparkfun.com/datasheets/Components/General/L298N.pdf

    Arman5592 says: Aug 28, 2014. 11:04 AM REPLYGreat ! I wanted to buy one of these and I was confused with all the pins and how to connect to an arduino .