Using/Powering the VHN2SP30

Hello,

I ordered a VHN2SP30 MDO3A motor driver and would like to use it in conjunction with an Arduino UNO board. The Arduino is being powered by my computer through a USB cord. My understanding is that the cord provides 5V to the board. I have connected the Arduino 5V pin to the +5IN pin on the VHN2SP30 and the Arduino GND to the GND on the right of the VHN2SP30 +5IN pin. For testing purposes, I connected a 9V battery to the VIN and GND pins on the VHN2SP30 designated for the motors and I connected a small DC motor to the A and B connections to the right of the VIN and GND pins.

Now for my very noob question. How do I know the VHN2SP30 is on? No LEDs are lit on the driver and of course when I run my Arduino code, the motor does nothing. I am still very new to this level of electronics and I would greatly appreciate some help. Is it possible that I may have burnt the VHN2SP30 somehow?

Hello.

It is possible to damage the board by making incorrect connections, but I think it is more likely that you are just not using it right. For example, a 9 V battery is generally a very bad choice for high-current applications like driving a motor: they have low capacities and cannot deliver much current without experiencing a sharp drop in voltage. I suggest you disconnect your motors and instead use the motor indicator LEDs for feedback. I also suggest you effectively remove your Arduino sketch from the picture by hard-wiring the driver for, say, full speed forward. You can do this by connecting the PWM and InA pins to 5 V and the InB pin to ground while using 9V for VIN and supplying 5 V to the +5V (in) pin. You can use your Arduino’s 5 V output for this; if you do, don’t forget to make sure your Arduino and the motor driver share a common ground. If this gets a response from the driver, this would point to a problem with your software. If this doesn’t get a response, the driver might be damaged, or you might have a wiring problem. Please let me know what happens.

- Ben

Thank you so much! I wired everything like you suggested and the red led turned on.

I’m glad you were able to get the driver to do something. Does it work with your Arduino sketch yet (once again, I recommend you do initial testing with motors disconnected)? If you have trouble with your sketch, feel free to post it and I can take a look.

- Ben

My sketch still is not working properly with the motor drive. We are building an autonomous robot that uses 3 proximity sensors to control the motors. Ive provided my sketch below. Just like before, no LEDs turn on on the motor drive once i wire it into the arduino and I dont think the outputs from the sensors are taking any effect. I have only coded for the two sensors that directly control the movement of the motors. The third sensor will act as an interrupt. Please someone help me!

i just need an arduino sketch that can take the analog signal from two proximity sensors that effects the pwm output to the motor drive

int PWM_1 = 3;  // Motor 1 Control
int IN1_A = 4;
int IN1_B = 7;

int PWM_2 = 11; // Motor 2 Control
int IN2_A = 12;
int IN2_B = 13;

const int SNS_1 = A0; // Sensors
const int SNS_2 = A1;
const int SNS_3 = A3;

int sensorValue = 0;
int outputValue = 0;
int sensorValue1 = 0;
int outputValue1 = 0;
int sensorValue2 = 0;
int outputValue2 = 0;


void setup()
{
  Serial.begin(9600);
  pinMode(PWM_1, OUTPUT);
  pinMode(IN1_A, OUTPUT);
  pinMode(IN1_B, OUTPUT);
  pinMode(PWM_2, OUTPUT);
  pinMode(IN2_A, OUTPUT);
  pinMode(IN2_B, OUTPUT);
  pinMode(SNS_1, INPUT);
  pinMode(SNS_2, INPUT);
  pinMode(SNS_3, INPUT);
}

void loop(){
  int sensorValue = analogRead(SNS_1);
  int sensorValue1 = analogRead(SNS_2);
  int sensorValue2 = analogRead(SNS_3);
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
  outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
  Serial.println(sensorValue, DEC);
  Serial.println(sensorValue1, DEC);
  Serial.println(sensorValue2, DEC);
  
 if(outputValue <= 160, outputValue1 >= 90){ //Make the robot go left if to close to right
   digitalWrite(IN1_A, LOW);
   digitalWrite(IN1_B, LOW);
   analogWrite(PWM_1, 0);
   digitalWrite(IN2_A, HIGH);
   digitalWrite(IN2_B, LOW);
   analogWrite(PWM_2, 255);
 }
 else if(outputValue >= 90, outputValue1 <= 160){ // Make the robot go right if to close to left
   digitalWrite(IN1_A, HIGH);
   digitalWrite(IN1_B, LOW);
   analogWrite(PWM_1, 255);
   digitalWrite(IN2_A, LOW);
   digitalWrite(IN2_B, LOW);
   analogWrite(PWM_2, 0);
 }
 else{
   digitalWrite(IN1_A, HIGH); // Make the Robot go forward
   digitalWrite(IN1_B, LOW);
   analogWrite(PWM_1, 255);
   digitalWrite(IN2_A, HIGH);
   digitalWrite(IN2_B, LOW);
   analogWrite(PWM_2, 255);
 }
 
   
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  Serial.print("\t output = ");      
  Serial.println(outputValue); 
  Serial.print("sensor = " );                       
  Serial.print(sensorValue1);      
  Serial.print("\t output = ");      
  Serial.println(outputValue1);   
  Serial.print("sensor = " );                       
  Serial.print(sensorValue2);      
  Serial.print("\t output = ");      
  Serial.println(outputValue2);
}

Hello.

Can you first write a program that basically does what you did when you manually wired it instead of complicating the program with sensor readings?

- Ryan

here is the simple code. When I use the code below the red led on one side of the VHN2SP30 barely illuminates. The first digitalWrite under the loop is where I would like to use the PWM. I used the command analogWrite(PWM1, 255) to simulate the digitalWrite(PWM1, HIGH). When I do this, the red led does not illuminate at all, therefore I’m assuming I am using the PWM function incorrectly but I cant’t figure out how to use it correctly.

When I hardwire like Ben suggested, the red led illuminates brightly and when a motor is connected, it spins quickly. Is it dim when I connect it to the arduino because I am only using a 9V battery? The practice motor I am using is one of those very small DC motors from hobby stores

// This code is to emulate the Pololu VHN2SP30 being hard wired
// PWM and INa connected to 5V, INb connected to ground
// 5V supplied to motor drive from Arduino UNO board, both share common ground.
// 9V battery plugged into VIN

int PWM1 = 3;  //Connect to PWM 1 of VHN2SP30
int IN1_A = 4; // Connect to INa
int IN1_B = 7; // Connect to INb

void setup(){
  pinMode(PWM1, OUTPUT);
  pinMode(IN1_A, OUTPUT);  //Make pins outputs
  pinMode(IN1_B, OUTPUT);
}

void loop(){
  digitalWrite(PWM1, HIGH); // Max output through PWM (as if connected to 5V) 0 = no output 
                          // 255 = max output. Would like to use analogWrite(PWM1, 255) instead
  digitalWrite(IN1_A, HIGH); // INa on (as if connected to 5V)
  digitalWrite(IN1_B, LOW); // INb off (as if grounded)
}

Are you describing LED behavior with a motor connected? If so, can you disconnect the motor and just use the indicator LEDs?

When you say you’re using a 9V battery, do you mean something like this. If so, you should switch to a better power source as 9V batteries are not good for high-current applications like driving motors.

- Ben

That’s without a motor connected. once the motor is connected the light no longer illuminates. I do understand that the 9V battery does not have a high amperage, but the motor that i am testing the coding with is just like the one at the link below.

pololu.com/catalog/product/1117

It seems like there’s a good chance you have a power problem, so I don’t think it makes much sense trying to debug this further until you get a better power source.

When you say that your motor is “just like” our product #1117, do you mean that it has the same specs or just that it looks the same. If it’s the latter, you should note that the form factor of a motor is not a good indication of its specs, and small motors can still draw a lot of current, especially when starting at full speed from rest. For example, this motor looks the same as the #1117 motor, but it has a stall current of around 6 A at 9 V (compared to around 1.2 A stall current at 9 V for the #1117 motor).

- Ben