Motor / Pot Driver Locking

I have a Arduino Uno and your Driver Dual Shield stacked with a pot connected on Ao
I’m using code below to turn on the motor when Newvalue is less than Prevalue. Using the serial monitor to send New values that would be either larger or smaller turning the motor on or off.

Driver gets locked in either on or off state, when next New value is sent using the monitor, am I missing something in the code.

Looking forward

#include "DualVNH5019MotorShield.h"

DualVNH5019MotorShield md;

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

int j1;
int j2;
int PreVal; 

int NewVal;  // New Actuator Value 
int NewVal1; // New Actuator Value Thousandth 
int NewVal2; // New Actuator Value Hundredth
int NewVal3; // New Actuator Value Tenth
int NewVal4; // New Actuator Value 0nes
int NewVal5; // New Actuator Value 
int NewVal6; // New Actuator Value 

int potPin = 0;    // select the input pin for the potentiometer

void setup()
  Serial.println("Dual VNH5019 Motor Shield");


void loop()
 if (Serial.available() > 0) {
  j1 =;

 if (j1 == 'A'){ // Find by reading the New X Value pre curser A
  delay (11); // It seems to need a delay here  
           NewVal = int (; // Read NewX value character
           Serial.println(NewVal); // Prit NewX value character
           NewVal1 = int (;//Read NewX1 value character convert to integer
           NewVal2 = int (;//Read NewX2 value character convert to integer
           NewVal3 = int (;//Read NewX3 value character convert to integer
           NewVal4 = int (;//Read NewX4 value character convert to integer
          Serial.println(NewVal1); //Print NewX1 digit integer
          Serial.println(NewVal2); //Print NewX2 digit integer
          Serial.println(NewVal3); //Print NewX3 digit integer
          Serial.println(NewVal4); //Print NewX4 digit integer        
      NewVal = ((NewVal1*1000)+(NewVal2*100)+(NewVal3*10)+(NewVal4*1)); // Add NewX digits               
       PreVal = analogRead(potPin);    // Read actuator pot value OldX 
          Serial.println(PreVal);        // Print actuator pot value OldX
          Serial.println(NewVal);        // Print actuator pot value OldX 
      if (NewVal << PreVal)



It sounds like maybe you haven’t see our read before you post thread. It has some general suggestions that might help you troubleshoot your problem and get the most out of our support, so please read through that and then see my more specific questions below.

Which motor driver shield are you using? I see your code is for the VNH5019 shield, but you should explicitly include this kind of information in your post. What is your motor, and what is your power supply? Can you please reduce your code and system to the simplest thing that demonstrates the problem. For example, you should be able to remove all of the serial stuff (unless that is causing the problem, in which case you’ll be closer to understanding the problem when you start to pare down that part of the code). Can you get the problem to happen without the pot in the system?

Also, please provide a better description of what you are doing, what you expect to happen, and exactly what is happening. Saying “the driver gets locked in either the on or off state” is not all that helpful. (What does locked mean? What input are you providing? What determines if it “locks” on vs “locks” off?)

Finally, please use [ code ][ /code ] tags (without spaces) when posting your code. I have edited your post to add them.

- Ben