Obstacle Avoiding Bot- Code Issue

I'm having trouble with some code, I was hoping someone else could take a look and tell me where I went wrong:

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int speed =127;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant

void setup()
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);
  digitalWrite(pinI1,LOW);
}

void backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
  digitalWrite(pinI3,HIGH);
  digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
  digitalWrite(pinI1,HIGH);
}

void left()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed/2);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
  digitalWrite(pinI1,LOW);
}

void stop()//
{
  digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
  digitalWrite(speedpinB,LOW);
  delay(1000);
 
}

void Sensor_loop()//this function is going to need to be played with_OLD NOTE
{
  long duration, inches;//establishes variables: duration and distance(inches)
  
  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  
  pinMode(pingPin, INPUT);
  duration=pulseIn(pingPin, HIGH);
 
  //code to convert time to distance
  inches=microsecondsToInches(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds/74/2;
}


void loop()//Main program
{
  Sensor_loop();
  delay(100);
  stop();
  
  if(inches>6)
  {
    forward();
    delay(2000);
    stop();
  }
  
  else 
  {
     backward();
     delay(2000);
     stop();
     
     left();
     delay(2000);
     stop();
  }
}

The compiler is reporting an issue in the "void loop" function. And claims that "inches" is not declared.

Any help would be awesome. I'm hoping to get this up and running before I leave for Basic on Sunday!

The compiler is reporting an issue in the "void loop" function. And claims that "inches" is not declared

The compiler is quite correct, though that isn't exactly what it says, is it? (There's a hint to your problem in the exact wording of the error message)

Ha, so I feel rather dumb for not catching that now.

That problem corrected, I now find that the program isn't running the way I wanted.

It was my intent for it to freely move forward until the ultrasonic registered an object 6in. ahead, then backup turn slightly to the left and carry continue forward. Instead... well honestly... I can't tell what it's trying to do. It's as if it's running thru the forward, backward, left function regardless of what the sensor "sees."

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int speed =1000;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant

void setup()
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);
  digitalWrite(pinI1,LOW);
}

void backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
  digitalWrite(pinI3,HIGH);
  digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
  digitalWrite(pinI1,HIGH);
}

void left()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed/2);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
  digitalWrite(pinI1,LOW);
}


void stop()//
{
  digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
  digitalWrite(speedpinB,LOW);
  delay(1000);
 
}

void Sensor_loop()//this funtion is going to need to be played with
{
  long duration, inches;//establishes variables: duration and distance(inches)
  
  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  
  pinMode(pingPin, INPUT);
  duration=pulseIn(pingPin, HIGH);
 
  //code to convert time to distance
  inches=microsecondsToInches(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds/74/2;
}


void loop()//Main program
{
  long inches;
  Sensor_loop();
  delay(100);
  stop();
  
  if(inches>6)
  {
    forward();
    delay(2000);
  }
  
  if(inches<=6) 
  {
     stop();
     
     backward();
     delay(2000);
     stop();
     
     left();
     delay(2000);
     stop();
  }
}

It was my intent for it to freely move forward until the ultrasonic registered an object 6in. ahead, then backup turn slightly to the left and carry continue forward. Instead... well honestly... I can't tell what it's trying to do. It's as if it's running thru the forward, backward, left function regardless of what the sensor "sees."

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int speed =1000;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant

void setup()
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);
  digitalWrite(pinI1,LOW);
}

void backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
  digitalWrite(pinI3,HIGH);
  digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
  digitalWrite(pinI1,HIGH);
}

void left()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed/2);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
  digitalWrite(pinI1,LOW);
}


void stop()//
{
  digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
  digitalWrite(speedpinB,LOW);
  delay(1000);
 
}

void Sensor_loop()//this funtion is going to need to be played with
{
  long duration, inches;//establishes variables: duration and distance(inches)
  
  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  
  pinMode(pingPin, INPUT);
  duration=pulseIn(pingPin, HIGH);
 
  //code to convert time to distance
  inches=microsecondsToInches(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds/74/2;
}


void loop()//Main program
{
  long inches;
  Sensor_loop();
  delay(100);
  stop();
  
  if(inches>6)
  {
    forward();
    delay(2000);
  }
  
  if(inches<=6) 
  {
     stop();
     
     backward();
     delay(2000);
     stop();
     
     left();
     delay(2000);
     stop();
  }
}

You have a problem with the variable "inches". You should:
move inches to a global variable and delete the local declarations in loop and Sensor_loop
or
return the long value inches from the Sensor_loop function and retrieve it in loop.

I'm currently working on a bot that avoids obstacles, unfortunately the code is giving me some headaches; and have come to a point where I think a second pair of eyes may be just what I need to get her up and running!

The bot is suppose to stay forward until it comes within 6inches of an object, at which point it is suppose to backup and turn left.

Currently it will only go forward, despite the distance(measured via an ultrasonic sensor, which also prints out distance so I know that part is working).

The code is as follow:

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int speed =1000;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant

void setup()
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//anticlockwise
  digitalWrite(pinI1,LOW);
}

void backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
  digitalWrite(pinI3,HIGH);
  digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
  digitalWrite(pinI1,HIGH);
}

void left()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed/2);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
  digitalWrite(pinI1,LOW);
}


void stop()//
{
  digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
  digitalWrite(speedpinB,LOW);
  delay(1000);
}

void Sensor_loop()//this funtion is going to need to be played with
{
  long microseconds, inches;//establishes variables: duration(microseconds) and distance(inches)

  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  microseconds=pulseIn(pingPin, HIGH);

  //code to convert time to distance
  inches= long (microseconds/74/2);
  //code to print distance values
  Serial.print(inches);
  Serial.print("in, ");

  delay(100);
}



void loop()//Main program
{
  Sensor_loop();
  {
    long (inches);
    if (inches>6)
      {
        forward();
        delay(2000);
      }

    else if (inches<=6)
    {
      stop();
      backward();
      delay(2000);
      stop();
      left();
      delay(2000);
      stop();
    }
  }
}

Any help would be much appreciated as I want this to run before I leave for Basic Sunday.

In "loop()", you don't assign anything to "inches", yet about five lines in, you check to see if "inches" is greater than six.

I'm currently working on a bot that avoids obstacles, unfortunately the code is giving me some headaches; and have come to a point where I think a second pair of eyes may be just what I need to get her up and running!

The bot is suppose to stay forward until it comes within 6inches of an object, at which point it is suppose to backup and turn left.

Currently it will only go forward, despite the distance(measured via an ultrasonic sensor, which also prints out distance so I know that part is working).

The code is as follow:

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int speed =1000;//define the spead of motor
const int pingPin=7;//defines pin number of sensor's output. let it be noted that const means constant

void setup()
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//anticlockwise
  digitalWrite(pinI1,LOW);
}

void backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed);
  digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
  digitalWrite(pinI3,HIGH);
  digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
  digitalWrite(pinI1,HIGH);
}

void left()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  analogWrite(speedpinB,speed/2);
  digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
  digitalWrite(pinI3,LOW);
  digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
  digitalWrite(pinI1,LOW);
}


void stop()//
{
  digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
  digitalWrite(speedpinB,LOW);
  delay(1000);
}

void Sensor_loop()//this funtion is going to need to be played with
{
  long microseconds, inches;//establishes variables: duration(microseconds) and distance(inches)

  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  microseconds=pulseIn(pingPin, HIGH);

  //code to convert time to distance
  inches= long (microseconds/74/2);
  //code to print distance values
  Serial.print(inches);
  Serial.print("in, ");
  delay(100);
}



void loop()//Main program
{
  Sensor_loop();
  {
    long (inches);
    if (inches>6)
      {
        forward();
        delay(2000);
      }

    else if (inches<=6)
    {
      stop();
      backward();
      delay(2000);
      stop();
      left();
      delay(2000);
      stop();
    }
  }
}

Any help would be much appreciated. It's my hope to get this to run before, I leave for Basic, this coming Sunday.

Multiple cross-posts merged - DO NOT CROSS-POST, IT WASTES TIME.