Need some help getting started with VNH5019

I’m building an ROV and I am using the VNH5019 motor controllers to run 4 bilge pumps. As of right now I am just trying to get one motor to turn off and on and go forwards and backwards through a keyboard. I would eventually like to control all of the motors through the keyboard. I don’t know anything about coding and the example isn’t very help for some one who doesn’t know anything about coding. I set up an Led and I could turn if off and on by pressing 1 or 0.

Does anybody have some code I can look at to get an idea of where things go?

Here is what I have now but I’m pretty sure its all wrong.

Update- I got the on of the motors to go forward whe I press 1 and reverse when I press 0. I just need to figure out how to control it with my arrow keys.

#include "DualVNH5019MotorShield.h"

DualVNH5019MotorShield md;

int M1INA =3;
int M1INB =2;
int M1PWM =11;

void setup() 
// Create Serial Object

Serial.println("Dual VNH5019 Motor Shield");
pinMode(M1INA, OUTPUT);
pinMode(M1INB, OUTPUT);
pinMode(M1PWM, OUTPUT);


void loop()
//Have arduino to recieve input
while (Serial.available() == 0){delay(500);}

//Read the input
int val = - '0';

if(val == 1)
  Serial.println("Motor Forward");
  digitalWrite(M1INA, HIGH);
  digitalWrite(M1INB, LOW);

else if(val == 0)
Serial.println("Motor Reverse");

digitalWrite(M1INA, LOW);
digitalWrite(M1INB, HIGH);

  Serial.println("Invalid you Bitch!");  





What are you using to send serial commands to the microcontroller? What operating system are you using? The easiest way to do this depends on your development environment. If you are using Windows, AutoHotkey might be worth looking into. We have an application note that provides several examples using AutoHotkey scripts to capture key presses with some of our other products and pass them to the command line utilities for those products. I did some quick Google searches for AutoHotkey and it looks like there are some useful results about capturing the arrow keys on the keyboard and communicating with Arduinos over serial. I didn’t see any results that did both, but you might be able to put together several examples to make your own code.


Hey Nathan,

My Plan is to use with a usb to Ethernet extender or I have an Ethernet shield to send commands to the aurduino via Telnet.

My code as it sits now starts the motor forward if I press 1. If I press 0 the motor runs in reverse. I’m looking for a way to press 1 and have the motor run until I release the 1 key and vice versa with the 0 key. Basically I want use the keyboard as a momentary switch. If I press a key the motor will run forward until I let go. I’m not sure if this is even possible.

I do have have a couple of small sparkfun joysticks that I would like to use but I have no idea how where to start with writing the code to control the motor.

It seems like it should be possible, but it might require something like a custom program that runs on your computer and sends a start command to the Arduino over serial when a key on a keyboard is first pressed and a second stop command when the key is released.

It sounds like maybe you should spend some time looking into development environments for writing software that runs on your computer (as opposed to the Arduino code, which runs on the Arduino itself) and then work out a reliable communication scheme between your computer and the Arduino.