Changing speed with Pololu High-Power Motor Driver 36v20 CS

Hi everyone,

I’m currently using Pololu High-Power Motor Driver 36v20 CS for controlling a 24V DC motor using the following arduino code to move forward:

int Dir_MotorRIGHT =4; // Direction input
int PWMH_MotorRIGHT=3;
int PWML_MotorRIGHT=2;


int Dir_MotorLEFT =7; // Direction input
int PWML_MotorLEFT=6;
int PWMH_MotorLEFT=5;

//int motorPin = 11;  // Pulse width modulation input           


void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  //pinMode(pot, INPUT); 
  pinMode(Dir_MotorRIGHT, OUTPUT);
  pinMode(PWML_MotorRIGHT, OUTPUT);
  pinMode(PWMH_MotorRIGHT, OUTPUT);
  
  pinMode(Dir_MotorLEFT, OUTPUT);
  pinMode(PWML_MotorLEFT, OUTPUT);
  pinMode(PWMH_MotorLEFT, OUTPUT);
//  pinMode(motorPin, OUTPUT);

}

int RobotForward() {
  
  digitalWrite(Dir_MotorRIGHT, HIGH);
  digitalWrite(Dir_MotorLEFT, LOW);
  
  digitalWrite(PWML_MotorRIGHT, HIGH);
   digitalWrite(PWML_MotorLEFT, HIGH);
   
  digitalWrite(PWMH_MotorRIGHT, HIGH);
  digitalWrite(PWMH_MotorLEFT, HIGH);
  delay(100);
                                    }
 
void loop()                     // run over and over again
{
RobotForward();
}

Now, this moves the robot forward alright, but how do I set the robot to move faster or slower?

Thanks in advance for your time,
Antonio

Hello.

You need to generate a PWM signal to control motor speed. To do this, you could use Arduino’s analogWrite() function, instead of digitalWrite(). You can find a description of the different motor control modes, all of which use PWM, under the “Motor Control Options” section of that motor driver’s product page.

By the way, your code is currently set up to power your motors with a 100% duty cycle, so you will only be able to use PWM to get speeds slower than what you are currently getting.

-Jon

John many thanks for the clarification! I appreciate it!
Do you have a code example I could work with just to get started with?

Thanks for your time,
Antonio

Unfortunately, we do not have any example code specifically for using our High Power Motor Drivers with an Arduino. However, to get the motor spinning at different speeds you should be able to just replace the calls to digitalWrite() for PWMH in your program above with calls to analogWrite() instead.

-Jon