Go Down

Topic: (Sorted) L298N Speed Control Issue (Read 17985 times) previous topic - next topic

jack wp

Yes, I can see those jumpers. That is a product of the board, not the L298N IC. I suspect they wanted to allow full enable onboard. You want to do speed control, so, If I was to guess about that board, I would think you should disconnect the jumper, and apply your PWM to one of those pins. (Which one?). Look closely at the board. Can you tell which one goes to the IC, and which one goes to Vcc (or ground). Hook to the one that goes to the IC.  Disclaimer: If it blows up, don't hold me responsible!

CyberBob

Hi Jack

I don't have access to the board (or anything else) until tomorrow. I will try and dig out a link from where I based the wiring that I used. Thanks for your help and advice. I'll post the link and anything else that I can find tomorrow.

Thanks again

Rob

jack wp

Great Rob,
I will be anxious to see how this turns out.

Jack

muangau

I used the same board as yours to control a brushed motor (rc toy).
You need 3 wires:
- Remove the jumper at ENA (there are 2 pins) then connect a wire at ENA (next to IN1) to pin 9 (arduino) : this pin controls the speed of the motor.
- Connect IN1 to pin 10 (arduino) : this pin controls the direction
- Connect IN2 to pin 11 (arduino) : this pin controls the direction

Here is my code:

int dir1PinA = 10; // direction
int dir2PinA = 11; // direction
int speedPinA = 9;  // pin ENA on the motor shield

unsigned long time;
int speed;
int dir;

void setup ()
{
pinMode (dir1PinA, OUTPUT);
pinMode (dir2PinA, OUTPUT);
pinMode (speedPinA, OUTPUT); // SPEED A
}

void loop ()
{
analogWrite (speedPinA, 100); // change the number from 1-255 to get the speed you want
digitalWrite (dir1PinA, LOW); //  pin 10 Low, pin 11 High
digitalWrite (dir2PinA, HIGH); // change between LOW and HIGH 
delay(3000);  //  stop for 3 seconds so you can see which direction when motor starts again.
}

Hope this help.


CyberBob

Hi Jack and muangau. Thanks for the suggestions. I'm a bit reluctant to remove the jumper in case I blow something. I am getting the motor to go both ways with the present configuration; it's the speed that is an issue. I got the wiring/code from the internet at Babelduck Cybernetics but the link no longer works. Here it is: http://www.babelduck.com/l298n-dual-dc-motor-driver-control-module/

I also found more info on the board here:

http://www.oddwires.com/l298n-dual-h-bridge-dc-stepper-motor-controller-module-for-arduino/

muangau, can you assure me that your wiring won't blow my board or MC?


jack wp

Hi CyberBob,
We do not provide insurance. We answer questions to our best ability. Our answers may not always be perfect, so you have to take them with caution. We advise, you decide.
If you want to leave the jumper on the enable pin, and wire the board as you had it wired, it's your decision.

I think my work here is done.

Jack

CyberBob

Jack and muangau, I appreciate all of your advice and I have so far treaded with caution. I have since bitten the bullet and wired everthing up as in muangau's post. Nothing blew and the motor turned both ways; I am so grateful to both of you.

Just a couple of points about the original sketch from muangau:

The delay(3000); just keep the motor running for 3 seconds at the pre-determined parameters.
There' nothing in the sketch to reverse the motor

I've modified the sketch to get the motor to go both ways, with a pause at change-over:

Code: [Select]
/*
- Remove the jumper at ENA (there are 2 pins) then connect a wire at ENA (next to IN1) to pin 9 (arduino) : this pin controls the speed of the motor.
- Connect IN1 to pin 10 (arduino) : this pin controls the direction
- Connect IN2 to pin 11 (arduino) : this pin controls the direction
*/

int dir1PinA = 10; // direction
int dir2PinA = 11; // direction
int speedPinA = 9;  // pin ENA on the motor shield

unsigned long time;
int speed;
int dir;

void setup ()
{
  pinMode (dir1PinA, OUTPUT);
  pinMode (dir2PinA, OUTPUT);
  pinMode (speedPinA, OUTPUT); // SPEED A
}

void loop ()
{
  analogWrite (speedPinA, 70); // change the number from 1-255 to get the speed you want
  digitalWrite (dir1PinA, LOW); //  pin 10 Low, pin 11 High
  digitalWrite (dir2PinA, HIGH); // change between LOW and HIGH 
  delay(3000);  //  continue for 3 seconds

  analogWrite (speedPinA, 0);
  delay(3000);

  analogWrite (speedPinA, 70); // change the number from 1-255 to get the speed you want
  digitalWrite (dir1PinA, HIGH); //  pin 10 High, pin 11 Low
  digitalWrite (dir2PinA, LOW); // change between HIGH and LOW 
  delay(3000);  //  continue for 3 seconds

  analogWrite (speedPinA, 0);
  delay(3000);
}



Again thanls Jack and muangau

Rob

jack wp

Great Rob! Glad the issue is solved BTW, change your thread title to say
(SOLVED) L298N Speed Control Issue

Code looks good. One other thing you may want to try, vary the speed. Maybe look at code in the example "fade".

Good job all.

CyberBob


muangau

Sorry Rob, i did not write the whole program because I cut and copy part of my test program with a note about Low and High. I am glad that you worked it out.
Cheers
muangau


CyberBob

Hi muangau

I thought that I would post my modified code and explanations to help anyone who may have the same problem.

Thanks again muangau and Jack (I've 'applauded' you both, so your Karma score has gone up)

Rob

the_wanderer

I know this post is over a month old but I hope someone replies.  When you guys said to remove the jumper from ENA and wrap it with a wire to port 9 on the arduino, did you mean wrap both pins of ENA with a wire or just one of them, thanks.

jack wp

I believe it was determined that you have a connection on the board labled ENa. If so, then just pull the jumper from enable a (don't wrap any wires), and connect pin 9 of arduino to the ENa connection.

roboleo

speed range control codes & pin no for l298 n arduino

pan speed range control

tilt range control

dead spot ???????????????????? please provide me codes..

 i am using arduino uno+l298n+variable joystick working good

but i wanna control speed range using analog pins arduino


please provide me codes

roboleo

speed range control codes & pin no for l298 n arduino

pan speed range control

tilt range control

dead spot ???????????????????? please provide me codes..

i am using arduino uno+l298n+variable joystick working good

but i wanna control speed range using analog pins arduino


please provide me codes

Go Up