Tutorial for Monster Motor Shield VNH2SP30

123K7637

Intro: Tutorial for Monster Motor Shield VNH2SP30

Description

VNH2SP30 is a full bridge motor driver intended for a wide range of automotive applications. The device incorporates a dual monolithic high side driver and two low side switches. The high side driver switch is designed using the STMicroelectronic’s well known and proven proprietary VIPower M0 technology which permits efficient integration on the same die of a true Power MOSFET with an intelligent signal/protection circuitary. The VIN and motor out are pitched for 5mm screw terminals, making it easy to connect larger gauge wires. INA and INB control the direction of each motor, and the PWM pins turns the motors on or off. For the VNH2SP30, the current sense (CS) pins will output approximately 0.13 volts per amp of output current.

Features

  • Voltage Range : 5.5V - 16V
  • Maximum Current rating : 30A
  • Practical Continuous Current: 14 A
  • Current sense output proportional to motor current
  • MOSFET on-resistance: 19 mΩ (per leg)
  • Maximum PWM frequency: 20 kHz
  • Thermal Shutdown
  • Undervoltage and Overvoltage shutdown

STEP 1: Material Preparation

Before getting started, make sure to prepare all of below:

1. Arduino Uno Board and USB
2. Monster Motor Shield VNH2SP30
3. 2 DC Motor 12V
4. Jumper Wires / Crocodile Clip
5. Adapter / Battery (5.5V - 16V)

STEP 2: Pinout Details

Hardware Pinout

A0 : Enable pin for motor 1

A1 : Enable pin for motor 2

A2 : Current sensor for motor 1

A3 : Current sensor for motor 2

D7 : Clockwise (CW) for motor 1

D8 : Counterclockwise (CCW) for motor 1

D4 : Clockwise (CW) for motor 2

D9 : Counterclockwise (CCW) for motor 2

D5 : PWM for motor 1

D6 : PWM for motor 2

Truthtable to make motor to rotate :

Motor 0

STOP : D7 0, D8 0 & D7 1, D7 1
CCW : D7 0, D8 1
CW : D7 1, D8 0

Motor 1

STOP : D4 0, D9 0 & D4 1, D9 1
CCW : D4 0, D9 1
CW : D4 1, D9 0

STEP 3: Attach Your Monster Motor Shield VNH2SP30 to Arduino Uno Board

STEP 4: Connect DC Motor

Connect Motor 1 to VNH2SP30 Monster Motor Shield VNH2SP30 A1:B1 and Motor 2 to VNH2SP30 Monster Motor Shield A2:B2

STEP 5: Power Supply

Connect your Monster Motor Shield VNH2SP30 board to a power supply in range between 5.5V to 16V. We use a 9V power adapter.

STEP 6: Assembled Circuit

You will have the whole circuit like this after following previous step. Now, connect your Arduino Uno Board to your computer using the USB.

STEP 7: Sample Source Code

This is a sample source code for the circuit, you may download, open and and upload it into your Arduino Uno Board. Make sure to go Tools and select the correct board and port.

STEP 8: Serial Monitor

After you have finished compiling the sample source code into your arduino uno board, go to Tools > Serial Monitor and you will get a serial monitor as shown in the picture above.

STEP 9: Result

This is the result of this tutorial :

i. when user enter number '2', dc motor start to rotate forward and serial monitor will print forward.
ii. when user enter '3', dc motor start to reverse and serial monitor will print reverse.
iii. when user enter '1', dc motor stop from rotating and serial monitor will print stop.
iv. when user enter '+', dc motor's speed increase by 10 and serial monitor will print the motor's speed. However, dc motor maximum speed is 255, thus, when user enter '++' more it will still print 255 and never more than 255 (as shown in the pic).
v. when user enter '-', dc motor's speed decrease by 10 and serial monitor will print the motor's speed. However, dc motor minimum speed is 0, thus, when user enter '--' more it will still print 0 and never less than 0 (as shown in the pic).

STEP 10: Video


This video demonstration show how the DC motor function according to the sample source code.

20 Comments

i have also use your GREAT TUTORIAL, and those dc motors wroked great, one question,
if it is possible, how can i make the dc motors turn toa specific angle, like 30 degrees,
again, thanks for your tutorial and time, please stay healthy
I keep getting invalid option entered when i key in 2 to the serial monitor
You need to upload all arduino file not just ino. file. I cant open it.
here it is
// vnh2sp30 full
#define BRAKE 0

#define CW 1

#define CCW 2

#define CS_THRESHOLD 15 // Definition of safety current (Check: "1.3 Monster Shield Example").

//MOTOR 1

#define MOTOR_A1_PIN 7

#define MOTOR_B1_PIN 8

//MOTOR 2

#define MOTOR_A2_PIN 4

#define MOTOR_B2_PIN 9


#define PWM_MOTOR_1 5

#define PWM_MOTOR_2 6


#define CURRENT_SEN_1 A2

#define CURRENT_SEN_2 A3


#define EN_PIN_1 A0

#define EN_PIN_2 A1


#define MOTOR_1 0

#define MOTOR_2 1


short usSpeed = 150; //default motor speed

unsigned short usMotor_Status = BRAKE;


void setup()

{

pinMode(MOTOR_A1_PIN, OUTPUT);

pinMode(MOTOR_B1_PIN, OUTPUT);


pinMode(MOTOR_A2_PIN, OUTPUT);

pinMode(MOTOR_B2_PIN, OUTPUT);


pinMode(PWM_MOTOR_1, OUTPUT);

pinMode(PWM_MOTOR_2, OUTPUT);


pinMode(CURRENT_SEN_1, OUTPUT);

pinMode(CURRENT_SEN_2, OUTPUT);
pinMode(EN_PIN_1, OUTPUT);

pinMode(EN_PIN_2, OUTPUT);


Serial.begin(9600); // Initiates the serial to do the monitoring

Serial.println("Begin motor control");

Serial.println(); //Print function list for user selection

Serial.println("Enter number for control option:");

Serial.println("1. STOP");

Serial.println("2. FORWARD");

Serial.println("3. REVERSE");

Serial.println("4. READ CURRENT");

Serial.println("+. INCREASE SPEED");

Serial.println("-. DECREASE SPEED");

Serial.println();


}


void loop()

{

char user_input;

while(Serial.available())

{

user_input = Serial.read(); //Read user input and trigger appropriate function

digitalWrite(EN_PIN_1, HIGH);

digitalWrite(EN_PIN_2, HIGH);
if (user_input =='1') {
Stop(); }

else if(user_input =='2')
{ Forward(); }

else if(user_input =='3')
{
Reverse(); }

else if(user_input =='+') {
IncreaseSpeed(); }

else if(user_input =='-')
{
DecreaseSpeed();
}

else
{
Serial.println("Invalid option entered.");
}


}

}


void Stop()

{

Serial.println("Stop");

usMotor_Status = BRAKE;

motorGo(MOTOR_1, usMotor_Status, 0);

motorGo(MOTOR_2, usMotor_Status, 0);

}


void Forward()

{

Serial.println("Forward");

usMotor_Status = CW;

motorGo(MOTOR_1, usMotor_Status, usSpeed);

motorGo(MOTOR_2, usMotor_Status, usSpeed);

}


void Reverse()

{

Serial.println("Reverse");

usMotor_Status = CCW;

motorGo(MOTOR_1, usMotor_Status, usSpeed);

motorGo(MOTOR_2, usMotor_Status, usSpeed);

}


void IncreaseSpeed()

{

usSpeed = usSpeed + 10;

if(usSpeed > 255)
{
usSpeed = 255; }


Serial.print("Speed +: ");

Serial.println(usSpeed);


motorGo(MOTOR_1, usMotor_Status, usSpeed);

motorGo(MOTOR_2, usMotor_Status, usSpeed);

}


void DecreaseSpeed()

{

usSpeed = usSpeed - 10;

if(usSpeed < 0)
{
usSpeed = 0; }


Serial.print("Speed -: ");

Serial.println(usSpeed);


motorGo(MOTOR_1, usMotor_Status, usSpeed);

motorGo(MOTOR_2, usMotor_Status, usSpeed);

}


void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
//Function that controls the variables: motor(0 ou 1), direction (cw ou ccw) e pwm (entra 0 e 255);

{

if(motor == MOTOR_1)

{

if(direct == CW)

{

digitalWrite(MOTOR_A1_PIN, LOW);

digitalWrite(MOTOR_B1_PIN, HIGH);

}

else if(direct == CCW)
{ digitalWrite(MOTOR_A1_PIN, HIGH); digitalWrite(MOTOR_B1_PIN, LOW); }

else
{
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, LOW); }

analogWrite(PWM_MOTOR_1, pwm);

}

else if(motor == MOTOR_2)

{
if(direct == CW)
{ digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, HIGH);
}

else if(direct == CCW)
{
digitalWrite(MOTOR_A2_PIN, HIGH);
digitalWrite(MOTOR_B2_PIN, LOW); }

else
{
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, LOW); }


analogWrite(PWM_MOTOR_2, pwm);

}

}
Do you have to code for command 4 Current Sensing?
i use vnh2sp30 for driving LARGE servos that requires 14A
to move, so i do not have any particular requirement for
current sensing, so if you really want current sensing, well,
enjoy this, and be aware, if the current you intend to use is
less than 1A( like 150mA) you will not get much info+accuracy:
https://forum.pololu.com/t/vnh2sp30-current-sense-...
use this:
DualVNH5019MotorShield md(InA1,InB1,ENDIAG1,CS1,InA2,InB2,ENDIAG2,CS2);
and find+install: encoder .h + DualVNH5019MotorShield.h
then include these:
#include <Encoder.h>
#include <DualVNH5019MotorShield.h>
the code for sensing the current:
md.getM1CurrentMilliamps();

so my apology for boring you with this amount of detail,
let me know how it works for you, take care
surv

1. Why the enable pins are connected to analog pin while we are using them as digital pin.
2. What is the purpose of current sensing pin.
Nice tutorial.
But when i send '2', only one motor start. Now when i send '3', both motors start. I don't know what's wrong. :S
sabe alguien para que sirve cada una de las lineas de codigo utilizado en el puente H?
Can someone write me a code using VNH2SP30 with Pot to control the speed of the two motors? thanks
Hi
How I could measure the current , in the code it dosen't coding
I’ve got one of these motor drivers and I’m trying to get a source code for a remote control lawnmower I’m building (Arduino Uno R3 Vnh2sp30 full dual motor controller and flysky tx 6078 transmitter the motors are 24 volt 75A) anyone with knowledge where I could achieve this task or could write a code for me would be greatly appreciated
How can I use this to control Stepper motor?

is there any possibility to use switches and potentiometers for direction and speed, I'm new in Arduino and need it for a school project, already thx for any help

do you know how too connect the motor shield too an rc reciever

kind regards Tom Jensen

I connect Li-Po battery with 8V voltage value.

When D7 is HIGH and D8 is LOW there is 8V on A1-B1 pins. But when D7 is LOW and D8 is HIGH there is only 3V. And chip become very hot in a moment.

Whats wrong?

Hi. Thanks for this great tutorial. I am wondering that is there any significant voltage drop between input and output voltage of the driver module for one motor. I want to use this driver for high current applications. Thanks for your reply for now. Good job :D

NevzatT, the solid state part that implements the switch on this board has a very low series resistance (0.019 ohms when in the "on" state). This should allow you to predict how much voltage drop you would get from your high current application. Just multiply the current you are using by 0.019 and you will have the voltage drop. Be aware that the 30 amp rating of this switch is actually for peak, short duration, current flow like a starting current transient in a motor. If you were to run 30 amps continuously, you would cause about 17 watts of power to be dissipated in the switch, which would cause it to overheat and die given the amount of heat sinking is built into this little board. I would guess that you can get away with 5 to 10 amps steady state, but things would be getting quite warm at 10 amps (~2 watts dissipation in switch). I plan on using this for 4 amps steady state on some Peltier Coolers, so I should be OK.

Thanks a lot!

I am trying to connect my VNH2SP30 single motor board to WeMos D1.

But getting errors:

ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset

load 0x4010f000, len 1384, room 16

tail 8

chksum 0x2d

csum 0x2d

v180000ca

~ld

Went through many forums but no success.

Any idea?

Great tutorial. I do needed to interface this shield to an ESP8266 and this tutorial helped me to identify the pinout. Thanks!