How To Mechatronics Tutorials - Arduino DC Motor Control L298N PWM H Bridge

May 8, 2024 | Author: Anonymous | Category: N/A
Share Embed Donate


Short Description

Download How To Mechatronics Tutorials - Arduino DC Motor Control L298N PWM H Bridge...

Description

HOME

ARDUINO

TUTORIALS

PROJECTS WHAT'S NEW?

PROJECTS

WORKS FOLLOW ME

Tutorials



  

ON:

HOW BRUSHLESS MOTOR AND ESC WORK





LEARN

DIY ARDUINO BASED RC HOVERCRAFT

 Home

HOW IT

Arduino Tutorials

L AT E S T

ARDUINO BRUSHLESS MOTOR CONTROL TUTORIAL | ESC … | BLDC

Arduino DC Motor Control Tutorial – L298N | DIY ARDUINO RC TRANSMITTER

PWM | H-Bridge  Arduino  Dejan Tutorials

 53

DIY ARDUINO ROBOT ARM WITH

DIY ARDUINO BASED RC

SMARTPHONE CONTROL

HOVERCRAFT

 Dejan  53

In this Arduino Tutorial we will learn how to control DC motors using Arduino. We well take a look at some basic techniques for controlling DC motors and make two example through which we will learn how to control DC motors using the L298N driver and the Arduino board.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

 Dejan

HOW B

Coding Tutorials Arduino Projects Electrical Relay CNC Controller

Overview We can control the speed of the DC motor by simply controlling the input voltage to the motor and the most common method of doing that is by using PWM signal.

PWM DC Motor Control Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

POPULAR

PWM, or pulse width modulation is a technique which allows us to adjust the Ultrasonic Sensor HC-

average value of the voltage that’s going to the electronic device by turning on

SR04 and Arduino

and off the power at a fast rate. The average voltage depends on the duty cycle,

Tutorial

or the amount of time the signal is ON versus the amount of time the signal is

 Dejan  92

OFF in a single period of time.

Arduino and HC-05 Bluetooth Module Tutorial Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

 Dejan  33

So depending on the size of the motor, we can simply connect an Arduino PWM output to the base of transistor or the gate of a MOSFET and control the speed of the motor by controlling the PWM output. The low power Arduino PWM signal switches on and off the gate at the MOSFET through which the high power motor is driven.

Note: Arduino GND and the motor power supply GND should be connected together.

H-Bridge DC Motor Control On the other hand, for controlling the rotation direction, we just need to inverse the direction of the current flow through the motor, and the most common method of doing that is by using an H-Bridge. An H-Bridge circuit contains four switching elements, transistors or MOSFETs, with the motor at the center forming Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Arduino TFT LCD Touch Screen Tutorial  Dejan  160

an H-like configuration. By activating two particular switches at the same time we can change the direction of the current flow, thus change the rotation direction of the motor.

So if we combine these two methods, the PWM and the H-Bridge, we can have a complete control over the DC motor. There are many DC motor drivers that have Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

F O L LO W M E !

these features and the L298N is one of them.

Join My Newsletter!

FANTASTIC!

1.000.000th visitor! This is not a joke! ONLINE: 8/03/2019 20:47:26 Our random winners selection system could choose you to win a £500 ASDA.

Get notified when I publish new projects and tutorials straight to your inbox. Enter you email SUBSCRIBE

CLICK HERE

©Aldaniti

How To Mechatronics 22,852 likes

L298N Driver The L298N is a dual H-Bridge motor driver which allows speed and direction

Like Page

Share

control of two DC motors at the same time. The module can drive DC motors that have voltages between 5 and 35V, with a peak current up to 2A.

C R E AT I V I T Y H E R O PROJECT

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Push In Din Rail Terminals Conta Clip Screw-less PRK New From Conta Clip, PRK Push In, Screw-less Din Rail Terminals.

news.demesne.ie

Let’s take a closer look at the pinout of L298N module and explain how it works. The module has two screw terminal blocks for the motor A and B, and another screw terminal block for the Ground pin, the VCC for motor and a 5V pin which can either be an input or output.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

OPEN

This depends on the voltage used at the motors VCC. The module have an onboard 5V regulator which is either enabled or disabled using a jumper. If the motor supply voltage is up to 12V we can enable the 5V regulator and the 5V pin can be used as output, for example for powering our Arduino board. But if the motor voltage is greater than 12V we must disconnect the jumper because those voltages will cause damage to the onboard 5V regulator. In this case the 5V pin will be used as input as we need connect it to a 5V power supply in order the IC to work properly. We can note here that this IC makes a voltage drop of about 2V. So for example, if we use a 12V power supply, the voltage at motors terminals will be about 10V, which means that we won’t be able to get the maximum speed out of our 12V DC motor.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Next are the logic control inputs. The Enable A and Enable B pins are used for enabling and controlling the speed of the motor. If a jumper is present on this pin, the motor will be enabled and work at maximum speed, and if we remove the jumper we can connect a PWM input to this pin and in that way control the speed of the motor. If we connect this pin to a Ground the motor will be disabled.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Next, the Input 1 and Input 2 pins are used for controlling the rotation direction of the motor A, and the inputs 3 and 4 for the motor B. Using these pins we actually control the switches of the H-Bridge inside the L298N IC. If input 1 is LOW and input 2 is HIGH the motor will move forward, and vice versa, if input 1 is HIGH and input 2 is LOW the motor will move backward. In case both inputs are same, either LOW or HIGH the motor will stop. The same applies for the inputs 3 and 4 and the motor B. See Also

Arduino Brushless Motor Control Tutorial | ESC | BLDC

Arduino and L298N Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Now let’s make some practical applications. In the first example we will control the speed of the motor using a potentiometer and change the rotation direction using a push button. Here’s the circuit schematics.

So we need an L298N driver, a DC motor, a potentiometer, a push button and an Arduino board. You can get the components needed for this Arduino Tutorial from the links below: L298N Driver ……………………………….. Amazon / Banggood 12V High Torque DC Motor ………….. Amazon / Banggood DC Motor w/ Plastic Tire Wheel ……. Amazon / Banggood Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Arduino Board ……………………………… Amazon / Banggood Breadboard and Jump Wires ………… Amazon / Banggood *Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Arduino Code Here’s the Arduino code:

1.

/*

Arduino DC Motor Control - PWM | H-Bridge | L298N

-

Example 01

2.

by Dejan Nedelkovski, www.HowToMechatronics.com

3. 4.

*/

5. 6. 7. 8. 9.

#define #define #define #define

enA 9 in1 6 in2 7 button 4

10. 11. 12.

int rotDirection = 0; int pressed = false;

13. 14. 15. 16. 17. 18. 19. 20. 21. 22.

void setup() { pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(button, INPUT); // Set initial rotation direction digitalWrite(in1, LOW); digitalWrite(in2, HIGH); }

23. 24. 25. 26.

void loop() { int potValue = analogRead(A0); // Read potentiometer value int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255 Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

27.

value from 0 to 255 analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin

28.

// Read button - Debounce if (digitalRead(button) == true) { pressed = !pressed; } while (digitalRead(button) == true); delay(20);

29. 30. 31. 32. 33. 34. 35.

// If button is pressed - change rotation direction if (pressed == true & rotDirection == 0) { digitalWrite(in1, HIGH); digitalWrite(in2, LOW); rotDirection = 1; delay(20); }

36. 37. 38. 39. 40. 41. 42.

// If button is pressed - change rotation direction if (pressed == false & rotDirection == 1) { digitalWrite(in1, LOW); digitalWrite(in2, HIGH); rotDirection = 0; delay(20); }

43. 44. 45. 46. 47. 48. 49. 50.

}

Description: So first we need to define the pins and some variables needed for the program. In the setup section we need to set the pin modes and the initial rotation direction of the motor. In the loop section we start by reading the potentiometer value and then map the value that we get from it which is from 0 to 1023, to a value from 0 to 255 for the PWM signal, or that’s 0 to 100% duty cycle of the PWM signal. Then using the analogWrite() function we send the PWM signal to the Enable pin of the L298N board, which actually drives the motor. Next, we check whether we have pressed the button, and if that’s true, we will change the rotation direction of the motor by setting the Input 1 and Input 2 Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

states inversely. The push button will work as toggle button and each time we press it, it will change the rotation direction of the motor. SPONSORED SEARCHES

Electronic Circuit Programming Code

Arduino Robot Car Control using L298N Driver So once we have learned this, now we can build our own Arduino robot car. Here’s the circuit schematic:

All we need is 2 DC Motors, the L298N driver, an Arduino board and a joystick for Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

the control. As for the power supply, I chose to use three 3.7V Li-ion batteries, providing total of 11V. I made the chassis out of 3 mm tick plywood, attached the motors to it using metal brackets, attached wheels to the motors and in front attached a swivel wheel.

Now let’s take a look at the Arduino code and see how it works. (Down below you can find the complete code)

1. 2.

int xAxis = analogRead(A0); // Read Joysticks X-axis int yAxis = analogRead(A1); // Read Joysticks Y-axis

After defining the pins, in the loop section, we start with reading the joystick X and Y axis values. The joystick is actually made of two potentiometers which are Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

connected to the analog inputs of the Arduino and they have values from 0 to 1023. When the joystick stays in its center position the value of both potentiometers, or axes is around 512.

We will add a little tolerance and consider the values from 470 to 550 as center. So if we move the Y axis of joystick backward and the value goes below 470 we will set the two motors rotation direction to backward using the four input pins. Then, we will convert the declining values from 470 to 0 into increasing PWM Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

values from 0 to 255 which is actually the speed of the motor.

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.

// Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); }

Similar, if we move the Y axis of the joystick forward and the value goes above 550 we will set the motors to move forward and convert the readings from 550 to 1023 into PWM values from 0 to 255. If the joystick stays in its center the motors speed will be zero. Next, let’s see how we use the X axis for the left and right control of the car.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.

// X-axis used for left and right control if (xAxis < 470) { // Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } }

So again, first we need to convert the X axis readings into speed values from 0 to 255. For moving left, we use this value to decrease the left motor speed and increase the right motor speed. Here, because of the arithmetic functions we use two additional “if” statements to confine the range of the motor speed from 0 to Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

255.

The same method is used for moving the car to the right. Depending on the applied voltage and the motor itself, at lower speeds the motor is not able to start moving and it produces a buzzing sound. In my case, the motors were not able to move if the value of the PWM signal was below 70. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Therefore using this two if statements I actually confined to speed range from 70 to 255. At the end we just send the final motor speeds or PWM signal to the enable pins of the L298N driver.

1. 2. 3. 4. 5. 6. 7. 8. 9.

// Prevent buzzing at low speeds (Adjust according to your motors. My motors couldn't start moving if PWM value was below value of 70) if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor A analogWrite(enB, motorSpeedB); // Send PWM signal to motor B

Here’s the complete code of the Arduino robot car example:

1.

/*

2. 3. 4.

Arduino DC Motor Control - PWM | H-Bridge | L298N Example 02 - Arduino Robot Car Control by Dejan Nedelkovski, www.HowToMechatronics.com

*/

5. 6. 7. 8. 9. 10. 11.

#define #define #define #define #define #define

enA in1 in2 enB in3 in4

9 4 5 10 6 7

12. 13. 14.

int motorSpeedA = 0; int motorSpeedB = 0;

15. 16. 17. 18. 19. 20.

void setup() { pinMode(enA, pinMode(enB, pinMode(in1, pinMode(in2,

OUTPUT); OUTPUT); OUTPUT); OUTPUT);

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);

21. 22. 23.

}

24. 25. 26. 27.

void loop() { int xAxis = analogRead(A0); // Read Joysticks X-axis int yAxis = analogRead(A1); // Read Joysticks Y-axis

28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56.

// Y-axis used for forward and backward control if (yAxis < 470) { // Set Motor A backward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Set Motor B backward digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Convert the declining Y-axis readings for going backward from 470 to 0 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 470, 0, 0, 255); motorSpeedB = map(yAxis, 470, 0, 0, 255); } else if (yAxis > 550) { // Set Motor A forward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Set Motor B forward digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Convert the increasing Y-axis readings for going forward from 550 to 1023 into 0 to 255 value for the PWM signal for increasing the motor speed motorSpeedA = map(yAxis, 550, 1023, 0, 255); motorSpeedB = map(yAxis, 550, 1023, 0, 255); } // If joystick stays in middle the motors are not moving else { motorSpeedA = 0; motorSpeedB = 0; }

57. 58. 59.

// X-axis used for left and right control if (xAxis < 470) { Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96.

// Convert the declining X-axis readings from 470 to 0 into increasing 0 to 255 value int xMapped = map(xAxis, 470, 0, 0, 255); // Move to left - decrease left motor speed, increase right motor speed motorSpeedA = motorSpeedA - xMapped; motorSpeedB = motorSpeedB + xMapped; // Confine the range from 0 to 255 if (motorSpeedA < 0) { motorSpeedA = 0; } if (motorSpeedB > 255) { motorSpeedB = 255; } } if (xAxis > 550) { // Convert the increasing X-axis readings from 550 to 1023 into 0 to 255 value int xMapped = map(xAxis, 550, 1023, 0, 255); // Move right - decrease right motor speed, increase left motor speed motorSpeedA = motorSpeedA + xMapped; motorSpeedB = motorSpeedB - xMapped; // Confine the range from 0 to 255 if (motorSpeedA > 255) { motorSpeedA = 255; } if (motorSpeedB < 0) { motorSpeedB = 0; } } // Prevent buzzing at low speeds (Adjust according to your motors couldn't start moving if PWM value was below value of if (motorSpeedA < 70) { motorSpeedA = 0; } if (motorSpeedB < 70) { motorSpeedB = 0; } analogWrite(enA, motorSpeedA); // Send PWM signal to motor analogWrite(enB, motorSpeedB); // Send PWM signal to motor }

motors. My 70)

A B

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

So that would be all for this tutorial, and in my next video we will upgrade this Arduino robot car, by adding a Bluetooth and Radio devices for enabling smartphone and wireless control. Feel free to ask any question in the comments section below and don’t forget to check my collection of Arduino Projects.

JLCPCB - Prototype 10 PCBs for $2 + 2 days Lead Time China's Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw

DC Motor

Driver

H-Bridge

L298N

PWM

SHARE ON:

Share 216

Like 216

Save

39

R E L AT E D P O S T S

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

ARDUINO COLOR SENSING ARDUINO BRUSHLESS MOTOR

TUTORIAL – TCS230 TCS3200

CONTROL TUTORIAL | ESC | BLDC

COLOR SENSOR

 Dejan  2

 Dejan  38

HOW TO CONTROL WS2812B

8×8 LED MATRIX MAX7219

INDIVIDUALLY ADDRESSABLE LEDS

TUTORIAL WITH SCROLLING TEXT &

USING ARDUINO

ANDROID CONTROL VIA BLUETOOTH

 Dejan  19

 Dejan  34

53 RESPONSES

Talha Arif August 9, 2017 Very good tutorial sir please show how can we use 4 motors i-e., wheels with it which two motors will be in parallel also show wiring…, Thanks for this!!!

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

REPLY

victor November 25, 2017 that would be the same just wire multiple motors to the same connector REPLY

Adilson September 3, 2017 The first example you gave has some mistakes, and it won’t work if they are not fixed: 1. In the schematics: external power ground must be connected to arduino ground as well, not being isolated as you had indicated there. 2. Variables in1/in2 are OUTPUT not INPUT. 3. (not very important) You never use buttonState variable; it can be removed. Would you be kind enough to modify that example’s code/schematics? Thank you. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

REPLY

Dejan Nedelkovski September 11, 2017 Thanks for the kind remarks. I’ve updated them. REPLY

RCA October 28, 2018 L298D-Arduino ground shcematic was not shown on the Arduino and L298N in Fritzz scheme.I tried and motor just buzzed until I understood the ground connection is missing.Please modify it. Thanks for all these tutorials…Take it easyyy.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

shyam September 6, 2017 really helpful. Thanks for the information. REPLY

Petar Stojanovski November 5, 2017 This is a great project. I like it how everything is well explained, not just a plain code and schematics. Keep up the good work! REPLY

Dejan Nedelkovski November 10, 2017 Thanks! REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

hei November 25, 2017 I have to do a similar thing for a school project but i have to amplify arduino’s output voltage to 25V by implementing a external voltage source . Any ideas on how can I do that? REPLY

Dejan Nedelkovski November 26, 2017 You could use 12V adapter plus an LM2596 Buck Converter to convert the 12V to 24V. REPLY

Ranulfo de Oliveira e Silva December 13, 2017 Amigo você estar de parabéns pelo projeto. Só me confirma umas coisas. posso utilizar o arduino NANO ? Esses último código, é o programa final ? Ou tenho que juntar todos os outros a cima mencionado com esse último ? Obrigado, e valeu amigo. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Friend you be of congratulations by the project. Just confirm some things. can I use arduino NANO? Those last code, is the final program? Or do I have to join all the others mentioned above with the latter? Thanks, and thanks buddy. REPLY

Dejan Nedelkovski December 16, 2017 Yes, you can use NANO. The last code is the final, the other mentioned are just explanations, all of them are contained in the last final code. REPLY

Tirta January 24, 2018 Hi, Thank you for sharing this very useful tutorial. Can you help me with the code to give half of enA output (0~4.6V). I tried to change the code Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

“motorSpeedA = map(yAxis, 550, 1023, 0, 255);” to “motorSpeedA = map(yAxis, 550, 1023, 0, 120);” but, it looks like the range of the joystick a bit, so it hard to increasing the speed smoothly. I need the motor to work at the lowest speed of 1.4V and the maximum speed is 2.1v (about 78~120) REPLY

Dejan Nedelkovski January 29, 2018 Hey, if you are using a Joystick just like I did, you might have a problem for increasing the speed smoothly, the joysticks aren’t so good. You can try to use potentiometers instead of joystick, for smoother work. REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Sara February 12, 2018 This is an amazingly helpful website, thank you!! Really saving my butt on a design project for college. REPLY

Dejan Nedelkovski February 15, 2018 Thanks! REPLY

AbdulRahman Shakeel February 13, 2018 I have a few questions regarding this project, Dejan. You seem to have used Arduino UNO in the pictures, however in the link to Amazon, you have linked Arduino MEGA. Does it make a difference? Could any be used? And is the joystick also from Arduino? Could we use any joystick? Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Also, I would like to get a link of the wires you have used. I am doing this project and I just do not know how to get the exact components you have used. P.S, this project is amazing! Thanks a lot! REPLY

Dejan Nedelkovski February 15, 2018 You can use any Arduino board for this project. A different joystick should work as well. Those wires are so called jumper wires. REPLY

Kasalian February 21, 2018 This is a very nice project, I love it. But am facing little challenge. The H bridge motor controller am using does nits drive the motor unless I touch the MOSFET’s heat sink. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

I also try another H bridge still the same thing. Am using 12 volt adapter to power the H bridge. REPLY

Dejan Nedelkovski February 24, 2018 Try connecting the Arduino GND and the power adapter GND. REPLY

tetos March 9, 2018 can i use this IC l298 to drive a 220 V DC motor with PWM , or not ? thanks for help. REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Dejan Nedelkovski March 18, 2018 No, you can’t! REPLY

Nathan March 30, 2018 Thanks for the information , i woud like to ask , since the specs say 5v to 35v and max current of 2A, does that mean its possible to drive maybe a linear actuator that is 24 volts with a max current of 0.65A or 1.1A? if i power the H bridge with 24volts? REPLY

Dejan Nedelkovski April 4, 2018 Well according to the L298 driver datasheet of the total power dissipation is 25W. So yes, at 24 volts you could probably drive a a motor with around 1A.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

REPLY

Jay, June 16, 2018 Thanks for your work, really helpful. One question: To which pin do I need to connect the PWMSignal? I only seem to get an output if I connect both of the pins to the PWM-signal, which doesn’t make sense to me. Also, now I am in 12V, but I will need to connect a 24Vmotor for an other project. Just have to remove that Jumper above the Power input and power the L298 with an external 5V-supply, right? Where would the 5V be connected to GND? Thanks! REPLY

Dejan Nedelkovski June 19, 2018 Thanks. If using two motors then you need to use the two PWM pins because they are separate channels, A and B. In case you use 24V, then you must remove the Jumper for the 5V regulator, because the Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

24V are too much for that on-board regulator, but also now you need to connect a separate 5V power supply to the +5V pin on the driver in order the control to work. REPLY

Lukas August 8, 2018 On my module there is 78M05 LDO as a 5V regulator. According to the datasheet the input voltage is up to 35V. So the limitation is the power dissipation of the chip only. So why in voltage above 12V it is necessary to disconnect the regulator? Did I miss something?

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Dejan Nedelkovski August 9, 2018 No, you are right. The datasheet states that the 78M05 regulator can handle up to 35V input voltage.

Rick Ennis July 13, 2018 I like your tutorials very much. You explain things very well and I come away with real understanding. You always give me information that I can really use. Thank you! REPLY

Dejan Nedelkovski July 16, 2018 Thanks! REPLY Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

W. D. Gamni Perera August 7, 2018 Very good explanation, programs and excellent diagrams. W. D. Gamini Perera Galle Sri Lanka REPLY

Dejan Nedelkovski August 8, 2018 Thanks! REPLY

David August 16, 2018 What adjustments should I make if I am using a 24V power supply? Everything else I have is the same as your schematic. Will it damage the boards? Also, thanks for this helpful article. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

REPLY

Dejan Nedelkovski August 19, 2018 First you motor must be rated at 24V, then the on-board 5V regulator on your L298N module must be able to handle the 24V, so you can power your Arduino with 5V. REPLY

Nicholas reynolds August 31, 2018 What would recommend if I only need to drive a 1.5v dc motor? A lower voltage driver? REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Dejan September 1, 2018 Well it depends what kind of control you want to achieve. You saw here for controlling rotation direction you would need something like H-Bridge, or for controlling the speed you need a PWM signal. As for such a low voltage motor you could use a 1.5V battery for power and simply control a transistor, like shown in the first circuit. REPLY

Houssam September 6, 2018 Great article and well explained project, thank you for the deployed efforts. well I’ll be using a 24V DC with 4,5 A. as specified, the max current is 2A. therfore, How we can hundle this ? do you know any alternatives ? To obtain the 24 V we can use 12V adapter plus an LM2596 Buck Converter to convert the 12V to 24V. but how we can hundle the current ? thanks in advance. Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Houssam REPLY

Dejan September 8, 2018 Thanks. The L298N definitely won’t be able to handle that powerful motor. Maybe you should try building your own circuit for driving this motor with higher rated transistors or mosfets which would work in similar way with this driver. REPLY

Kelly October 8, 2018 Dejan, This is an amazing site and excellent project description. I’m using 2 SYREN controlllers to drive 2-24v motors. SYREN only requires 1 pin to control fwd vs. rev. So I’m only using “in1” and “in3” to control direction. Believe it works as coded however when I move the joystick to the left or the Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

right only one of the motors will rotate. Based on how the code is written I would expect motor A to rotate forward at the same time motor B would rotate backward for a left turn? However only the right motor will move forward when I move the joystick left and then only the left motor will move forward when I move the joystick to the right? Seems like the xmapped code is not working correctly? Any input here would help. thanks.. REPLY

Dejan October 8, 2018 Hey, thanks Kelly! Well if the joystick is move only right or left, that’s normal, the left or the right motor will move forward and the other motor will not move. I guess your question comes from the two lines where I add and subtract the values from the joystick.In the case of pure left or right movement, one of the PWM values will be negative, but that doesn’t mean the motor will rotate backward, it actually means nothing, no PWM signal. From the above example we can see that for that purpose, Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

for changing the rotation direction we actually use the In1 and In2 control pins of the L298N driver. I hope that was what you were trying to ask and understand. REPLY

Kelly October 14, 2018 Thanks so much for the reply. I’m actually not using the L298N drivers. Using SYREN controllers which only require 1 pin to control fwd and rev. So yes trying to understand what this code is actually doing; // Move to left – decrease left motor speed, increase right motor speed motorSpeedA = Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

motorSpeedA – xMapped; motorSpeedB = motorSpeedB + xMapped; when I read this I’m thinking the car has the ability to have a zero turning radius as one motor will accelerate forward while the other accelerates backward when moving the joystick left or right. I actually achieved this by doing the following; // right turn if (xAxis 550) { // Set Motor A backward digitalWrite(in1, LOW); // Set Motor B forward digitalWrite(in3, HIGH); // Convert the declining xaxis readings for going backward from 470 to 0 into 0 to 255 value for the Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

PWM signal for increasing the motor speed motorSpeedA = map(xAxis, 550, 1023, 0, 255); motorSpeedB = map(xAxis, 550, 1023, 0, 255); }

Matsobane October 29, 2018 Thank you — very much this was very helpful — you effort is much appreciated — @South Africa REPLY

Chatch December 28, 2018 Dejan, Excellence Job ! Thank you so much . It ‘s very useful for me. Do you have any Arduino and L298N control code for DC motors by using Remote Control like Flysky ? Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Thank so much from Thailand. REPLY

Dejan December 30, 2018 Thanks! I’m afraid I don’t have such a example code. REPLY

Edgardo Hernandez Meyer January 22, 2019 From Colombia, thank you very much for all this time dedicated to explain these issues. The quality of their videos and their explanations are insurmountable, I remain attentive to your channel. Edgardo Hernandez (Google translator) REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Eric January 27, 2019 looking forward to trying this out – this will be my first real arduino project after the “basics” (LED blink etc.). I’m looking to buy all the parts but stumbled when it came to the wheels – can you provide a link or two for where I could get them? I wouldn’t mind spending a little more for something that is good quality. still very new to all this but, as many others have said, I really appreciate the way you teach these projects! REPLY

Dejan February 4, 2019 Well the wheels I used where taken out from a toy car which happened to fit the motors shaft perfectly. You can use DC Motors that come with plastic tire wheel, I’ve just updated the post and included a link to them in the parts list section. REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Cesar February 1, 2019 What’s the resistor OHMs value that’s connected to the push button on the first diagram? REPLY

Dejan February 4, 2019 It can be anything from 1K to 100K ohms. REPLY

Cesar February 5, 2019 Great explanation!. On the second schematic (where you control the speed of the motor using a potentiometer and rotation using a button) can you tell the resistor ohms rating? Also how is arduino powered on the 5V connector? REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Walter Glover February 6, 2019 Connected the circuit for variable speed above. motor gets 11.5 volts with no change in speed. The direction can be changed so the push button works. The pot will vary the voltage to A0 from 0 to 5volts. Any advice greatly appreciated Walter REPLY

Dejan February 6, 2019 Well you should send PWM signal to the driver, make sure you have connected those pins to a PWM capable pins on Arduino. REPLY

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

L E AV E A R E P LY Your email address will not be published.

Comment

Name*

Email*

Website

SUBMIT Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

H O W T O M E C H AT R O N I C S

FOLLOW

DISCLOSURE

H O W T O M E C H AT R O N I C S HowToMechatronics is an

HowToMechatronics is a participant

education website in the area of

ON SOCIAL MEDIA

in the Amazon Services LLC

Mechanical, Electrical and

Associates Program, an affiliate

Computer Engineering. Tutorials,

advertising program designed to

Tips, Tricks, How It Works, Projects,

provide a means for sites to earn

Examples, Source Codes, Download

advertising fees by advertising and

files and much more can be found

linking to Amazon.com

here.

Copyright © 2019 HowToMechatronics.com. All rights reserved. Terms and Conditions | Privacy Policy

This website uses cookies to improve user experience. By using our website, you agree to our use of cookies.

Convertido de web en PDF a https://www.htmlapdf.com con el api html a pdf

Ok

Read more

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF