Speed and direction control of dc motor using arduino and l298

Hello

I am trying to control both the speed and direction of dc motor using l298. Is speed control possible with l298?

Following is a snippet of my code

Counterclockwise:
digitalWrite(9,HIGH); //Enable
digitalWrite(5,HIGH);
digitalWrite(6,LOW);

Clockwise:
digitalWrite(9,HIGH); //Enable
digitalWrite(5,LOW);
digitalWrite(6,HIGH);

This works but the motor rotates at a constant speed!

To vary the speed, if I write analog values to pin 5 to move it counterclockwise, it is not working (I keep pin 6 LOW throughout)! Same thing is happening with pin 6!

Any input is appreciated. Thanks in advance.

It seems like your method should work. Perhaps you can try PWM to the ENABLE pin. - Scotty

Thanks scottyjr.

I took a different approach this time and problem is solved!

I am varying the time for which I keep the pins 5 and 6 HIGH. This is taking care of the variation in speed.

What sort of speeds are you able to get?

I tried this method using a delay to hold the pin high. The chip runs too fast for the motor, you have to slow it down. And if delay was a variable, you could control the speed. But I burned out my old shield as it did not have any back-emf protection. I have a new shield now but it is not hooked up yet.