0

I have a small L298N module which I would like to use to run a couple of dc motors. The module I have is smaller than most of the ones you see on eBay, it looks like this... enter image description here I am trying to use the following library : https://github.com/AndreaLombardo/L298N

I have managed to get the motor going forwards and backwards, but the problem is, this module doesn't have a pin for enable ( EN for PWM from the Arduino) and the library seems to require this; therefore I can't control the speed of the motors.

Does anyone have any experience with these modules? Is there a different technique I should be using? Is there another library that works with these kind of modules?

All help appreciated.

1

PWM is used to control the duty cycle and not the voltage directly so your PWM will work directly on the input pins of motor driver and you will be able to control the speed. just use analogWrite on the input pin which was held HIGH and HOLD the other pin to LOW. If you desire to change the direction while simultaneously controlling the speed. just analogWrite both the pins. Just keep in mind that the duty cycle of both the pins should not be tweaked simultaneously. while the speed is being controlled in one direction the other pin should be at analogWrite(other,0).

  • Thanks very much for the answer. Do you know of any libraries that will handle the pin writing such that I can just send an int for speed / direction? ( similar to the other library I referenced ). Or do you have some example code of how to set the speed manually? – juliusbangert Jan 24 '18 at 22:47
0

you can use this snippet in your code if you want

void Loop()
{
   //this is basically to demostrate how you can control the speed
   // and direction simultaneously
   for(i=0;i<256;i+=51)
   {
      analogWrite(motorForwardPin,i);
      analogWrite(motorBackwardPin,0);
      delay(2000);
   }
   for(i=0;i<256;i+=51)
   {
      analogWrite(motorForwardPin,0);
      analogWrite(motorBackwardPin,i);
      delay(2000);
   }
}
  • and it's better if you don't use a library for this purpose. – Sudhanshu Shivam Jan 26 '18 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.