Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Replacing l293d with Pololu Dual VNH5019

Hey, guys, I am currently using an l293d in my robot to drive to 2dc motors but now for my project, I need to use 2 12v motors with higher power consumption so obviously l293d can’t handle more than 1A so if I were to replace the l293d with Pololu Dual VNH5019 would I need to change the code or can I use the same code as below and also as for the schematic of this new motor driver I am confused about what is the use of M1/M2PWM pin on the motor driver?

#include <IRremote.h>

/*
   Left Motor
*/
// IN 1
#define LM_IN1    2
// IN 2
#define LM_IN2    4
/*
   Right Motor
*/
// IN 3
#define RM_IN3    5
// IN 4
#define RM_IN4    7


// IR receiver
# define RECV_PIN 10

IRrecv irrecv(RECV_PIN);

decode_results results;

//HEX codes for buttons
#define FWD       0xFD8877 // go forward
#define LFT       0xFD28D7 // go left
#define RGT       0xFD6897 // go right
#define BWD       0xFD9867 // go backward
#define STOP      0xFD30CF // stop
#define RESET     0xFD00FF // Resets the Arduino Board(RED)

unsigned long int value=0;

/*
 ************Arduino Reset Pin**************
 */
#define RESET_PIN A0

void setup() {
  
  // set mode of the pins as output
  for (int i = 2; i <= 7; i++) {
    pinMode(i, OUTPUT);
  }


  // start serial communication
  Serial.begin(9600);
  // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");

}

void loop() {
  if (irrecv.decode(&results)) {
    value = results.value;
    Serial.println(value, HEX);
    irrecv.resume(); // Receive the next value
    delay(200);
  }

  delay(100);
  check_Inst(value);
  value=0;
}

void check_Inst(long int value) {

  switch (value) {
    case FWD:
      go_Forward();
      break;
    case LFT:
      go_Left();
      break;
    case RGT:
      go_Right();
      break;
    case BWD:
      go_Backward();
      break;
    case STOP:
      go_Stop();
      break;
    case RESET:
      pinMode(RESET_PIN,OUTPUT);
      digitalWrite(RESET_PIN,HIGH);   
      break;  

    default:
      value = 0;
  }
}

void go_Forward() {
 
  movement_Inst_Fwd();
  delay(10);
}

void go_Left() {
   
  movement_Inst_Lft();
  delay(10);
}

void go_Right() {
  
  movement_Inst_Rgt();
  delay(10);
}

void go_Backward(){

  movement_Inst_Bwd();
  delay(10);
}  

void go_Stop(){
  
  movement_Inst_Stp();
  delay(10);
}  

/*
 * These movement instruction are repeated several times in the code
 */
void movement_Inst_Fwd(void){
  Serial.println("Going_Forward");
  
  // forward movement instructions
  digitalWrite(LM_IN1,HIGH);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,HIGH);
  digitalWrite(RM_IN4,LOW);   
  } 
  
void movement_Inst_Lft(void){
  Serial.println("Going_Left");
  
  // Left movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,HIGH);
  digitalWrite(RM_IN4,LOW);  
  delay(500);
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW);    
  delay(500);
  }
  
void movement_Inst_Rgt(void){
  Serial.println("Going_Right");  
  
  // Rgt movement instructions
  digitalWrite(LM_IN1,HIGH);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW); 
  delay(500);
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW); 
  delay(500);
    
  }
  
void movement_Inst_Bwd(void){
  Serial.println("Going_Backward"); 
    
  // Bwd movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,HIGH);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,HIGH);   
  }
  
void movement_Inst_Stp(void){  
  Serial.println("Stopping");    
  
  // Stp movement instructions
  digitalWrite(LM_IN1,LOW);
  digitalWrite(LM_IN2,LOW);
  digitalWrite(RM_IN3,LOW);
  digitalWrite(RM_IN4,LOW);  
  }

schematic

Hello, Dave.

The code you posted will not work with our Dual VNH5019 Motor Driver Shield without some modification. I recommend reading the shield’s user’s guide and the datasheet for the VNH5019 (both are available on the product page under the “Resources” tab) for getting a better understanding of how the board works and how it is different from the L293d, but at minimum you will need change which pins are declared as the motor inputs and set the PWM pins (which are generally used for speed control) high. The “Shield Connections” section of the board’s user’s guide shows the default pin mappings when it is used as an Arduino shield.

By the way, I also suggest checking out our Arduino library for the dual VNH5019 shield which might make it easier for you to write more advanced, concise, and elegant programs for using this driver.

- Patrick

After some reading i realised the pwm pin acts the same way as the enable pin on l293d, therefore could I just connect the 2 pwm pins of Dual VNH5019 Motor Driver Shield with 5v pin on arduino…considering I am not trying to control the speed and just want to achieve the same use!

That would be an okay approach. If you decide to do that, I suggest cutting the connection between the driver PWM pins and the Arduino I/O pins they are connected to by default as suggested in the “Remapping the Arduino Connections” section of the user’s guide. That way you will free up those pins and you are less likely to damage something (such as by accidentally driving one of those pins low creating a short).

- Patrick

Do I have to cut the connection? Instead of using it as a shield, I can just use jumper wires to connect different Arduino pins to the necessary pins on the left side of the motor driver!

You do not need to cut any traces if you use jumpers to connect to the pins on the left side of the board as described in the “Using as a General-Purpose Motor Driver” section of the user’s guide.

If you still want to use the board as a shield, you do not have to cut the PWM pin traces unless you want to use those pins on your Arduino for something else, but please be careful not to accidentally drive those pins in your code. If you just configure them as inputs at the beginning of your program and do not do anything else with them you should be fine.

- Patrick