control continuous servo motor with LCD display

I’m currently doing a solar panel charger with LDR Sensor to track the maximum voltage etc measurement. i’m using labview interface to control the servo motor( one horizontal & one vertical ). my auto sensing mode code can work perfectly. but i wan to implement manual mode to self control the servo motor but i cant get any display on my measurement in arduino pro mini 328 5v 16Mhz in LCD. I’m not sure if i can combine auto control and manual control or i need to separate into two arduino code. anyone can guide me thanks. i posted the auto+manual mode in attachments, the manual mode can be control rotate left,right etc but i can’t get the display on my LCD.

// Auto sensing mode without manual control inside

    #include <LiquidCrystal.h>
    #include <Servo.h> 
    #include <Math.h>
    Servo myservo;
    Servo myservol;
    int pos=90;
    int posl=1500;
    int clockwise = 1555;
    int anticlockwise = 1445;
    int stopped = 1500;

    LiquidCrystal lcd(2, 4, 5, 6, 7, 8); 
    float sample1 = 0;
    float voltage = 0;
    float sample2 = 0;
    float val = 0;
    float actualval = 0;
    float amps = 0;

    float totamps= 0;
    float avgamps= 0;
    float amphr= 0; 
    float watt = 0 ; 
    float energy = 0; 
    int diff = 0;
    int SensitivityV = 30;
    int SensitivityH = 27;

    int tpl = 0; // top left
    int tpr = 0; // top right
    int dwl = 0; // down left
    int dwr = 0; //down right
    int avt = 0; // average top
    int avd = 0; // average down
    int avl = 0; // average left
    int avr = 0; // average right

    int Incoming=0;
    int DunMove=48;
    int MoveUp=50;
    int MoveDown=52;
    int TurnLeft=54;
    int TurnRight=56;
    int Auto1=47;
    int Auto2=49;
    int ManualA=49;
    int ManualB=51;
    int Display=58;

    void setup() 
    {
      Serial.begin(9600);
      pinMode(3,OUTPUT);
      digitalWrite(3,HIGH);  //set up the LCD's number of columns and rows
      lcd.begin(16, 2);
      myservo.attach(9);
      myservol.attach(10);
    }

    void loop()
    {
      if(Serial.available()<=0)  //check if no data received, this will be         executed
      {
       lcd.setCursor(1,0);   //set the cursor at 1st col and 1st row
       lcd.print("Power ");
       lcd.print("  ");
       lcd.print("Voltage"); 
       lcd.print("  ");
       lcd.setCursor(1,1);   //set the cursor at 1st col and 2nd row
       lcd.print("Energy  ");
       lcd.print("Current");
      }

        if(Serial.available()>0)   //check if data received, this will be         executed
      {
        Incoming = Serial.read();  //read the incoming data

       if((Incoming>Auto1)&&(Incoming<Auto2))    //check if auto mode is         selected, this will be executed
        {
          tpl = analogRead(A2);  //top left
          tpr = analogRead(A3);  //top right
          dwl = analogRead(A4);  //down left
          dwr = analogRead(A5);  //down right

          avt = (tpl + tpr) / 2;   //average value top
          avd = (dwl + dwr) / 2;  //average value down
          avl = (tpl + dwl) / 2;  //average value left
          avr = (tpr + dwr) / 2;  //average value right

          int dvert = abs(avt - avd);  //check the difference of up and down
          int dhoriz = abs(avl - avr); //check the difference of left and right

          if((avt > avd) && (dvert > SensitivityV))  //check if top value is         more than btm value and if difference is more than sensitivity
      {
          pos--;  //increase pos value
       } 

          if((avt < avd) && (dvert > SensitivityV))   //  check if btm value is more than top value and if difference is more than sensitivity
      {
          pos ++;  //decrease pos value
       }
          myservo.write(pos); //write value to servo

    if((avl > avr) && (dhoriz > SensitivityH))  //check if left value is more than right value and if difference is more than sensitivity
      {
  posl = clockwise;
  myservol.write(posl);// write value to servo
       }

  else if((avl < avr) && (dhoriz > SensitivityH))  //check if right value is more than left value and if difference is more than sensitivity
      {
          posl = anticlockwise;
          myservol.write(posl);  //write value to servo
        }

          else //if top is both not true this will be executed
      {
          posl = stopped;
          myservol.write(posl);  // write value to servo
      } 
    for(int i=0;i<150;i++)    // taking 150 samples from voltage divider with a         interval of 2sec and then average the samples data collected 
    {
    sample1=sample1+analogRead(A0);  //read the voltage from the divider circuit
    delay (2);
    }
    sample1=sample1/150;
    voltage=5*2*sample1/1023;   // taking 150 samples from sensors with a interval         of 2sec and then average the samples data collected
    for(int i=0;i<150;i++)
    {
    sample2+=analogRead(A1);  //read the current from sensor
    delay(2);
    }
    sample2=sample2/150;
    amps= (512-sample2)/1023*27.03;
    long milisec = millis();   //calculate time in milliseconds
    long time=milisec/1000;   //convert milliseconds to seconds

    totamps=totamps+amps;   //calculate total amps
    avgamps=totamps/time;   //average amps
    amphr=(avgamps*time)/3600;   // amp-hour
    watt =voltage*amps;   // power=voltage*current
    energy=(watt*time)/3600;   // Watt-sec is again convert to Watt-Hr by dividing         1hr(3600sec)



    lcd.setCursor(16,1);  // set the cursor outside the display count
    lcd.print(" ");  // print empty character

    //////////////////////////////////////////print power and energy to a         LCD//////////////////////////////////////////////// 
    lcd.setCursor(1,0);  // set the cursor at 1st col and 1st row
    lcd.print(watt);
    lcd.print("W ");
    lcd.print("  ");
    lcd.print(voltage);
    lcd.print("V ");
    lcd.setCursor(1,1);  // set the cursor at 1st col and 2nd row
    lcd.print(energy);
    lcd.print("WH  ");
    lcd.print(" ");
    lcd.print(amps);
    lcd.print("A ");



    char currentChar[10];
    String currentConvert;
    dtostrf(amps,1,2,currentChar);   //Convert number to string;
    currentConvert = String(currentChar);
    String currentString="C";   //represent Current, for easy searching in labview
    String currentShow;
    currentShow=currentString+currentConvert;  //combine number and char together in one string

    char voltageChar[10];
    String voltageConvert;
    dtostrf(voltage,1,2,voltageChar);   //Convert number to string;
    voltageConvert = String(voltageChar);
    String voltageString="V";    //represent Voltage, for easy searching in labview 
    String voltageShow;
    voltageShow=voltageString+voltageConvert;   //combine number and char together in one string

    char wattChar[10];
    String wattConvert;
    dtostrf(watt,1,2,wattChar);   //Convert number to string;
    wattConvert = String(wattChar);
    String wattString="P";   //represent Power, for easy searching in labview 
    String wattShow;
    wattShow=wattString+wattConvert;   //combine number and char together in one string

    char energyChar[10];
    String energyConvert;
    dtostrf(energy,1,2,energyChar);  //Convert number to string;
    energyConvert = String(energyChar);
    String energyString="E";   //represent Energy, for easy searching in labview
    String energyShow;
    energyShow=energyString+energyConvert;   //combine number and char together in one string

    Serial.println(currentShow);
    Serial.println(voltageShow);
    Serial.println(wattShow);
    Serial.println(energyShow);

    delay(1000);
        }
      }
    }

Solar_Charge_jiale.ino (9.44 KB)

but i can’t get the display on my LCD.

 LiquidCrystal lcd(2, 4, 5, 6, 7, 8);

Please checkYou used proper data line i recommend to do this

Use below code make ensure LCD working fine.

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 4, 5, 6, 7, 8); 
void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
  lcd.setCursor(0, 1);
  lcd.print(millis()/1000);
}

We need detail schematic with connection diagram to Understand coding part made correct as per hardware.

Please mention the Which part is autoMode & which part has ManualMode.I recommend Assign Digital Pin to change mode.

For Example

int Mode=1;
if(digitalRead(Mode)==HIGH)
{
// Automode
}
Else
{
// manual mode
}

hi, the LCD is working fine i tried the code already. Okay i put in comment already =). please check again ! thanks =)

Auto+manual code.ino (10 KB)

your code is incomplete please ue code code tag for posting your code. The code not even compile & open in IDE

#include <LiquidCrystal.h>
#include <Servo.h> 
#include <Math.h>

Servo myservo;
Servo myservol;

int pos=90;
int posl=1500;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 4, 5, 6, 7, 8);
float sample1 = 0;
float voltage = 0;
float sample2 = 0;
float val = 0;
float actualval = 0;
float amps = 0;

float totamps= 0;
float avgamps= 0;
float amphr= 0; 
float watt = 0 ; 
float energy = 0; 
int diff = 0;
int SensitivityV = 30;
int SensitivityH = 27;

int tpl = 0;
int tpr = 0;
int dwl = 0;
int dwr = 0;
int avt = 0;
int avd = 0;
int avl = 0;
int avr = 0;

int Incoming=0;
int DunMove=48;
int MoveUp=50;
int MoveDown=52;
int TurnLeft=54;
int TurnRight=56;
int Auto1=47;
int Auto2=49;
int ManualA=49;
int ManualB=51;
int Display=58;

int clockwise = 1555;
int anticlockwise = 1445;
int stopped = 1500;

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3

                       // outside leads to ground and +5V

int input = 0;           // variable to store the value read

void setup() {
  
  Serial.begin(9600);
  pinMode(3,OUTPUT);
  digitalWrite(3,HIGH);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  myservo.attach(9);
  myservol.attach(10);
 
 
}

void loop()
{

  input = analogRead(analogPin);    // read the input pin

  Serial.println(val);             // debug value

////////
  if(Serial.available()<=0)// check if no data received, this will be excuted
  { 
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("Power ");
  lcd.print("Voltage");
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print("Energy ");
  lcd.print("Current");
  lcd.setCursor(1,2);
  lcd.print("Vin");
  }
  if(Serial.available()>0)//check if data received, this will be excuted
  {
    Incoming = Serial.read();// read the incoming data
  if((Incoming>Auto1)&&(Incoming<Auto2))// check if auto mode is selected, this will be excuted
    {
  tpl = analogRead(A2); // top left
  tpr = analogRead(A3); // top right
  dwl = analogRead(A4); // down left
  dwr = analogRead(A5); // down right
  
  avt = (tpl + tpr) / 2; // average value top
  avd = (dwl + dwr) / 2; // average value down
  avl = (tpl + dwl) / 2; // average value left
  avr = (tpr + dwr) / 2; // average value right
  
  int dvert = abs(avt - avd); // check the diffirence of up and down
  int dhoriz = abs(avl - avr);// check the diffirence of left and rigt
    
    
    // Auto mode with LCD working!

  if((avt > avd) && (dvert > SensitivityV))// check if top value is more then btm value and if difference is more then sensitivity
  {
    pos--;// increase pos value
  }
  
  if((avt < avd) && (dvert > SensitivityV))// check if btm value is more then top value and if difference is more then sensitivity
  {
    pos ++;// decrease pos value
    }
    myservo.write(pos);// write value to servo
  
 if((avl > avr) && (dhoriz > SensitivityH))// check if left value is more then right value and if difference is more then sensitivity
  {
    posl = clockwise;
    myservol.write(posl);// write value to servo
  }
  
  else if((avl < avr) && (dhoriz > SensitivityH))// check if right value is more then left value and if difference is more then sensitivity
  {
    posl = anticlockwise;
    myservol.write(posl);// write value to servo
    }
   
  else// if top is both not true this will be excuted
  {
    posl = stopped;
    myservol.write(posl);// write value to servo
  }
  
  for(int i=0;i<150;i++)  
// taking 150 samples from voltage divider with a interval of 2sec and then average the samples data collected for(int i=0;i<150;i++)
{
sample1=sample1+analogRead(A0); //read the voltage from the divider circuit
delay (2);
}
sample1=sample1/150;
voltage=5*2*sample1/1023;



// taking 150 samples from sensors with a interval of 2sec and then average the samples data collected
for(int i=0;i<150;i++)
{
sample2+=analogRead(A1); //read the current from sensor
delay(2);
}
sample2=sample2/150;


amps= (512-sample2)/1023*27.03;
long milisec = millis(); // calculate time in milliseconds
long time=milisec/1000; // convert milliseconds to seconds

totamps=totamps+amps; // calculate total amps
avgamps=totamps/time; // average amps
amphr=(avgamps*time)/3600; // amp-hour
watt =voltage*amps; // power=voltage*current
energy=(watt*time)/3600;// Watt-sec is again convert to Watt-Hr by dividing 1hr(3600sec)



lcd.setCursor(16,1); // set the cursor outside the display count
lcd.print(" "); // print empty character
//delay(600);
//////////////////////////////////////////print power and energy to a LCD//////////////////////////////////////////////// 
lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
lcd.print(watt);
lcd.print("W ");
lcd.print("  ");
lcd.print(voltage);
lcd.print("V ");
lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
lcd.print(energy);
lcd.print("WH  ");
lcd.print(" ");
lcd.print(amps);
lcd.print("A ");
// delay(1000);

char currentChar[10];
String currentConvert;
dtostrf(amps,1,2,currentChar);
//Convert number to string;
currentConvert = String(currentChar);
String currentString="C";
//represent Current, for easy searching in labview
String currentShow;
currentShow=currentString+currentConvert;

char voltageChar[10];
String voltageConvert;
dtostrf(voltage,1,2,voltageChar);
//Convert number to string;
voltageConvert = String(voltageChar);
String voltageString="V";
//represent Voltage, for easy searching in labview 
String voltageShow;
voltageShow=voltageString+voltageConvert;
//combine number and char together in one string

char wattChar[10];
String wattConvert;
dtostrf(watt,1,2,wattChar);
//Convert number to string;
wattConvert = String(wattChar);
String wattString="P";
//represent Power, for easy searching in labview 
String wattShow;
wattShow=wattString+wattConvert;
//combine number and char together in one string



char energyChar[10];
String energyConvert;
dtostrf(energy,1,2,energyChar);
//Convert number to string;
energyConvert = String(energyChar);
String energyString="E";
//represent Energy, for easy searching in labview
String energyShow;
energyShow=energyString+energyConvert;
//combine number and char together in one string



Serial.println(currentShow);
Serial.println(voltageShow);
Serial.println(wattShow);
Serial.println(energyShow);


delay(1000);
    }
// Auto mode with LCD working!

this code is just below the auto code, continue to manual >

  //Manual code<< with control movement but LCD not working
//      if((Incoming<MoveUp)&&(Incoming>DunMove))//check if manual move and moveup is selected, this will be excuted
//    {
//    
//    pos--;
//    myservo.write(pos);
//    Serial.println(Incoming);
//    
//    }
//    else if((Incoming<MoveDown)&&(Incoming>MoveUp))//check if manual move and movedown is selected, this will be excuted
//   {
//    pos++;
//    myservo.write(pos);
//    Serial.println(Incoming);
//    
//    }
//  else if((Incoming<TurnLeft)&&(Incoming>MoveDown))//check if manual move and clockwise is selected, this will be excuted
//   {
//    posl=clockwise;
//    myservol.write(posl);
//    Serial.println(Incoming);
//   
//   }
//  else if((Incoming<TurnRight)&&(Incoming>TurnLeft))//check if manual move and anticlockwise is selected, this will be excuted
//   {
//    posl=anticlockwise;
//    myservol.write(posl);
//    Serial.println(Incoming);
//   }
//  else if((Incoming<Display)&&(Incoming>TurnRight))//check if manual display is selected, this will be excuted
//    {
//    for(int i=0;i<150;i++)  
//  // taking 150 samples from voltage divider with a interval of 2sec and then average the samples data collected for(int i=0;i<150;i++)
//  {
//  sample1=sample1+analogRead(A0); //read the voltage from the divider circuit
//  delay (2);
//  }
//  sample1=sample1/150;
//  voltage=5*2*sample1/1023;
//  
//  
//  
//  // taking 150 samples from sensors with a interval of 2sec and then average the samples data collected
//  for(int i=0;i<150;i++)
//  {
//  sample2+=analogRead(A1); //read the current from sensor
//  delay(2);
//  }
//  sample2=sample2/150;
//  
//  
//  amps= (512-sample2)/1023*27.03;
//  long milisec = millis(); // calculate time in milliseconds
//  long time=milisec/1000; // convert milliseconds to seconds
//  
//  totamps=totamps+amps; // calculate total amps
//  avgamps=totamps/time; // average amps
//  amphr=(avgamps*time)/3600; // amp-hour
//  watt =voltage*amps; // power=voltage*current
//  energy=(watt*time)/3600;// Watt-sec is again convert to Watt-Hr by dividing 1hr(3600sec)
//  
//  
//  
//  lcd.setCursor(16,1); // set the cursor outside the display count
//  lcd.print(" "); // print empty character
//  //delay(600);
//  //////////////////////////////////////////print power and energy to a LCD//////////////////////////////////////////////// 
//  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
//  lcd.print(watt);
//  lcd.print("W ");
//  lcd.print("  ");
//  lcd.print(voltage);
//  lcd.print("V ");
//  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
//  lcd.print(energy);
//  lcd.print("WH  ");
//  lcd.print(" ");
//  lcd.print(amps);
//  lcd.print("A ");
//  // delay(1000);
//  
//  char currentChar[10];
//  String currentConvert;
//  dtostrf(amps,1,2,currentChar);
//  currentConvert = String(currentChar);
//  String currentString="C";
//  String currentShow;
//  currentShow=currentString+currentConvert;
//  
//  char voltageChar[10];
//  String voltageConvert;
//  dtostrf(voltage,1,2,voltageChar);
//  voltageConvert = String(voltageChar);
//  String voltageString="V";
//  String voltageShow;
//  voltageShow=voltageString+voltageConvert;
//  
//  
//  char wattChar[10];
//  String wattConvert;
//  dtostrf(watt,1,2,wattChar);
//  wattConvert = String(wattChar);
//  String wattString="P";
//  String wattShow;
//  wattShow=wattString+wattConvert;
//  
//  
//  
//  char energyChar[10];
//  String energyConvert;
//  dtostrf(energy,1,2,energyChar);
//  energyConvert = String(energyChar);
//  String energyString="E";
//  String energyShow;
//  energyShow=energyString+energyConvert;
//  
//  
//  
//  Serial.println(currentShow);
//  Serial.println(voltageShow);
//  Serial.println(wattShow);
//  Serial.println(energyShow);
//  
//  
//  delay(1000);
//    }
//   }
//    }

//Manual code<< with control movement but LCD not working
 if((Incoming>Auto1)&&(Incoming<Auto2))
    {
   // check if auto mode is selected, this will be executed
    }Else
 { 
  // manual mode code not defined
 }

you posted the code Saying below code is automatic working with LCD. which leads confusion.

Here two code tags mention define your automatic code & create Manual code tag define your manual operation.
In simple word create two project one with auto & other with manual ; so i wont disturb your auto code. I wil check Manual code. Then i club together to make one code.

If you using manual operation all Should be manual. dont alter the common parameter(variables)

sorry my bad. yeah sorry for confusing. okay thanks for your help :) :) appreciate it =)

S0 kindly write to project with manual & auto operation & pasted here with code Tags Let me check whats issue

this code for Manual,not working. i wan the code to move when i control button on left right top bottom in labview interface.

#include <LiquidCrystal.h>
#include <Servo.h> 
#include <Math.h>

Servo myservo;
Servo myservol;

int pos=90;
int posl=1500;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 4, 5, 6, 7, 8);
float sample1 = 0;
float voltage = 0;
float sample2 = 0;
float val = 0;
float actualval = 0;
float amps = 0;

float totamps= 0;
float avgamps= 0;
float amphr= 0; 
float watt = 0 ; 
float energy = 0; 
int diff = 0;
int SensitivityV = 30;
int SensitivityH = 27;

int tpl = 0;
int tpr = 0;
int dwl = 0;
int dwr = 0;
int avt = 0;
int avd = 0;
int avl = 0;
int avr = 0;

int Incoming=0;
int DunMove=48;
int MoveUp=50;
int MoveDown=52;
int TurnLeft=54;
int TurnRight=56;
int Auto1=47;
int Auto2=49;
int ManualA=49;
int ManualB=51;
int Display=58;

int clockwise = 1555;
int anticlockwise = 1445;
int stopped = 1500;

int analogPin = 3;

int input = 0;
void setup() {
  
  Serial.begin(9600);
  pinMode(3,OUTPUT);
  digitalWrite(3,HIGH);
  lcd.begin(16, 2);
  myservo.attach(9);
  myservol.attach(10);
}

void loop()
{
  input = analogRead(analogPin);    // read the input pin

  Serial.println(val);             // debug value

  if(Serial.available()<=0)// check if no data received, this will be excuted
  { 
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("Power ");
  lcd.print("Voltage");
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print("Energy ");
  lcd.print("Current");
  lcd.setCursor(1,2);
  lcd.print("Vin");
  }
        if((Incoming<MoveUp)&&(Incoming>DunMove))//check if manual move and moveup is selected, this will be excuted
    {
    
    pos--;
    myservo.write(pos);
    Serial.println(Incoming);
    
    }
    else if((Incoming<MoveDown)&&(Incoming>MoveUp))//check if manual move and movedown is selected, this will be excuted
   {
    pos++;
    myservo.write(pos);
    Serial.println(Incoming);
    
    }
  else if((Incoming<TurnLeft)&&(Incoming>MoveDown))//check if manual move and clockwise is selected, this will be excuted
   {
    posl=clockwise;
    myservol.write(posl);
    Serial.println(Incoming);
   
   }
  else if((Incoming<TurnRight)&&(Incoming>TurnLeft))//check if manual move and anticlockwise is selected, this will be excuted
   {
    posl=anticlockwise;
    myservol.write(posl);
    Serial.println(Incoming);
   }
  else if((Incoming<Display)&&(Incoming>TurnRight))//check if manual display is selected, this will be excuted
    {
    for(int i=0;i<150;i++)  
  // taking 150 samples from voltage divider with a interval of 2sec and then average the samples data collected for(int i=0;i<150;i++)
  {
  sample1=sample1+analogRead(A0); //read the voltage from the divider circuit
  delay (2);
  }
  sample1=sample1/150;
  voltage=5*2*sample1/1023;
  
  // taking 150 samples from sensors with a interval of 2sec and then average the samples data collected
  for(int i=0;i<150;i++)
  {
  sample2+=analogRead(A1); //read the current from sensor
  delay(2);
  }
  sample2=sample2/150;
  
  
  amps= (512-sample2)/1023*27.03;
  long milisec = millis(); // calculate time in milliseconds
  long time=milisec/1000; // convert milliseconds to seconds
  
  totamps=totamps+amps; // calculate total amps
  avgamps=totamps/time; // average amps
  amphr=(avgamps*time)/3600; // amp-hour
  watt =voltage*amps; // power=voltage*current
  energy=(watt*time)/3600;// Watt-sec is again convert to Watt-Hr by dividing 1hr(3600sec)
  
  lcd.setCursor(16,1); // set the cursor outside the display count
  lcd.print(" "); // print empty character
  //delay(600);
  //////////////////////////////////////////print power and energy to a LCD//////////////////////////////////////////////// 
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print(watt);
  lcd.print("W ");
  lcd.print("  ");
  lcd.print(voltage);
  lcd.print("V ");
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print(energy);
  lcd.print("WH  ");
  lcd.print(" ");
  lcd.print(amps);
  lcd.print("A ");
  // delay(1000);
  
  char currentChar[10];
  String currentConvert;
  dtostrf(amps,1,2,currentChar);
  currentConvert = String(currentChar);
  String currentString="C";
  String currentShow;
  currentShow=currentString+currentConvert;
  
  char voltageChar[10];
  String voltageConvert;
  dtostrf(voltage,1,2,voltageChar);
  voltageConvert = String(voltageChar);
  String voltageString="V";
  String voltageShow;
  voltageShow=voltageString+voltageConvert;
  
  char wattChar[10];
  String wattConvert;
  dtostrf(watt,1,2,wattChar);
  wattConvert = String(wattChar);
  String wattString="P";
  String wattShow;
  wattShow=wattString+wattConvert;

  char energyChar[10];
  String energyConvert;
  dtostrf(energy,1,2,energyChar);
  energyConvert = String(energyChar);
  String energyString="E";
  String energyShow;
  energyShow=energyString+energyConvert;

  Serial.println(currentShow);
  Serial.println(voltageShow);
  Serial.println(wattShow);
  Serial.println(energyShow);
  
  
  delay(1000);
    }
   }

Auto mode working-

#include <LiquidCrystal.h>
#include <Servo.h> 
#include <Math.h>

Servo myservo;
Servo myservol;

int pos=90;
int posl=1500;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 4, 5, 6, 7, 8);
float sample1 = 0;
float voltage = 0;
float sample2 = 0;
float val = 0;
float actualval = 0;
float amps = 0;

float totamps= 0;
float avgamps= 0;
float amphr= 0; 
float watt = 0 ; 
float energy = 0; 
int diff = 0;
int SensitivityV = 30;
int SensitivityH = 27;

int tpl = 0;
int tpr = 0;
int dwl = 0;
int dwr = 0;
int avt = 0;
int avd = 0;
int avl = 0;
int avr = 0;

int Incoming=0;
int DunMove=48;
int MoveUp=50;
int MoveDown=52;
int TurnLeft=54;
int TurnRight=56;
int Auto1=47;
int Auto2=49;
int ManualA=49;
int ManualB=51;
int Display=58;

int clockwise = 1555;
int anticlockwise = 1445;
int stopped = 1500;
//
int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3

                       // outside leads to ground and +5V

int input = 0;           // variable to store the value read
///
void setup() {
  
  Serial.begin(9600);
  pinMode(3,OUTPUT);
  digitalWrite(3,HIGH);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  myservo.attach(9);
  myservol.attach(10);
 
 
}

void loop()
{
////////
  input = analogRead(analogPin);    // read the input pin

  Serial.println(val);             // debug value

////////
  if(Serial.available()<=0)// check if no data received, this will be excuted
  { 
  lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
  lcd.print("Power ");
  lcd.print("Voltage");
  lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
  lcd.print("Energy ");
  lcd.print("Current");
  lcd.setCursor(1,2);
  lcd.print("Vin");
  }
  if(Serial.available()>0)//check if data received, this will be excuted
  {
    Incoming = Serial.read();// read the incoming data
  if((Incoming>Auto1)&&(Incoming<Auto2))// check if auto mode is selected, this will be excuted
    {
  tpl = analogRead(A2); // top left
  tpr = analogRead(A3); // top right
  dwl = analogRead(A4); // down left
  dwr = analogRead(A5); // down right
  
  avt = (tpl + tpr) / 2; // average value top
  avd = (dwl + dwr) / 2; // average value down
  avl = (tpl + dwl) / 2; // average value left
  avr = (tpr + dwr) / 2; // average value right
  
  int dvert = abs(avt - avd); // check the diffirence of up and down
  int dhoriz = abs(avl - avr);// check the diffirence of left and rigt
    
    
    // Auto mode with LCD working!
  if((avt > avd) && (dvert > SensitivityV))// check if top value is more then btm value and if difference is more then sensitivity
  {
    pos--;// increase pos value
  }
  
  if((avt < avd) && (dvert > SensitivityV))// check if btm value is more then top value and if difference is more then sensitivity
  {
    pos ++;// decrease pos value
    }
    myservo.write(pos);// write value to servo
  
 if((avl > avr) && (dhoriz > SensitivityH))// check if left value is more then right value and if difference is more then sensitivity
  {
    posl = clockwise;
    myservol.write(posl);// write value to servo
  }
  
  else if((avl < avr) && (dhoriz > SensitivityH))// check if right value is more then left value and if difference is more then sensitivity
  {
    posl = anticlockwise;
    myservol.write(posl);// write value to servo
    }
   
  else// if top is both not true this will be excuted
  {
    posl = stopped;
    myservol.write(posl);// write value to servo
  }
  
  for(int i=0;i<150;i++)  
// taking 150 samples from voltage divider with a interval of 2sec and then average the samples data collected for(int i=0;i<150;i++)
{
sample1=sample1+analogRead(A0); //read the voltage from the divider circuit
delay (2);
}
sample1=sample1/150;
voltage=5*2*sample1/1023;



// taking 150 samples from sensors with a interval of 2sec and then average the samples data collected
for(int i=0;i<150;i++)
{
sample2+=analogRead(A1); //read the current from sensor
delay(2);
}
sample2=sample2/150;


amps= (512-sample2)/1023*27.03;
long milisec = millis(); // calculate time in milliseconds
long time=milisec/1000; // convert milliseconds to seconds

totamps=totamps+amps; // calculate total amps
avgamps=totamps/time; // average amps
amphr=(avgamps*time)/3600; // amp-hour
watt =voltage*amps; // power=voltage*current
energy=(watt*time)/3600;// Watt-sec is again convert to Watt-Hr by dividing 1hr(3600sec)



lcd.setCursor(16,1); // set the cursor outside the display count
lcd.print(" "); // print empty character
//delay(600);
//////////////////////////////////////////print power and energy to a LCD//////////////////////////////////////////////// 
lcd.setCursor(1,0); // set the cursor at 1st col and 1st row
lcd.print(watt);
lcd.print("W ");
lcd.print("  ");
lcd.print(voltage);
lcd.print("V ");
lcd.setCursor(1,1); // set the cursor at 1st col and 2nd row
lcd.print(energy);
lcd.print("WH  ");
lcd.print(" ");
lcd.print(amps);
lcd.print("A ");
// delay(1000);

char currentChar[10];
String currentConvert;
dtostrf(amps,1,2,currentChar);
//Convert number to string;
currentConvert = String(currentChar);
String currentString="C";
//represent Current, for easy searching in labview
String currentShow;
currentShow=currentString+currentConvert;

char voltageChar[10];
String voltageConvert;
dtostrf(voltage,1,2,voltageChar);
//Convert number to string;
voltageConvert = String(voltageChar);
String voltageString="V";
//represent Voltage, for easy searching in labview 
String voltageShow;
voltageShow=voltageString+voltageConvert;
//combine number and char together in one string

char wattChar[10];
String wattConvert;
dtostrf(watt,1,2,wattChar);
//Convert number to string;
wattConvert = String(wattChar);
String wattString="P";
//represent Power, for easy searching in labview 
String wattShow;
wattShow=wattString+wattConvert;
//combine number and char together in one string



char energyChar[10];
String energyConvert;
dtostrf(energy,1,2,energyChar);
//Convert number to string;
energyConvert = String(energyChar);
String energyString="E";
//represent Energy, for easy searching in labview
String energyShow;
energyShow=energyString+energyConvert;
//combine number and char together in one string



Serial.println(currentShow);
Serial.println(voltageShow);
Serial.println(wattShow);
Serial.println(energyShow);


delay(1000);
    }
  }
}

Here some points ;

  1. you are not switching to manual mode code.

2)When you are checking condition ; How it expect TO move postion ++ 0r – when entry are same; So it will always give preference in first condition . that need to be change.

if((Incoming<MoveUp)&&(Incoming>DunMove))//check if manual move and moveup is selected, this will be excuted
    {
     Serial.println("Moveup/down Selected");
      pos--;
      myservo.write(pos);
      Serial.println(Incoming);

    }
    else if((Incoming<MoveDown)&&(Incoming>MoveUp))//check if manual move and movedown is selected, this will be excuted
    {
      Serial.println("Move down Selected");
      pos++;
      myservo.write(pos);
      Serial.println(Incoming);

    }

There always 4 conditions there are two variables

Move up & move DOwn condition not mentioned for both are high / LOW

  1. you have followed same process to below conditions

  2. If you reading auto mode all entry condition are differ from each other so they executing properly.

  3. I found if you using LCD & serial Print at same time The buffer will be full ; because of which u might get garbage values on LCD

  4. For debugging i recommend to use Serial . once it Work done display On LCD.

These alternation need to be done. Since i don’t Know What makes you make FW the motor or reverse motor you need to put entry condition.
Else use flags
else use SPDT switch with your hardware & config manually.

I dont why use Serial.read here. If i am doing programming use digital pin depend on status i choose mode(Manual/Auto) ; switch like DIP switch. In other part of code you just using Analog values & no Serial Data.

If in manual Mode ; u need todo operation like forward/reverse/stop; these can be done using same pin

my programming is lousy that's why i don't know how to change .. erm you can help me change the codes? i use serial.read, because i'm using four LDR sensor on solar panel to track the sunlight and will auto move to the brightest part of sunlight. i'm not sure what your last part meant as i'm new in these programming thing. sorry!