   if (inputString == "i")
   {
     isSerialControl = true;
+    initialSensorValue = analogRead(analogInPin);
   }
   else
   {

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // Value read from the potentiometer

double alphaSigned = 0;
String inputString = "";         // A string to hold incoming data
boolean stringComplete = false;  // Whether the string is complete
boolean isSerialControl = false; 

void setup()
{

  double sensorValueMax = 767;//1023
  double deadBand = 0.05; // Use to ensure zero speed. Should not be zero
  sensorValue = analogRead(analogInPin);
  
  // If the analog value is changed, it means that the user wants to take control manually
  // so fallback to manual control
  if (fabs(initialSensorValue-sensorValue)>10)
  {
    isSerialControl = false;
  }
  if (sensorValue < 10)
  { 
    // Motor is free to move to enable manual control
