but didn't work on real situation.
What's wrong?
You have the robot in front of you. You can see what it actually does. You are the ONLY one that can.
You have some ideas about what the robot should be. You are the ONLY one that has any idea what you expect it to do.
You can't really expect us to tell you how to change the code to change one undefined behavior (what it actually does) to another undefined behavior (what you want it to do).
Connecting the ping sensor to pins that the LCD uses does not seem like a good idea.
Using one letter global variable names is definitely NOT a good idea.
motor2.run(FORWARD); // going forward
motor1.run(FORWARD); // going forward
delay(100);
}
//Function used to stop motors when going backwards, due to issue with general stop
void botstopB()
{
motor2.setSpeed(0); // set the speed to 200
motor1.setSpeed(0); // set the speed to 200
motor2.run(BACKWARD); // going forward
motor1.run(BACKWARD); // going forward
Does SIDEWAYS also mean forward?